/** Test of selectByNameAndNodeId method, of class PublicationDAO. */
 @Test
 public void testSelectByNameAndNodeId() throws Exception {
   IDatabaseConnection connection = getConnection();
   try {
     Connection con = connection.getConnection();
     PublicationPK pubPK = new PublicationPK("100", "kmelia200");
     String name = "Publication 1";
     int nodeId = 110;
     PublicationDetail result = PublicationDAO.selectByNameAndNodeId(con, pubPK, name, nodeId);
     assertEquals(pubPK, result.getPK());
     assertEquals("Homer Simpson", result.getAuthor());
     assertEquals("2009/10/18", DateUtil.formatDate(result.getBeginDate()));
     assertEquals("00:00", result.getBeginHour());
     assertEquals("Contenu de la publication 1", result.getContent());
     assertEquals("2008/11/18", DateUtil.formatDate(result.getCreationDate()));
     assertEquals("100", result.getCreatorId());
     assertEquals("Première publication de test", result.getDescription());
     assertEquals("2020/12/18", DateUtil.formatDate(result.getEndDate()));
     assertEquals("23:59", result.getEndHour());
     assertEquals(1, result.getImportance());
     assertEquals("0", result.getInfoId());
     assertEquals("kmelia200", result.getInstanceId());
     assertEquals("test", result.getKeywords());
     assertEquals("Publication 1", result.getName());
     assertEquals("Valid", result.getStatus());
     assertEquals("300", result.getValidatorId());
     assertEquals("Publication 1", result.getTitle());
   } finally {
     connection.close();
   }
 }
  /** Test of selectByStatus method, of class PublicationDAO. */
  @Test
  public void testSelectByStatus_3args_2() throws Exception {
    IDatabaseConnection connection = getConnection();
    try {
      Connection con = connection.getConnection();
      List<String> componentIds = new ArrayList<String>();
      componentIds.add("kmelia200");
      componentIds.add("kmelia201");
      String status = "Valid";
      Collection<PublicationDetail> result =
          PublicationDAO.selectByStatus(con, componentIds, status);
      assertEquals(result.size(), 2);

      status = "Draft";
      result = PublicationDAO.selectByStatus(con, componentIds, status);
      assertEquals(result.size(), 0);

      status = "Valid";
      componentIds.remove("kmelia200");
      result = PublicationDAO.selectByStatus(con, componentIds, status);
      assertEquals(result.size(), 0);
    } finally {
      connection.close();
    }
  }
  /** Test of selectByFatherIds method, of class PublicationDAO. */
  @Test
  public void testSelectByFatherIds() throws Exception {
    IDatabaseConnection connection = getConnection();
    try {
      Connection con = connection.getConnection();
      List<String> fatherIds = new ArrayList<String>();
      fatherIds.add("110");
      PublicationPK pubPK = new PublicationPK("useless", "kmelia200");
      String sorting = "P.pubName";
      List<String> status = new ArrayList<String>();
      status.add("Valid");
      boolean filterOnVisibilityPeriod = true;
      ArrayList<PublicationDetail> result =
          PublicationDAO.selectByFatherIds(
              con, fatherIds, pubPK, sorting, status, filterOnVisibilityPeriod);
      assertEquals(result.size(), 2);

      // Test on an empty node
      fatherIds.clear();
      fatherIds.add("999");

      result =
          PublicationDAO.selectByFatherIds(
              con, fatherIds, pubPK, sorting, status, filterOnVisibilityPeriod);
      assertEquals(result.size(), 0);
    } finally {
      connection.close();
    }
  }
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    // initialize Log4j
    Properties props = new Properties();
    props.load(
        (new ClassPathResource("confs/log4j-exercise.properties", CompanyService.class))
            .getInputStream());
    org.apache.log4j.PropertyConfigurator.configure(props);

    // load springframework context
    applContext =
        new ClassPathXmlApplicationContext(
            "confs/spring-exercise-hibernate.xml", CompanyService.class);

    // create DbUnit core components
    IDatabaseConnection conn =
        new DatabaseDataSourceConnection((DataSource) applContext.getBean("dataSource"));
    dataSet =
        new FlatXmlDataSet(
            (new ClassPathResource(
                    "thirdstage/exercise/spring/transaction/case2/test/dataset/company-building-factory-seed-01.xml"))
                .getFile());

    // clean target tables and load test data
    try {
      DatabaseOperation.CLEAN_INSERT.execute(conn, dataSet);
    } finally {
      conn.close();
    }
  }
  protected final void setupData(InputStream... dataSetStream) {
    try {
      IDataSet[] dataSets = new IDataSet[dataSetStream.length];
      for (int i = 0; i < dataSetStream.length; i++) {
        ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(dataSetStream[i]));
        dataSet.addReplacementObject("[null]", null);
        dataSets[i] = dataSet;
      }
      CompositeDataSet compositeDataSet = new CompositeDataSet(dataSets);

      databaseTester.setDataSet(compositeDataSet);
      connection = databaseTester.getConnection();
      connection
          .getConnection()
          .prepareStatement("set referential_integrity FALSE")
          .execute(); // HSQL DB
      DatabaseConfig config = connection.getConfig();
      config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

      DatabaseOperation.CLEAN_INSERT.execute(connection, databaseTester.getDataSet());

      connection
          .getConnection()
          .prepareStatement("set referential_integrity TRUE")
          .execute(); // HSQL DB
    } catch (Exception e) {
      throw translateException("Could not setup DBUnit data", e);
    }
  }
Exemplo n.º 6
0
 @Override
 protected void verifyRows(AmbitRows<Object> rows) throws Exception {
   IDatabaseConnection c = getConnection();
   Assert.assertNotNull(rows);
   Assert.assertEquals(1, rows.size());
   while (rows.next()) {
     ITable table =
         c.createQueryTable(
             "EXPECTED",
             "select name,idreference,idproperty,idstructure,ifnull(text,value) as value_string,value_num,title,url,-1,id,units,comments from property_values \n"
                 + "left join property_string using(idvalue_string) \n"
                 + "join properties using(idproperty) join catalog_references using(idreference) \n"
                 + "where idstructure=100215 and name='Property 1' "
             /*
             "select name,idreference,idproperty,idstructure,value_string,value_num,idtype from properties join\n"+
             "(\n"+
             "select idstructure,idproperty,null as value_string,value as value_num,1 as idtype from values_number where idstructure=100215\n"+
             "union\n"+
             "select idstructure,idproperty,value as value_string,null,0 as idtype from values_string where idstructure=100215\n"+
             ") as L using (idproperty)\nwhere name='Property 1'"
             */
             );
     Assert.assertEquals(1, table.getRowCount());
     for (int i = 1; i <= rows.getMetaData().getColumnCount(); i++) {
       Object expected = table.getValue(0, rows.getMetaData().getColumnName(i));
       Object actual = rows.getObject(i);
       if ((expected == null) && (actual == null)) continue;
       else Assert.assertEquals(expected.toString(), actual.toString());
     }
   }
 }
Exemplo n.º 7
0
  protected void extractFullDataset(final String datasetFileName) throws Exception {
    // database connection
    IDatabaseConnection connection = getDbUnitConnection();

    // full database export
    IDataSet fullDataSet = connection.createDataSet();
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream(datasetFileName));
  }
Exemplo n.º 8
0
 protected void assertExpTable() throws Exception {
   String table = expected.getTableMetaData().getTableName();
   actual = databaseConnection.createQueryTable(table, query);
   try {
     assertEquals(expected, actual);
   } finally {
     databaseConnection.close();
   }
 }
 /** Executa operações do DBUnit no dataset <code>dbUnitXmlPath</code>. */
 protected void execute(DatabaseOperation operation, String dbUnitXmlPath) {
   try {
     IDatabaseConnection dbconn = this.getDbUnitConnection();
     operation.execute(dbconn, this.getDataSetFrom(dbUnitXmlPath));
     dbconn.close();
   } catch (Exception e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   }
 }
  /** Test of selectByFatherPK method, of class PublicationDAO. */
  @Test
  public void testSelectByFatherPK_Connection_NodePK() throws Exception {
    IDatabaseConnection connection = getConnection();
    try {
      Connection con = connection.getConnection();
      NodePK fatherPK = new NodePK("110", "kmelia200");
      Collection<PublicationDetail> result = PublicationDAO.selectByFatherPK(con, fatherPK);
      assertNotNull(result);
      assertEquals(2, result.size());
      Iterator<PublicationDetail> iter = result.iterator();
      PublicationDetail detail = iter.next();
      PublicationPK primaryKey = new PublicationPK("100", "kmelia200");
      assertEquals(primaryKey, detail.getPK());
      assertEquals("Homer Simpson", detail.getAuthor());
      assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
      assertEquals("00:00", detail.getBeginHour());
      assertEquals("Contenu de la publication 1", detail.getContent());
      assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
      assertEquals("100", detail.getCreatorId());
      assertEquals("Première publication de test", detail.getDescription());
      assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
      assertEquals("23:59", detail.getEndHour());
      assertEquals(1, detail.getImportance());
      assertEquals("0", detail.getInfoId());
      assertEquals("kmelia200", detail.getInstanceId());
      assertEquals("test", detail.getKeywords());
      assertEquals("Publication 1", detail.getName());
      assertEquals("Valid", detail.getStatus());
      assertEquals("300", detail.getValidatorId());
      assertEquals("Publication 1", detail.getTitle());

      detail = iter.next();
      primaryKey = new PublicationPK("101", "kmelia200");
      assertEquals(primaryKey, detail.getPK());
      assertEquals("Bart Simpson", detail.getAuthor());
      assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
      assertEquals("01:10", detail.getBeginHour());
      assertEquals("Contenu de la publication 2", detail.getContent());
      assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
      assertEquals("101", detail.getCreatorId());
      assertEquals("2ème publication de test", detail.getDescription());
      assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
      assertEquals("20:35", detail.getEndHour());
      assertEquals(5, detail.getImportance());
      assertEquals("0", detail.getInfoId());
      assertEquals("kmelia200", detail.getInstanceId());
      assertEquals("test", detail.getKeywords());
      assertEquals("Publication 2", detail.getName());
      assertEquals("Valid", detail.getStatus());
      assertEquals("300", detail.getValidatorId());
      assertEquals("Publication 2", detail.getTitle());
    } finally {
      connection.close();
    }
  }
Exemplo n.º 11
0
 /**
  * Override this method if you aren't using HSQL DB.
  *
  * <p>Execute whatever statement is necessary to enable integrity constraint checks after dataset
  * operations.
  *
  * @param con A DBUnit connection wrapper, before it is used by the application again
  */
 protected void enableReferentialIntegrity(IDatabaseConnection con) {
   try {
     if (database.equals(Database.hsql)) {
       con.getConnection().prepareStatement("set referential_integrity TRUE").execute(); // HSQL DB
     } else if (database.equals(Database.mysql)) {
       con.getConnection().prepareStatement("set foreign_key_checks=1").execute(); // MySQL > 4.1.1
     }
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
 }
Exemplo n.º 12
0
 private void closeAllConnections() {
   for (; ; ) {
     IDatabaseConnection conn = connections.poll();
     if (conn == null) return;
     try {
       conn.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 13
0
 /**
  * Print the contents of the given tableName to system.out<br>
  * <br>
  * Call this from any {@link BaseContextSensitiveTest} child by:
  * TestUtil.printOutTableContents(getConnection(), "encounter");
  *
  * @param sqlConnection the connection to use
  * @param tableNames the name(s) of the table(s) to print out
  * @throws Exception
  */
 public static void printOutTableContents(Connection sqlConnection, String... tableNames)
     throws Exception {
   for (String tableName : tableNames) {
     System.out.println("The contents of table: " + tableName);
     IDatabaseConnection connection = new DatabaseConnection(sqlConnection);
     DatabaseConfig config = connection.getConfig();
     config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
     QueryDataSet outputSet = new QueryDataSet(connection);
     outputSet.addTable(tableName);
     FlatXmlDataSet.write(outputSet, System.out);
   }
 }
Exemplo n.º 14
0
  protected void setUp() throws Exception {
    // NOTE: This will disable the SYS GLOBAL party creation and creation of all the reference
    // entities!!!
    initializeModelData = false;

    super.setUp();
    IDatabaseConnection dbUnitConn = null;
    dbUnitConn = getDbUnitConnection();
    DatabaseOperation.REFRESH.execute(dbUnitConn, getDataSet());
    dbUnitConn.getConnection().commit();
    dbUnitConn.close();
    dbUnitConn.getConnection().close();
  }
 public void dump(String dbUnitXmlPath) {
   try {
     IDatabaseConnection dbconn = getDbUnitConnection();
     IDataSet iDataSet = dbconn.createDataSet();
     // se for necessário ordenar devido as constraints - demora pacas
     // iDataSet = new FilteredDataSet(new
     // DatabaseSequenceFilter(dbconn), iDataSet);
     FlatXmlDataSet.write(iDataSet, new FileOutputStream(dbUnitXmlPath));
   } catch (Exception e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 16
0
  /**
   * Override this method if you want to provide your own DBUnit <tt>IDatabaseConnection</tt>
   * instance.
   *
   * <p>If you do not override this, default behavior is to use the * configured datasource name and
   * to obtain a connection with a JNDI lookup.
   *
   * @return a DBUnit database connection (wrapped)
   */
  protected IDatabaseConnection getConnection() {
    try {
      DataSource datasource = ((DataSource) getInitialContext().lookup(datasourceJndiName));

      // Get a JDBC connection from JNDI datasource
      Connection con = datasource.getConnection();
      IDatabaseConnection dbUnitCon = new DatabaseConnection(con);
      editConfig(dbUnitCon.getConfig());
      return dbUnitCon;
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  }
Exemplo n.º 17
0
  public void test() throws Exception {
    Connection jdbcConnection = null;
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection, "");
    DatabaseConfig config = connection.getConfig();

    // Use the ForwardOnlyResultSetTableFactory to export very large dataset.
    config.setProperty(
        DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY, new ForwardOnlyResultSetTableFactory());

    // Use the StreamingDataSet to import very large dataset.
    IDataSetProducer producer = new FlatXmlProducer(new InputSource("dataset.xml"));
    IDataSet dataSet = new StreamingDataSet(producer);
  }
  /** {@inheritDoc} Uses the connection from the provided databaseTester. */
  public void verifyData() throws Exception {
    if (databaseTester == null) {
      throw new IllegalStateException("databaseTester is null; must configure or set it first");
    }

    IDatabaseConnection connection = databaseTester.getConnection();

    try {
      int count = tableDefs.length;
      LOG.info("verifyData: about to verify {} tables={}", new Integer(count), tableDefs);
      if (count == 0) {
        LOG.warn("verifyData: No tables to verify;" + " no VerifyTableDefinitions specified");
      }

      for (int i = 0; i < count; i++) {
        VerifyTableDefinition td = tableDefs[i];
        String[] excludeColumns = td.getColumnExclusionFilters();
        String[] includeColumns = td.getColumnInclusionFilters();
        String tableName = td.getTableName();

        LOG.info("verifyData: Verifying table '{}'", tableName);

        LOG.debug("verifyData: Loading its rows from expected dataset");
        ITable expectedTable = null;
        try {
          expectedTable = expectedDs.getTable(tableName);
        } catch (Exception e) {
          final String msg =
              "verifyData: Problem obtaining table '" + tableName + "' from expected dataset";
          LOG.error(msg, e);
          throw new DataSetException(msg, e);
        }

        LOG.debug("verifyData: Loading its rows from actual table");
        ITable actualTable = null;
        try {
          actualTable = connection.createTable(tableName);
        } catch (Exception e) {
          final String msg =
              "verifyData: Problem obtaining table '" + tableName + "' from actual dataset";
          LOG.error(msg, e);
          throw new DataSetException(msg, e);
        }

        verifyData(expectedTable, actualTable, excludeColumns, includeColumns);
      }
    } finally {
      LOG.debug("verifyData: Verification done, closing connection");
      connection.close();
    }
  }
 /** Test of changeInstanceId method, of class PublicationDAO. */
 @Test
 public void testChangeInstanceId() throws Exception {
   IDatabaseConnection connection = getConnection();
   try {
     Connection con = connection.getConnection();
     PublicationPK pk = new PublicationPK("100", "kmelia200");
     PublicationDetail detail = PublicationDAO.loadRow(con, pk);
     assertEquals(pk, detail.getPK());
     assertEquals("Homer Simpson", detail.getAuthor());
     assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
     assertEquals("00:00", detail.getBeginHour());
     assertEquals("Contenu de la publication 1", detail.getContent());
     assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
     assertEquals("100", detail.getCreatorId());
     assertEquals("Première publication de test", detail.getDescription());
     assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
     assertEquals("23:59", detail.getEndHour());
     assertEquals(1, detail.getImportance());
     assertEquals("0", detail.getInfoId());
     assertEquals("kmelia200", detail.getInstanceId());
     assertEquals("test", detail.getKeywords());
     assertEquals("Publication 1", detail.getName());
     assertEquals("Valid", detail.getStatus());
     assertEquals("300", detail.getValidatorId());
     assertEquals("Publication 1", detail.getTitle());
     String targetInstance = "kmelia" + RandomGenerator.getRandomInt(600);
     PublicationDAO.changeInstanceId(con, pk, targetInstance);
     pk = new PublicationPK("100", targetInstance);
     detail = PublicationDAO.loadRow(con, pk);
     assertEquals(pk, detail.getPK());
     assertEquals("Homer Simpson", detail.getAuthor());
     assertEquals("2009/10/18", DateUtil.formatDate(detail.getBeginDate()));
     assertEquals("00:00", detail.getBeginHour());
     assertEquals("Contenu de la publication 1", detail.getContent());
     assertEquals("2008/11/18", DateUtil.formatDate(detail.getCreationDate()));
     assertEquals("100", detail.getCreatorId());
     assertEquals("Première publication de test", detail.getDescription());
     assertEquals("2020/12/18", DateUtil.formatDate(detail.getEndDate()));
     assertEquals("23:59", detail.getEndHour());
     assertEquals(1, detail.getImportance());
     assertEquals("0", detail.getInfoId());
     assertEquals(targetInstance, detail.getInstanceId());
     assertEquals("test", detail.getKeywords());
     assertEquals("Publication 1", detail.getName());
     assertEquals("Valid", detail.getStatus());
     assertEquals("300", detail.getValidatorId());
     assertEquals("Publication 1", detail.getTitle());
   } finally {
     connection.close();
   }
 }
Exemplo n.º 20
0
 @Override
 protected IDatabaseConnection getConnection() throws Exception {
   Connection conn = dataSource.getConnection();
   IDatabaseConnection connection =
       new DatabaseConnection(
           conn,
           dbType.equalsIgnoreCase("oracle") ? testProperties.getProperty("db.username") : null);
   DatabaseConfig config = connection.getConfig();
   if (containsProperty(testProperties, DATATYPE_FACTORY)) {
     Class clazz = Class.forName(testProperties.getProperty(DATATYPE_FACTORY));
     config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, BeanUtils.getInstance(clazz));
   }
   return connection;
 }
Exemplo n.º 21
0
 protected static void closeDBUnit() {
   try {
     connection.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
  @Test
  @XmlDataSet(location = {"/org/dbunit/ext/annotation/xmlDataSet.xml", "xmlDataSet2.xml"})
  public void testWhenMultipleXmlDataSetsInserted(IDatabaseConnection connection) throws Exception {
    ITable table = connection.createTable("fellowship");

    Assert.assertEquals(5, table.getRowCount());
  }
Exemplo n.º 23
0
 protected final IDataSet getCurrentDataSet() {
   try {
     return connection.createDataSet();
   } catch (SQLException e) {
     throw translateException("Could not create the current dataset", e);
   }
 }
  @Test
  @XmlDataSet(location = "/org/dbunit/ext/annotation/xmlDataSet.xml")
  public void testWhenXmlDataSetInsertedWithAbsoluteClassPath(IDatabaseConnection connection)
      throws Exception {
    ITable table = connection.createTable("fellowship");

    Assert.assertEquals(3, table.getRowCount());
  }
  @Test
  @XmlDataSet(location = "xmlDataSet.xml")
  public void testWhenXmlDataSetInsertedWithRelativeClassPath(IDatabaseConnection connection)
      throws Exception {
    ITable table = connection.createTable("fellowship");

    Assert.assertEquals(3, table.getRowCount());
  }
  /**
   * Verify that we can start the server as a daemon.
   *
   * @throws Exception If there was an error.
   */
  @Test
  public void testRunDaemon() throws Exception {
    ReflectionUtils.setVariableValueInObject(mojo, "daemon", Boolean.TRUE);
    try {
      mojo.execute();
      Thread.sleep(5000L);
      final Connection jdbcConnection = DriverManager.getConnection(getConnectionString());
      final IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
      IDataSet databaseDataSet = connection.createDataSet();
      assertNotNull(databaseDataSet.getTable(getTableName()));

      connection.close();
      jdbcConnection.close();
    } finally {
      signalStop();
    }
  }
 protected void onTearDown() {
   IDatabaseConnection connection = null;
   try {
     connection = getConnection();
     DatabaseOperation.DELETE_ALL.execute(connection, getDataSet());
   } catch (Exception ex) {
     ex.printStackTrace();
   } finally {
     if (connection != null) {
       try {
         connection.getConnection().close();
       } catch (SQLException e) {
         e.printStackTrace();
       }
     }
   }
 }
  /** Test of selectByStatus method, of class PublicationDAO. */
  @Test
  public void testSelectByStatus_3args_1() throws Exception {
    IDatabaseConnection connection = getConnection();
    try {
      Connection con = connection.getConnection();
      PublicationPK pubPK = new PublicationPK("useless", "kmelia200");
      String status = "Valid";
      Collection<PublicationDetail> result = PublicationDAO.selectByStatus(con, pubPK, status);
      assertEquals(result.size(), 2);

      status = "Draft";
      result = PublicationDAO.selectByStatus(con, pubPK, status);
      assertEquals(result.size(), 0);
    } finally {
      connection.close();
    }
  }
Exemplo n.º 29
0
  public static void main(String[] args) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection connection =
        DriverManager.getConnection("jdbc:mysql://localhost:3306/dbunit", "root", "1234");
    IDatabaseConnection databaseConnection = new DatabaseConnection(connection);

    // 根据SQL导出部分数据
    QueryDataSet queryDataSet = new QueryDataSet(databaseConnection);
    queryDataSet.addTable("users", "select password from users where id = 10");
    FlatXmlDataSet.write(queryDataSet, new FileOutputStream("dbunitXMLConditation.xml"));

    // 导出整个库的数据
    IDataSet dataSet = databaseConnection.createDataSet();
    // 将dbunit表中的数据写入到dbunitXML.xml文件中
    FlatXmlDataSet.write(dataSet, new FileOutputStream("dbunitXML.xml"));
    FlatDtdDataSet.write(dataSet, new FileOutputStream("dbunitXML.dtd"));
  }
  private synchronized IDatabaseConnection initialiseDbUnitConnection(
      ApplicationContext applicationContext) {
    if (dbUnitCon == null) {
      try {
        DataSource dataSource = applicationContext.getBean(DataSource.class);
        Preconditions.checkNotNull("dataSource not found", dataSource);
        dbUnitCon = new DatabaseDataSourceConnection(dataSource);
        DatabaseConfig config = dbUnitCon.getConfig();
        config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory());
        checkDataBase(dbUnitCon.getConnection().getMetaData());
      } catch (SQLException e) {

        log.error("error initialiseDbUnitConnection ", e);
      }
    }
    return dbUnitCon;
  }