Search in sources :

Example 1 with VersionControlledObject

use of com.dailystudio.dataobject.samples.VersionControlledObject in project devbricks by dailystudio.

the class DatabaseObjectTest method testVersionRelatedFunctions.

public void testVersionRelatedFunctions() {
    DatabaseObject object = null;
    Intent actual = null;
    String expected = null;
    object = new VersionControlledObject(mContext, DatabaseObject.VERSION_START);
    assertNotNull(object);
    assertEquals(DatabaseObject.VERSION_START, object.getVersion());
    object.setValue(VersionControlledObject.COLUMN_INT_VER1, 1982);
    object.setValue(VersionControlledObject.COLUMN_INT_VER2, 1983);
    object.setValue(VersionControlledObject.COLUMN_LONG_VER1, 12345678987654321l);
    object.setValue(VersionControlledObject.COLUMN_DOUBLE_VER2, 0.414);
    object.setValue(VersionControlledObject.COLUMN_TEXT_VER2, "Text string");
    assertEquals(1982, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER1));
    assertEquals(0, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER2));
    assertEquals(12345678987654321l, object.getLongValue(VersionControlledObject.COLUMN_LONG_VER1));
    assertEquals(.0, object.getDoubleValue(VersionControlledObject.COLUMN_DOUBLE_VER2));
    assertNull(object.getTextValue(VersionControlledObject.COLUMN_TEXT_VER2));
    object.setValue(VersionControlledObject.COLUMN_INT_VER1.getName(), 1982);
    object.setValue(VersionControlledObject.COLUMN_INT_VER2.getName(), 1983);
    object.setValue(VersionControlledObject.COLUMN_LONG_VER1.getName(), 12345678987654321l);
    object.setValue(VersionControlledObject.COLUMN_DOUBLE_VER2.getName(), 0.414);
    object.setValue(VersionControlledObject.COLUMN_TEXT_VER2.getName(), "Text string");
    assertEquals(1982, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER1.getName()));
    assertEquals(0, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER2.getName()));
    assertEquals(12345678987654321l, object.getLongValue(VersionControlledObject.COLUMN_LONG_VER1.getName()));
    assertEquals(.0, object.getDoubleValue(VersionControlledObject.COLUMN_DOUBLE_VER2.getName()));
    assertNull(object.getTextValue(VersionControlledObject.COLUMN_TEXT_VER2.getName()));
    assertEquals("int_ver1 = 1982 AND long_ver1 = 12345678987654321", object.toSQLSelectionString());
    expected = "CREATE TABLE IF NOT EXISTS VersionControlledObject ( int_ver1 INTEGER, long_ver1 LONG );";
    assertEquals(expected, object.toSQLTableCreationString());
    actual = object.convertToIntent();
    assertNotNull(actual);
    assertEquals(1982, actual.getIntExtra("int_ver1", 0));
    assertEquals(0, actual.getIntExtra("int_ver2", 0));
    assertEquals(12345678987654321l, actual.getLongExtra("long_ver1", 0l));
    assertEquals(.0, actual.getDoubleExtra("double_ver2", .0));
    assertNull(actual.getStringExtra("text_ver2"));
    object = new VersionControlledObject(mContext);
    assertNotNull(object);
    assertEquals(DatabaseObject.VERSION_START + 1, object.getVersion());
    object.setValue(VersionControlledObject.COLUMN_INT_VER1, 1982);
    object.setValue(VersionControlledObject.COLUMN_INT_VER2, 1983);
    object.setValue(VersionControlledObject.COLUMN_LONG_VER1, 12345678987654321l);
    object.setValue(VersionControlledObject.COLUMN_DOUBLE_VER2, 0.414);
    object.setValue(VersionControlledObject.COLUMN_TEXT_VER2, "Text string");
    assertEquals(1982, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER1));
    assertEquals(1983, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER2));
    assertEquals(12345678987654321l, object.getLongValue(VersionControlledObject.COLUMN_LONG_VER1));
    assertEquals(0.414, object.getDoubleValue(VersionControlledObject.COLUMN_DOUBLE_VER2));
    assertEquals("Text string", object.getTextValue(VersionControlledObject.COLUMN_TEXT_VER2));
    object.setValue(VersionControlledObject.COLUMN_INT_VER1.getName(), 1982);
    object.setValue(VersionControlledObject.COLUMN_INT_VER2.getName(), 1983);
    object.setValue(VersionControlledObject.COLUMN_LONG_VER1.getName(), 12345678987654321l);
    object.setValue(VersionControlledObject.COLUMN_DOUBLE_VER2.getName(), 0.414);
    object.setValue(VersionControlledObject.COLUMN_TEXT_VER2.getName(), "Text string");
    assertEquals(1982, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER1.getName()));
    assertEquals(1983, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER2.getName()));
    assertEquals(12345678987654321l, object.getLongValue(VersionControlledObject.COLUMN_LONG_VER1.getName()));
    assertEquals(0.414, object.getDoubleValue(VersionControlledObject.COLUMN_DOUBLE_VER2.getName()));
    assertEquals("Text string", object.getTextValue(VersionControlledObject.COLUMN_TEXT_VER2.getName()));
    assertEquals("int_ver1 = 1982 AND int_ver2 = 1983 AND long_ver1 = 12345678987654321 AND double_ver2 = 0.414 AND text_ver2 = \'Text string\'", object.toSQLSelectionString());
    expected = "CREATE TABLE IF NOT EXISTS VersionControlledObject ( int_ver1 INTEGER, int_ver2 INTEGER, long_ver1 LONG, double_ver2 DOUBLE, text_ver2 TEXT );";
    assertEquals(expected, object.toSQLTableCreationString());
    actual = object.convertToIntent();
    assertNotNull(actual);
    assertEquals(1982, actual.getIntExtra("int_ver1", 0));
    assertEquals(1983, actual.getIntExtra("int_ver2", 0));
    assertEquals(12345678987654321l, actual.getLongExtra("long_ver1", 0l));
    assertEquals(0.414, actual.getDoubleExtra("double_ver2", .0));
    assertEquals("Text string", actual.getStringExtra("text_ver2"));
}
Also used : VersionControlledObject(com.dailystudio.dataobject.samples.VersionControlledObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) Intent(android.content.Intent)

Example 2 with VersionControlledObject

use of com.dailystudio.dataobject.samples.VersionControlledObject in project devbricks by dailystudio.

the class DatabaseObjectFactoryTest method testVersionRelatedFunctions.

public void testVersionRelatedFunctions() {
    DatabaseObject object = null;
    Intent actual = null;
    String expected = null;
    object = DatabaseObjectFactory.createDatabaseObject(VersionControlledObject.class, DatabaseObject.VERSION_START);
    assertNotNull(object);
    assertEquals(DatabaseObject.VERSION_START, object.getVersion());
    object.setValue(VersionControlledObject.COLUMN_INT_VER1, 1982);
    object.setValue(VersionControlledObject.COLUMN_INT_VER2, 1983);
    object.setValue(VersionControlledObject.COLUMN_LONG_VER1, 12345678987654321l);
    object.setValue(VersionControlledObject.COLUMN_DOUBLE_VER2, 0.414);
    object.setValue(VersionControlledObject.COLUMN_TEXT_VER2, "Text string");
    assertEquals(1982, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER1));
    assertEquals(0, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER2));
    assertEquals(12345678987654321l, object.getLongValue(VersionControlledObject.COLUMN_LONG_VER1));
    assertEquals(.0, object.getDoubleValue(VersionControlledObject.COLUMN_DOUBLE_VER2));
    assertNull(object.getTextValue(VersionControlledObject.COLUMN_TEXT_VER2));
    object.setValue(VersionControlledObject.COLUMN_INT_VER1.getName(), 1982);
    object.setValue(VersionControlledObject.COLUMN_INT_VER2.getName(), 1983);
    object.setValue(VersionControlledObject.COLUMN_LONG_VER1.getName(), 12345678987654321l);
    object.setValue(VersionControlledObject.COLUMN_DOUBLE_VER2.getName(), 0.414);
    object.setValue(VersionControlledObject.COLUMN_TEXT_VER2.getName(), "Text string");
    assertEquals(1982, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER1.getName()));
    assertEquals(0, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER2.getName()));
    assertEquals(12345678987654321l, object.getLongValue(VersionControlledObject.COLUMN_LONG_VER1.getName()));
    assertEquals(.0, object.getDoubleValue(VersionControlledObject.COLUMN_DOUBLE_VER2.getName()));
    assertNull(object.getTextValue(VersionControlledObject.COLUMN_TEXT_VER2.getName()));
    assertEquals("int_ver1 = 1982 AND long_ver1 = 12345678987654321", object.toSQLSelectionString());
    expected = "CREATE TABLE IF NOT EXISTS VersionControlledObject ( int_ver1 INTEGER, long_ver1 LONG );";
    assertEquals(expected, object.toSQLTableCreationString());
    actual = object.convertToIntent();
    assertNotNull(actual);
    assertEquals(1982, actual.getIntExtra("int_ver1", 0));
    assertEquals(0, actual.getIntExtra("int_ver2", 0));
    assertEquals(12345678987654321l, actual.getLongExtra("long_ver1", 0l));
    assertEquals(.0, actual.getDoubleExtra("double_ver2", .0));
    assertNull(actual.getStringExtra("text_ver2"));
    object = DatabaseObjectFactory.createDatabaseObject(VersionControlledObject.class);
    assertNotNull(object);
    assertEquals(DatabaseObject.VERSION_START + 1, object.getVersion());
    object.setValue(VersionControlledObject.COLUMN_INT_VER1, 1982);
    object.setValue(VersionControlledObject.COLUMN_INT_VER2, 1983);
    object.setValue(VersionControlledObject.COLUMN_LONG_VER1, 12345678987654321l);
    object.setValue(VersionControlledObject.COLUMN_DOUBLE_VER2, 0.414);
    object.setValue(VersionControlledObject.COLUMN_TEXT_VER2, "Text string");
    assertEquals(1982, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER1));
    assertEquals(1983, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER2));
    assertEquals(12345678987654321l, object.getLongValue(VersionControlledObject.COLUMN_LONG_VER1));
    assertEquals(0.414, object.getDoubleValue(VersionControlledObject.COLUMN_DOUBLE_VER2));
    assertEquals("Text string", object.getTextValue(VersionControlledObject.COLUMN_TEXT_VER2));
    object.setValue(VersionControlledObject.COLUMN_INT_VER1.getName(), 1982);
    object.setValue(VersionControlledObject.COLUMN_INT_VER2.getName(), 1983);
    object.setValue(VersionControlledObject.COLUMN_LONG_VER1.getName(), 12345678987654321l);
    object.setValue(VersionControlledObject.COLUMN_DOUBLE_VER2.getName(), 0.414);
    object.setValue(VersionControlledObject.COLUMN_TEXT_VER2.getName(), "Text string");
    assertEquals(1982, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER1.getName()));
    assertEquals(1983, object.getIntegerValue(VersionControlledObject.COLUMN_INT_VER2.getName()));
    assertEquals(12345678987654321l, object.getLongValue(VersionControlledObject.COLUMN_LONG_VER1.getName()));
    assertEquals(0.414, object.getDoubleValue(VersionControlledObject.COLUMN_DOUBLE_VER2.getName()));
    assertEquals("Text string", object.getTextValue(VersionControlledObject.COLUMN_TEXT_VER2.getName()));
    assertEquals("int_ver1 = 1982 AND int_ver2 = 1983 AND long_ver1 = 12345678987654321 AND double_ver2 = 0.414 AND text_ver2 = \'Text string\'", object.toSQLSelectionString());
    expected = "CREATE TABLE IF NOT EXISTS VersionControlledObject ( int_ver1 INTEGER, int_ver2 INTEGER, long_ver1 LONG, double_ver2 DOUBLE, text_ver2 TEXT );";
    assertEquals(expected, object.toSQLTableCreationString());
    actual = object.convertToIntent();
    assertNotNull(actual);
    assertEquals(1982, actual.getIntExtra("int_ver1", 0));
    assertEquals(1983, actual.getIntExtra("int_ver2", 0));
    assertEquals(12345678987654321l, actual.getLongExtra("long_ver1", 0l));
    assertEquals(0.414, actual.getDoubleExtra("double_ver2", .0));
    assertEquals("Text string", actual.getStringExtra("text_ver2"));
}
Also used : VersionControlledObject(com.dailystudio.dataobject.samples.VersionControlledObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)2 TestDatabaseObject (com.dailystudio.dataobject.samples.TestDatabaseObject)2 VersionControlledObject (com.dailystudio.dataobject.samples.VersionControlledObject)2