use of org.jumpmind.symmetric.io.data.DbExport in project symmetric-ds by JumpMind.
the class DbExportImportTest method testExportCsvToDirectory.
@Test
public void testExportCsvToDirectory() throws Exception {
ISymmetricEngine engine = getSymmetricEngine();
IDatabasePlatform platform = engine.getSymmetricDialect().getPlatform();
DbImport importXml = new DbImport(platform);
importXml.setFormat(DbImport.Format.XML);
importXml.importTables(getClass().getResourceAsStream("/test-dbexportimport-3-tables.xml"));
File dir = new File("target/test");
FileUtils.deleteDirectory(dir);
Assert.assertFalse(dir.exists());
DbExport exportCsv = new DbExport(platform);
exportCsv.setComments(true);
exportCsv.setFormat(Format.CSV);
exportCsv.setDir(dir.getAbsolutePath());
exportCsv.exportTables(new String[] { "a", "b", "c" });
Assert.assertTrue(dir.exists());
Assert.assertTrue(dir.isDirectory());
File a = new File(dir, platform.getTableFromCache("a", false).getName() + ".csv");
Assert.assertTrue(a.exists());
Assert.assertTrue(a.isFile());
List<String> lines = FileUtils.readLines(a);
Assert.assertEquals(9, lines.size());
Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
Assert.assertEquals("\"1\",\"This is a test of a\"", lines.get(6));
Assert.assertEquals("\"2\",\"This is a test of a\"", lines.get(7));
File b = new File(dir, platform.getTableFromCache("b", false).getName() + ".csv");
Assert.assertTrue(b.exists());
Assert.assertTrue(b.isFile());
lines = FileUtils.readLines(b);
Assert.assertEquals(10, lines.size());
Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
Assert.assertEquals("\"1\",\"This is a test of b\"", lines.get(6));
Assert.assertEquals("\"2\",\"This is a test of b\"", lines.get(7));
Assert.assertEquals("\"3\",\"This is line 3 of b\"", lines.get(8));
File c = new File(dir, platform.getTableFromCache("c", false).getName() + ".csv");
Assert.assertTrue(c.exists());
Assert.assertTrue(c.isFile());
lines = FileUtils.readLines(c);
Assert.assertEquals(9, lines.size());
Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
Assert.assertEquals("\"1\",\"This is a test of c\"", lines.get(6));
Assert.assertEquals("\"2\",\"This is a test of c\"", lines.get(7));
}
Aggregations