@Override public void execute(IDatabaseConnection conn) { try { IDataSet dbDataSet = dbDataUtil.buildExport() .addTablesByDataSet(dataSetUrl, true) .createDataSet(conn); Assertion.assertEquals(flatXmlDataSet, dbDataSet); } catch (Exception ex) { throw new JuDbException("Couldn't assert DB data", ex); } }
/** * Tests the data export function writing DB data to an XML file. */ @Test public void writeToXmlFile() { File file = null; try { // Whole table to file String fileName = "writeToXmlFile_team.xml"; file = new File(fileName); if (file.exists()) file.delete(); this.createDbDataUtil().buildExport() .addTable("Team", null) .writeToXmlFile(fileName); Assert.assertTrue(file.exists()); } finally { if (file != null && file.exists()) file.delete(); } }
@Test public void canExportData_toXmlDocument() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); TestingEntity te = new TestingEntity(); te.setName("Export Test"); this.em.persist(te); DbDataUtil du = new DbDataUtil(this.em); Document doc = du.buildExport().addTable("TestingEntity").writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); logger.debug("Exported XML\n" + XmlUtils.toString(doc, false, true)); Assert.assertEquals(1, xg.getArray("//TestingEntity").length); Assert.assertEquals("Export Test", xg.getSingle("//TestingEntity/@name")); }
@Test public void xmlExport_copesWithCamelCaseTable_andUsesUpperCaseColumnNames() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); TestingEntity te = new TestingEntity(); te.setName("Export Test"); this.em.persist(te); // Export table with camel case DbDataUtil du = new DbDataUtil(this.em); Document doc = du.buildExport().addTable("TestingEntity").writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); logger.debug("Exported XML\n" + XmlUtils.toString(doc, false, true)); Assert.assertEquals(1, xg.getArray("//TestingEntity").length); Assert.assertEquals("Export Test", xg.getSingle("//TestingEntity/@name")); }
@Test public void xmlExport_copesWithUpperCaseTable_andUsesUpperCaseColumnNames() { // MySQL is case sensitive JuAssumeUtils.dbIsNot(this.emUtil, DbType.MYSQL); DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); TestingEntity te = new TestingEntity(); te.setName("Export Test"); this.em.persist(te); // Export table with camel case DbDataUtil du = new DbDataUtil(this.em); Document doc = du.buildExport().addTable("TESTINGENTITY").writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); logger.debug("Exported XML\n" + XmlUtils.toString(doc, false, true)); Assert.assertEquals(1, xg.getArray("//TESTINGENTITY").length); Assert.assertEquals("Export Test", xg.getSingle("//TESTINGENTITY/@name")); }
@Test public void xmlExport_copesWithLowerCaseTable_andUsesUpperCaseColumnNames() { // MySQL is case sensitive JuAssumeUtils.dbIsNot(this.emUtil, DbType.MYSQL); DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); TestingEntity te = new TestingEntity(); te.setName("Export Test"); this.em.persist(te); // Export table with camel case DbDataUtil du = new DbDataUtil(this.em); Document doc = du.buildExport().addTable("testingentity").writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); logger.debug("Exported XML\n" + XmlUtils.toString(doc, false, true)); Assert.assertEquals(1, xg.getArray("//testingentity").length); Assert.assertEquals("Export Test", xg.getSingle("//testingentity/@name")); }
@Test public void canExportTables_basedOnDatasetXml() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); TestingEntity te = new TestingEntity(); te.setName("Export Test"); this.em.persist(te); // Export table with camel case DbDataUtil du = new DbDataUtil(this.em); Document doc = du.buildExport() .addTablesByDataSet(JuUrl.resource("ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity.xml"), false) .writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); logger.debug("Exported XML\n" + XmlUtils.toString(doc, false, true)); Assert.assertEquals(1, xg.getArray("//TestingEntity").length); Assert.assertEquals("Export Test", xg.getSingle("//TestingEntity/@name")); }
@Test public void xmlExport_canApply_casedTableNames() { DbSchemaUtil ds = new DbSchemaUtil(this.em); ds.prepareDefaultTestData(true, true, true); TestingEntity te = new TestingEntity(); te.setName("Export Test"); this.em.persist(te); // Export table with camel case DbDataUtil du = new DbDataUtil(this.em); Document doc = du.buildExport() .addTable("TESTINGENTITY") .setTableNamesCasingByDataSet("/ch/inftec/ju/testing/db/DbDataUtilTest_testingEntity.xml") .writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); logger.debug("Exported XML\n" + XmlUtils.toString(doc, false, true)); Assert.assertEquals(1, xg.getArray("//TestingEntity").length); Assert.assertEquals("Export Test", xg.getSingle("//TestingEntity/@name")); }
if (tablesDataSestUrl == null) tablesDataSestUrl = JuUrl.resource(dataSetExport.tablesDataSet()); XmlOutputConverter xmlOutput = this.getDbDataUtil(emUtil).buildExport() .addTablesByDataSet(tablesDataSestUrl, true) .writeToXml();
/** * Tests the data export function writing DB data to an XML Document. */ @Test public void writeToDocument() { // Whole table to XML Document Document doc = this.createDbDataUtil().buildExport() .addTable("Team", null) .writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); Assert.assertEquals(2, xg.getSingleLong("count(//Team)").intValue()); }
@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")); }
@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 writeToDocument_order() { // Annotation not working as it would run after class annotation which results // in an INSERT instead of a CLEAN_INSERT this.createDbDataUtil().buildImport() .from("/datasets/testingEntityUnsortedData.xml") .executeCleanInsert(); Document doc = this.createDbDataUtil().buildExport() .addTableSorted("TestingEntity", "ID") .writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); Assert.assertEquals(1, xg.getSingleLong("//TestingEntity[1]/@id").intValue()); Assert.assertEquals(2, xg.getSingleLong("//TestingEntity[2]/@id").intValue()); Assert.assertEquals(3, xg.getSingleLong("//TestingEntity[3]/@id").intValue()); }
@Test public void writeToDocument_query() { // Annotation not working as it would run after class annotation which results // in an INSERT instead of a CLEAN_INSERT this.createDbDataUtil().buildImport() .from("/datasets/testingEntityUnsortedData.xml") .executeCleanInsert(); Document doc = this.createDbDataUtil().buildExport() .addTable("TestingEntity", "SELECT * FROM TESTINGENTITY WHERE ID=2") .writeToXmlDocument(); XPathGetter xg = new XPathGetter(doc); Assert.assertEquals(1, xg.getSingleLong("count(//TestingEntity)").intValue()); Assert.assertEquals(2, xg.getSingleLong("//TestingEntity/@id").intValue()); }