@Test public void canImportData_fromDatasetFile() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); DbDataUtil du = new DbDataUtil(this.em); du.cleanImport("/ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity.xml"); TestingEntity te = this.em.find(TestingEntity.class, 1L); Assert.assertEquals("DbDataUtilTest", te.getName()); }
@Before public void loadTestData() { this.createDbDataUtil().cleanImport("/datasets/fullData.xml"); }
@Before public void loadTestData() { this.createDbDataUtil().cleanImport("/datasets/fullData.xml"); }
@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(); }
@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 public void databaseSetup() { this.createDbDataUtil().cleanImport("DbUnitTest-singleTestingEntityData.xml"); Assert.assertEquals("SpringDbUnitTest", this.testingEntityRepo.findOne(1L).getName()); } }
@Test public void exportTables_basedOnDatasetXml_areSortedByPrimaryKey() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); DbDataUtil du = new DbDataUtil(this.em); du.cleanImport("/ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity_unsorted.xml"); // Export table with camel case Document doc = du.buildExport() .addTablesByDataSet(JuUrl.resource("ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity.xml"), true) .writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); logger.debug("Exported XML\n" + XmlUtils.toString(doc, false, true)); Assert.assertEquals(3, xg.getArray("//TestingEntity").length); Assert.assertEquals("1", xg.getSingle("//TestingEntity[1]/@id")); Assert.assertEquals("2", xg.getSingle("//TestingEntity[2]/@id")); Assert.assertEquals("3", xg.getSingle("//TestingEntity[3]/@id")); }
@Test public void exportTables_areSortedByPrimaryKey() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); DbDataUtil du = new DbDataUtil(this.em); du.cleanImport("/ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity_unsorted.xml"); // Export table with camel case Document doc = du.buildExport() .addTableSorted("TestingEntity") .writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); logger.debug("Exported XML\n" + XmlUtils.toString(doc, false, true)); Assert.assertEquals(3, xg.getArray("//TestingEntity").length); Assert.assertEquals("1", xg.getSingle("//TestingEntity[1]/@id")); Assert.assertEquals("2", xg.getSingle("//TestingEntity[2]/@id")); Assert.assertEquals("3", xg.getSingle("//TestingEntity[3]/@id")); }