From ce2cae234e1dd1994a2bf9355013c19899d9dbed Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sat, 12 Oct 2013 14:27:12 +0000 Subject: [PATCH] add unit tests for property modification git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@819 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/PropertiesTest.java | 126 +++++++++++++++--- 1 file changed, 110 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java b/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java index e71252e..aa98ce5 100644 --- a/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java @@ -233,22 +233,7 @@ public class PropertiesTest extends TestCase PropertyMapImpl propMap = iter.next(); PropertyMapImpl propMap2 = iter2.next(); - assertEquals(propMap.getSize(), propMap2.getSize()); - for(PropertyMap.Property prop : propMap) { - PropertyMap.Property prop2 = propMap2.get(prop.getName()); - - assertEquals(prop.getName(), prop2.getName()); - assertEquals(prop.getType(), prop2.getType()); - - Object v1 = prop.getValue(); - Object v2 = prop2.getValue(); - - if(v1 instanceof byte[]) { - assertTrue(Arrays.equals((byte[])v1, (byte[])v2)); - } else { - assertEquals(v1, v2); - } - } + checkProperties(propMap, propMap2); } assertFalse(iter.hasNext()); @@ -258,4 +243,113 @@ public class PropertiesTest extends TestCase } } + public void testModifyProperties() throws Exception + { + for(TestDB testDb : SUPPORTED_DBS_TEST) { + Database db = openCopy(testDb); + File dbFile = db.getFile(); + + Table t = db.getTable("Table1"); + + // grab originals + PropertyMap origCProps = t.getColumn("C").getProperties(); + PropertyMap origFProps = t.getColumn("F").getProperties(); + PropertyMap origDProps = t.getColumn("D").getProperties(); + + db.close(); + + + // modify but do not save + db = new DatabaseBuilder(dbFile).open(); + + t = db.getTable("Table1"); + + PropertyMap cProps = t.getColumn("C").getProperties(); + PropertyMap fProps = t.getColumn("F").getProperties(); + PropertyMap dProps = t.getColumn("D").getProperties(); + + assertFalse((Boolean)cProps.getValue(PropertyMap.REQUIRED_PROP)); + assertEquals("0", fProps.getValue(PropertyMap.DEFAULT_VALUE_PROP)); + assertEquals((short)109, dProps.getValue("DisplayControl")); + + cProps.put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, true); + fProps.get(PropertyMap.DEFAULT_VALUE_PROP).setValue("42"); + dProps.remove("DisplayControl"); + + db.close(); + + + // modify and save + db = new DatabaseBuilder(dbFile).open(); + + t = db.getTable("Table1"); + + cProps = t.getColumn("C").getProperties(); + fProps = t.getColumn("F").getProperties(); + dProps = t.getColumn("D").getProperties(); + + assertFalse((Boolean)cProps.getValue(PropertyMap.REQUIRED_PROP)); + assertEquals("0", fProps.getValue(PropertyMap.DEFAULT_VALUE_PROP)); + assertEquals((short)109, dProps.getValue("DisplayControl")); + + checkProperties(origCProps, cProps); + checkProperties(origFProps, fProps); + checkProperties(origDProps, dProps); + + cProps.put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, true); + cProps.save(); + fProps.get(PropertyMap.DEFAULT_VALUE_PROP).setValue("42"); + fProps.save(); + dProps.remove("DisplayControl"); + dProps.save(); + + db.close(); + + + // reload saved props + db = new DatabaseBuilder(dbFile).open(); + + t = db.getTable("Table1"); + + cProps = t.getColumn("C").getProperties(); + fProps = t.getColumn("F").getProperties(); + dProps = t.getColumn("D").getProperties(); + + assertTrue((Boolean)cProps.getValue(PropertyMap.REQUIRED_PROP)); + assertEquals("42", fProps.getValue(PropertyMap.DEFAULT_VALUE_PROP)); + assertNull(dProps.getValue("DisplayControl")); + + cProps.put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, false); + fProps.get(PropertyMap.DEFAULT_VALUE_PROP).setValue("0"); + dProps.put("DisplayControl", DataType.INT, (short)109); + + checkProperties(origCProps, cProps); + checkProperties(origFProps, fProps); + checkProperties(origDProps, dProps); + + db.close(); + } + } + + private static void checkProperties(PropertyMap propMap1, + PropertyMap propMap2) + { + assertEquals(propMap1.getSize(), propMap2.getSize()); + for(PropertyMap.Property prop : propMap1) { + PropertyMap.Property prop2 = propMap2.get(prop.getName()); + + assertEquals(prop.getName(), prop2.getName()); + assertEquals(prop.getType(), prop2.getType()); + + Object v1 = prop.getValue(); + Object v2 = prop2.getValue(); + + if(v1 instanceof byte[]) { + assertTrue(Arrays.equals((byte[])v1, (byte[])v2)); + } else { + assertEquals(v1, v2); + } + } + } + } -- 2.39.5