Search in sources :

Example 46 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class DatabaseWriterTest method testColumnNotExisting.

@Test
public void testColumnNotExisting() throws Exception {
    List<String> testColumns = new ArrayList<String>(Arrays.asList(TEST_COLUMNS));
    testColumns.add(4, "Unknown_Column");
    String[] columns = testColumns.toArray(new String[testColumns.size()]);
    String[] values = { getNextId(), "testColumnNotExisting", "string not null", "char", "i do not exist!", "char not null", "2007-01-02 00:00:00.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747" };
    List<String> valuesAsList = new ArrayList<String>(Arrays.asList(values));
    valuesAsList.remove(4);
    String[] expectedValues = valuesAsList.toArray(new String[valuesAsList.size()]);
    writeData(new CsvData(DataEventType.INSERT, values), expectedValues, columns);
}
Also used : ArrayList(java.util.ArrayList) CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Example 47 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class DatabaseWriterTest method testUpdateDetectVersionIgnoreBatch.

@Test
public void testUpdateDetectVersionIgnoreBatch() {
    Conflict setting = new Conflict();
    setting.setConflictId("unit.test");
    setting.setDetectType(DetectConflict.USE_VERSION);
    setting.setDetectExpression("integer_value");
    setting.setResolveRowOnly(false);
    setting.setResolveChangesOnly(false);
    setting.setResolveType(ResolveConflict.NEWER_WINS);
    writerSettings.setDefaultConflictSetting(setting);
    String id = getNextId();
    String[] originalValues = massageExpectectedResultsForDialect(new String[] { id, "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.000", "2012-03-12 07:00:00.000", "0", "2", "67.89", "-0.0747663" });
    CsvData data = new CsvData(DataEventType.INSERT, originalValues);
    writeData(data, originalValues);
    long before = countRows(TEST_TABLE);
    String[] updateShouldNotBeApplied = CollectionUtils.copyOfRange(originalValues, 0, originalValues.length);
    updateShouldNotBeApplied[2] = "updated string";
    updateShouldNotBeApplied[8] = "1";
    CsvData update = new CsvData(DataEventType.UPDATE, massageExpectectedResultsForDialect(updateShouldNotBeApplied));
    String newId = getNextId();
    CsvData newInsert = new CsvData(DataEventType.INSERT, massageExpectectedResultsForDialect(new String[] { newId, "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.0", "2012-03-12 07:00:00.0", "0", "2", "67.89", "-0.0747663" }));
    writeData(update, newInsert);
    Assert.assertEquals(before, countRows(TEST_TABLE));
}
Also used : ResolveConflict(org.jumpmind.symmetric.io.data.writer.Conflict.ResolveConflict) DetectConflict(org.jumpmind.symmetric.io.data.writer.Conflict.DetectConflict) CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Example 48 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class DatabaseWriterTest method testDeleteExisting.

@Test
public void testDeleteExisting() throws Exception {
    String[] values = { getNextId(), "a row to be deleted", "testDeleteExisting", "char2", "char not null2", "2007-01-02 03:20:10.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747" };
    massageExpectectedResultsForDialect(values);
    writeData(new CsvData(DataEventType.INSERT, values), values);
    writeData(new CsvData(DataEventType.DELETE, new String[] { getId() }, null), null);
}
Also used : CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Example 49 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class DatabaseWriterTest method testTableNotExisting.

@Test
public void testTableNotExisting() throws Exception {
    String[] values = { getNextId(), "testTableNotExisting", "This row should load", "char", "char not null", "2007-01-02 00:00:00.000", "2007-02-03 04:05:06.000", "0", "0", "12.10", "-0.0747" };
    Table badTable = buildSourceTable("UnknownTable", TEST_KEYS, TEST_COLUMNS);
    writeData(new TableCsvData(badTable, new CsvData(DataEventType.INSERT, values)), new TableCsvData(buildSourceTable(TEST_TABLE, TEST_KEYS, TEST_COLUMNS), new CsvData(DataEventType.INSERT, values)));
    massageExpectectedResultsForDialect(values);
    assertTestTableEquals(values[0], values);
}
Also used : Table(org.jumpmind.db.model.Table) CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Example 50 with CsvData

use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.

the class CsvDataTest method testGetCsvData.

@Test
public void testGetCsvData() {
    final String TEST = "\"This is a test\", laughs Kunal.\n\r";
    CsvData data = new CsvData(DataEventType.INSERT, new String[] { TEST });
    String rowData = data.getCsvData(CsvData.ROW_DATA);
    CsvData newData = new CsvData();
    newData.putCsvData(CsvData.ROW_DATA, rowData);
    String result = newData.getParsedData(CsvData.ROW_DATA)[0];
    assertEquals(TEST, result);
}
Also used : CsvData(org.jumpmind.symmetric.io.data.CsvData) Test(org.junit.Test)

Aggregations

CsvData (org.jumpmind.symmetric.io.data.CsvData)57 Test (org.junit.Test)39 AbstractWriterTest (org.jumpmind.symmetric.io.AbstractWriterTest)26 Table (org.jumpmind.db.model.Table)16 ArrayList (java.util.ArrayList)15 Column (org.jumpmind.db.model.Column)7 OracleDatabasePlatform (org.jumpmind.db.platform.oracle.OracleDatabasePlatform)7 Batch (org.jumpmind.symmetric.io.data.Batch)7 DetectConflict (org.jumpmind.symmetric.io.data.writer.Conflict.DetectConflict)7 ResolveConflict (org.jumpmind.symmetric.io.data.writer.Conflict.ResolveConflict)6 Statistics (org.jumpmind.util.Statistics)5 CommonsDbcpNativeJdbcExtractor (org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor)5 Connection (java.sql.Connection)4 DataSource (javax.sql.DataSource)4 TableCsvData (org.jumpmind.symmetric.io.AbstractWriterTest.TableCsvData)4 TransformTable (org.jumpmind.symmetric.io.data.transform.TransformTable)4 NativeJdbcExtractor (org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor)4 IOException (java.io.IOException)3 IoException (org.jumpmind.exception.IoException)3 DataContext (org.jumpmind.symmetric.io.data.DataContext)3