Search in sources :

Example 11 with DbExport

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));
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DbExport(org.jumpmind.symmetric.io.data.DbExport) DbImport(org.jumpmind.symmetric.io.data.DbImport) File(java.io.File) AbstractServiceTest(org.jumpmind.symmetric.service.impl.AbstractServiceTest) Test(org.junit.Test)

Aggregations

DbExport (org.jumpmind.symmetric.io.data.DbExport)11 AbstractServiceTest (org.jumpmind.symmetric.service.impl.AbstractServiceTest)9 Test (org.junit.Test)9 Table (org.jumpmind.db.model.Table)7 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)6 Database (org.jumpmind.db.model.Database)4 DbImport (org.jumpmind.symmetric.io.data.DbImport)4 File (java.io.File)3 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)3 Row (org.jumpmind.db.sql.Row)2 DbFill (org.jumpmind.symmetric.io.data.DbFill)2 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ThreadInfo (java.lang.management.ThreadInfo)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Properties (java.util.Properties)1