/** * Shortcut to execute a clean import from a dataset resource file. * @param resourcePath Path to dataset resource */ public void cleanImport(String resourcePath) { this.buildImport().from(resourcePath).executeCleanInsert(); }
/** * Gets an instance of a DbDataUtil for the current connection. * @return DbDataUtil instance */ protected final DbDataUtil createDbDataUtil() { DbDataUtil util = new DbDataUtil(this.em); // util.setSchema(this.connectionInfo.getSchema()); if (this.dataTypeFactor != null) { util.setConfigProperty("http://www.dbunit.org/properties/datatypeFactory", this.dataTypeFactor); } return util; }
/** * Creates the Default test DB Schema (Player, Team, TestingEntity...) and * loads the default test data. * <p> * Also resets the sequences to 1. */ public void prepareDefaultSchemaAndTestData() { this.prepareDefaultTestData(false, true, true); }
@Test public void assert_canAssertTables() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); DbDataUtil du = new DbDataUtil(this.emUtil); du.cleanImport("/ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity_unsorted.xml"); du.buildAssert() .expected("/ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity_sorted.xml") .assertEquals(); }
/** * Executes a DbUnit dataset import through a JDBC connection. * @param conn JDBC connection * @param dataSetUrl DataSet URL * @param cleanInsert If true, a clean insert is performed. Otherwise, an insert is performed. */ public static void executeInsert(Connection conn, URL dataSetUrl, boolean cleanInsert) { ImportBuilder ib = new DbDataUtil(conn).buildImport().from(dataSetUrl); if (cleanInsert) { ib.executeCleanInsert(); } else { ib.executeInsert(); } }
@Test @DataSet("dataSetExport/exportForTest2") @DataSetExport(tablesDataSet = "ds", exportName = "exportForTest3") public void test2() { }
@Test @JuDbTest(profile="derby-testing", persistenceUnit="ju-testing pu-default-test-data") public void canLoadDefaultData_inAbstractDbTest() { new DbSchemaUtil(this.connUtil).prepareDefaultSchemaAndTestData(); } }
/** * Helper method that allows us to prepare a Schema as defined in the DB test profile. * <p> * This method can be called multiple time, it will only create the Schema the first time. * <p> * TODO: Whole Schema handling should be refactored... */ public static void prepareSchemaByProfile() { new DbInitializerRule(null).prepareSchemaByProfile(); }
/** * Returns a new ExportBuilder to configure and execute DB data exports. * @return ExportBuilder instance */ public ExportBuilder buildExport() { return new ExportBuilder(this); }
/** * Returns a builder to set up a Liquibase ChangeLog run. * <p> * Allows to set liquibase parameters as well. * * @return */ public LiquibaseChangeLogBuilder liquibaseChangeLog() { return new LiquibaseChangeLogBuilder(); }
/** * Initializes the environment for the test case. * @return A SystemPropertyTempSetter that can be used to restore the original system property state */ public SystemPropertyTempSetter initContainerTestEnv() { return DbTestAnnotationHandler.setTestEnvProperties(this.annoInfo.testEnvAnnos); }
/** * Returns a new AssertBuilder to assert that table data equals expected data * specified in an XML file. * @return AssertBuilder instance */ public AssertBuilder buildAssert() { return new AssertBuilder(this); }
/** * Gets a DbTestAnnotationInfo object for the specified test method. * * @param testMethod * Test method * @return DbTestAnnotationInfo object */ static DbTestAnnotationInfo getDbTestAnnotationInfo(Method testMethod) { return new DbTestAnnotationInfo(testMethod); }
@Override public void execute(IDatabaseConnection conn) { dataSetWork.execute(createDataSet(conn)); }; });
@Test(expected=ComparisonFailure.class) public void assert_canAssertTables_failsOnWrongData() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); DbDataUtil du = new DbDataUtil(this.emUtil); du.cleanImport("/ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity_unsorted.xml"); du.buildAssert() .expected("/ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity.xml") .assertEquals(); }
@Test @DataSet("dataSetExport/exportForTest2") @DataSetExport(tablesDataSet = "ds", exportName = "exportForTest1") public void test2() { } }
/** * Loads the default test data and resets the sequences to 1. * <p> * Doesn't perform Schema updates. */ public void loadDefaultTestData() { this.prepareDefaultTestData(false, true, false); }
@Test @DataSet("dataSetExport/exportForTest1") @DataSetExport(tablesDataSet = "ds", exportName = "exportForTest2") public void test1() { } }
@Test @DataSet("dataSetExport/exportForTest3") @DataSetExport(tablesDataSet = "ds", exportName = "exportForTest1") public void test3() { } }
@Test @DataSet("dataSetExport/exportForTest1") @DataSetExport(tablesDataSet = "ds", exportName = "exportForTest2") public void test1() { }