]> source.dussan.org Git - jackcess.git/commitdiff
add 2007 complex test db
authorJames Ahlborn <jtahlborn@yahoo.com>
Wed, 26 Oct 2011 02:57:23 +0000 (02:57 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Wed, 26 Oct 2011 02:57:23 +0000 (02:57 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@581 f203690c-595d-4dc9-a70b-905162fa7fd2

test/data/V2007/complexDataTestV2007.accdb [new file with mode: 0755]
test/src/java/com/healthmarketscience/jackcess/ComplexColumnTest.java
test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java

diff --git a/test/data/V2007/complexDataTestV2007.accdb b/test/data/V2007/complexDataTestV2007.accdb
new file mode 100755 (executable)
index 0000000..3f9ff36
Binary files /dev/null and b/test/data/V2007/complexDataTestV2007.accdb differ
index d853f6f0bae4b4de1fb46c237393ddecb037d40c..a0664c46dcd7e11c748e67f8703ad7d6f6ff8cf2 100644 (file)
@@ -8,6 +8,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import static com.healthmarketscience.jackcess.JetFormatTest.*;
 import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.complex.Attachment;
 import com.healthmarketscience.jackcess.complex.ComplexDataType;
@@ -30,189 +31,198 @@ public class ComplexColumnTest extends TestCase
 
   public void testVersions() throws Exception
   {
-    Database db = DatabaseTest.openCopy(Database.FileFormat.V2007, new File("/data2/jackcess_test/complexDataTest.accdb"));
-    db.setTimeZone(TEST_TZ);
-
-    Table t1 = db.getTable("Table1");
-    Column col = t1.getColumn("append-memo-data");
-    assertTrue(col.isAppendOnly());
-    Column verCol = col.getVersionHistoryColumn();
-    assertNotNull(verCol);
-    assertEquals(ComplexDataType.VERSION_HISTORY,
-                 verCol.getComplexInfo().getType());
-
-    for(Map<String,Object> row : t1) {
-      String rowId = (String)row.get("id");
-      ComplexValueForeignKey complexValueFk =
-        (ComplexValueForeignKey)verCol.getRowValue(row);
-
-      String curValue = (String)col.getRowValue(row);
+    for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) {
       
-      if(rowId.equals("row1")) {
-        checkVersions(1, complexValueFk, curValue);
-      } else if(rowId.equals("row2")) {
-        checkVersions(2, complexValueFk, curValue,
-                      "row2-memo", new Date(1315876862334L));
-      } else if(rowId.equals("row3")) {
-        checkVersions(3, complexValueFk, curValue,
-                      "row3-memo-again", new Date(1315876965382L),
-                      "row3-memo-revised", new Date(1315876953077L),
-                      "row3-memo", new Date(1315876879126L));
-      } else if(rowId.equals("row4")) {
-        checkVersions(4, complexValueFk, curValue,
-                      "row4-memo", new Date(1315876945758L));
-      } else {
-        assertTrue(false);
+      Database db = openCopy(testDB);
+      db.setTimeZone(TEST_TZ);
+
+      Table t1 = db.getTable("Table1");
+      Column col = t1.getColumn("append-memo-data");
+      assertTrue(col.isAppendOnly());
+      Column verCol = col.getVersionHistoryColumn();
+      assertNotNull(verCol);
+      assertEquals(ComplexDataType.VERSION_HISTORY,
+                   verCol.getComplexInfo().getType());
+
+      for(Map<String,Object> row : t1) {
+        String rowId = (String)row.get("id");
+        ComplexValueForeignKey complexValueFk =
+          (ComplexValueForeignKey)verCol.getRowValue(row);
+
+        String curValue = (String)col.getRowValue(row);
+      
+        if(rowId.equals("row1")) {
+          checkVersions(1, complexValueFk, curValue);
+        } else if(rowId.equals("row2")) {
+          checkVersions(2, complexValueFk, curValue,
+                        "row2-memo", new Date(1315876862334L));
+        } else if(rowId.equals("row3")) {
+          checkVersions(3, complexValueFk, curValue,
+                        "row3-memo-again", new Date(1315876965382L),
+                        "row3-memo-revised", new Date(1315876953077L),
+                        "row3-memo", new Date(1315876879126L));
+        } else if(rowId.equals("row4")) {
+          checkVersions(4, complexValueFk, curValue,
+                        "row4-memo", new Date(1315876945758L));
+        } else {
+          assertTrue(false);
+        }
       }
-    }
 
-    Object[] row8 = {"row8", Column.AUTO_NUMBER, "some-data", "row8-memo",
-                     Column.AUTO_NUMBER, Column.AUTO_NUMBER};
-    t1.addRow(row8);
-
-    ComplexValueForeignKey row8ValFk = (ComplexValueForeignKey)
-      verCol.getRowValue(row8);
-    Date upTime = new Date();
-    row8ValFk.addVersion("row8-memo", upTime);
-    checkVersions(8, row8ValFk, "row8-memo",
-                  "row8-memo", upTime);    
-
-    Cursor cursor = Cursor.createCursor(t1);
-    assertTrue(cursor.findRow(t1.getColumn("id"), "row3"));
-    ComplexValueForeignKey row3ValFk = (ComplexValueForeignKey)
-      cursor.getCurrentRowValue(verCol);
-    cursor.setCurrentRowValue(col, "new-value");
-    Version v = row3ValFk.addVersion("new-value", upTime);
-    checkVersions(3, row3ValFk, "new-value",
-                  "new-value", upTime,
-                  "row3-memo-again", new Date(1315876965382L),
-                  "row3-memo-revised", new Date(1315876953077L),
-                  "row3-memo", new Date(1315876879126L));
-
-    try {
-      v.update();
-      fail("UnsupportedOperationException should have been thrown");
-    } catch(UnsupportedOperationException expected) {
-      // success
-    }
+      Object[] row8 = {"row8", Column.AUTO_NUMBER, "some-data", "row8-memo",
+                       Column.AUTO_NUMBER, Column.AUTO_NUMBER};
+      t1.addRow(row8);
+
+      ComplexValueForeignKey row8ValFk = (ComplexValueForeignKey)
+        verCol.getRowValue(row8);
+      Date upTime = new Date();
+      row8ValFk.addVersion("row8-memo", upTime);
+      checkVersions(8, row8ValFk, "row8-memo",
+                    "row8-memo", upTime);    
+
+      Cursor cursor = Cursor.createCursor(t1);
+      assertTrue(cursor.findRow(t1.getColumn("id"), "row3"));
+      ComplexValueForeignKey row3ValFk = (ComplexValueForeignKey)
+        cursor.getCurrentRowValue(verCol);
+      cursor.setCurrentRowValue(col, "new-value");
+      Version v = row3ValFk.addVersion("new-value", upTime);
+      checkVersions(3, row3ValFk, "new-value",
+                    "new-value", upTime,
+                    "row3-memo-again", new Date(1315876965382L),
+                    "row3-memo-revised", new Date(1315876953077L),
+                    "row3-memo", new Date(1315876879126L));
+
+      try {
+        v.update();
+        fail("UnsupportedOperationException should have been thrown");
+      } catch(UnsupportedOperationException expected) {
+        // success
+      }
     
-    db.close();
+      db.close();
+    }
   }
 
   public void testAttachments() throws Exception
   {
-    Database db = DatabaseTest.openCopy(Database.FileFormat.V2007, new File("/data2/jackcess_test/complexDataTest.accdb"));
-    db.setTimeZone(TEST_TZ);
-
-    Table t1 = db.getTable("Table1");
-    Column col = t1.getColumn("attach-data");
-    assertEquals(ComplexDataType.ATTACHMENT,
-                 col.getComplexInfo().getType());
-
-    for(Map<String,Object> row : t1) {
-      String rowId = (String)row.get("id");
-      ComplexValueForeignKey complexValueFk =
-        (ComplexValueForeignKey)col.getRowValue(row);
-
-      if(rowId.equals("row1")) {
-        checkAttachments(1, complexValueFk);
-      } else if(rowId.equals("row2")) {
-        checkAttachments(2, complexValueFk, "test_data.txt", "test_data2.txt");
-      } else if(rowId.equals("row3")) {
-        checkAttachments(3, complexValueFk);
-      } else if(rowId.equals("row4")) {
-        checkAttachments(4, complexValueFk, "test_data2.txt");
-      } else {
-        assertTrue(false);
+    for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) {
+      
+      Database db = openCopy(testDB);
+      db.setTimeZone(TEST_TZ);
+
+      Table t1 = db.getTable("Table1");
+      Column col = t1.getColumn("attach-data");
+      assertEquals(ComplexDataType.ATTACHMENT,
+                   col.getComplexInfo().getType());
+
+      for(Map<String,Object> row : t1) {
+        String rowId = (String)row.get("id");
+        ComplexValueForeignKey complexValueFk =
+          (ComplexValueForeignKey)col.getRowValue(row);
+
+        if(rowId.equals("row1")) {
+          checkAttachments(1, complexValueFk);
+        } else if(rowId.equals("row2")) {
+          checkAttachments(2, complexValueFk, "test_data.txt", "test_data2.txt");
+        } else if(rowId.equals("row3")) {
+          checkAttachments(3, complexValueFk);
+        } else if(rowId.equals("row4")) {
+          checkAttachments(4, complexValueFk, "test_data2.txt");
+        } else {
+          assertTrue(false);
+        }
       }
-    }
 
-    Object[] row8 = {"row8", Column.AUTO_NUMBER, "some-data", "row8-memo",
-                     Column.AUTO_NUMBER, Column.AUTO_NUMBER};
-    t1.addRow(row8);
-
-    ComplexValueForeignKey row8ValFk = (ComplexValueForeignKey)
-      col.getRowValue(row8);
-    row8ValFk.addAttachment(null, "test_data.txt", "txt",
-                            getFileBytes("test_data.txt"), null, null);
-    checkAttachments(8, row8ValFk, "test_data.txt");
-
-    Cursor cursor = Cursor.createCursor(t1);
-    assertTrue(cursor.findRow(t1.getColumn("id"), "row4"));
-    ComplexValueForeignKey row4ValFk = (ComplexValueForeignKey)
-      cursor.getCurrentRowValue(col);
-    Attachment a = row4ValFk.addAttachment(null, "test_data.txt", "txt",
-                                           getFileBytes("test_data.txt"), null,
-                                           null);
-    checkAttachments(4, row4ValFk, "test_data2.txt", "test_data.txt");
-
-    a.setFileType("xml");
-    a.setFileName("some_data.xml");
-    byte[] newBytes = "this is not xml".getBytes("US-ASCII");
-    a.setFileData(newBytes);
-    a.update();
-
-    Attachment updated = row4ValFk.getAttachments().get(1);
-    assertNotSame(updated, a);
-    assertEquals("xml", updated.getFileType());
-    assertEquals("some_data.xml", updated.getFileName());
-    assertTrue(Arrays.equals(newBytes, updated.getFileData()));
+      Object[] row8 = {"row8", Column.AUTO_NUMBER, "some-data", "row8-memo",
+                       Column.AUTO_NUMBER, Column.AUTO_NUMBER};
+      t1.addRow(row8);
+
+      ComplexValueForeignKey row8ValFk = (ComplexValueForeignKey)
+        col.getRowValue(row8);
+      row8ValFk.addAttachment(null, "test_data.txt", "txt",
+                              getFileBytes("test_data.txt"), null, null);
+      checkAttachments(8, row8ValFk, "test_data.txt");
+
+      Cursor cursor = Cursor.createCursor(t1);
+      assertTrue(cursor.findRow(t1.getColumn("id"), "row4"));
+      ComplexValueForeignKey row4ValFk = (ComplexValueForeignKey)
+        cursor.getCurrentRowValue(col);
+      Attachment a = row4ValFk.addAttachment(null, "test_data.txt", "txt",
+                                             getFileBytes("test_data.txt"), null,
+                                             null);
+      checkAttachments(4, row4ValFk, "test_data2.txt", "test_data.txt");
+
+      a.setFileType("xml");
+      a.setFileName("some_data.xml");
+      byte[] newBytes = "this is not xml".getBytes("US-ASCII");
+      a.setFileData(newBytes);
+      a.update();
+
+      Attachment updated = row4ValFk.getAttachments().get(1);
+      assertNotSame(updated, a);
+      assertEquals("xml", updated.getFileType());
+      assertEquals("some_data.xml", updated.getFileName());
+      assertTrue(Arrays.equals(newBytes, updated.getFileData()));
     
-    db.close();
+      db.close();
+    }
   }
 
   public void testMultiValues() throws Exception
   {
-    Database db = DatabaseTest.openCopy(Database.FileFormat.V2007, new File("/data2/jackcess_test/complexDataTest.accdb"));
-    db.setTimeZone(TEST_TZ);
-
-    Table t1 = db.getTable("Table1");
-    Column col = t1.getColumn("multi-value-data");
-    assertEquals(ComplexDataType.MULTI_VALUE,
-                 col.getComplexInfo().getType());
-
-    for(Map<String,Object> row : t1) {
-      String rowId = (String)row.get("id");
-      ComplexValueForeignKey complexValueFk =
-        (ComplexValueForeignKey)col.getRowValue(row);
-
-      if(rowId.equals("row1")) {
-        checkMultiValues(1, complexValueFk);
-      } else if(rowId.equals("row2")) {
-        checkMultiValues(2, complexValueFk, "value1", "value4");
-      } else if(rowId.equals("row3")) {
-        checkMultiValues(3, complexValueFk,
-                         "value1", "value2", "value3", "value4");
-      } else if(rowId.equals("row4")) {
-        checkMultiValues(4, complexValueFk);
-      } else {
-        assertTrue(false);
-      }
-    }     
-
-    Object[] row8 = {"row8", Column.AUTO_NUMBER, "some-data", "row8-memo",
-                     Column.AUTO_NUMBER, Column.AUTO_NUMBER};
-    t1.addRow(row8);
-
-    ComplexValueForeignKey row8ValFk = (ComplexValueForeignKey)
-      col.getRowValue(row8);
-    row8ValFk.addMultiValue("value1");
-    row8ValFk.addMultiValue("value2");
-    checkMultiValues(8, row8ValFk, "value1", "value2");
-
-    Cursor cursor = Cursor.createCursor(t1);
-    assertTrue(cursor.findRow(t1.getColumn("id"), "row2"));
-    ComplexValueForeignKey row2ValFk = (ComplexValueForeignKey)
-      cursor.getCurrentRowValue(col);
-    SingleValue v = row2ValFk.addMultiValue("value2");
-    row2ValFk.addMultiValue("value3");
-    checkMultiValues(2, row2ValFk, "value1", "value4", "value2", "value3");
-
-    v.set("value5");
-    v.update();
-    checkMultiValues(2, row2ValFk, "value1", "value4", "value5", "value3");
+    for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) {
+      
+      Database db = openCopy(testDB);
+      db.setTimeZone(TEST_TZ);
+
+      Table t1 = db.getTable("Table1");
+      Column col = t1.getColumn("multi-value-data");
+      assertEquals(ComplexDataType.MULTI_VALUE,
+                   col.getComplexInfo().getType());
+
+      for(Map<String,Object> row : t1) {
+        String rowId = (String)row.get("id");
+        ComplexValueForeignKey complexValueFk =
+          (ComplexValueForeignKey)col.getRowValue(row);
+
+        if(rowId.equals("row1")) {
+          checkMultiValues(1, complexValueFk);
+        } else if(rowId.equals("row2")) {
+          checkMultiValues(2, complexValueFk, "value1", "value4");
+        } else if(rowId.equals("row3")) {
+          checkMultiValues(3, complexValueFk,
+                           "value1", "value2", "value3", "value4");
+        } else if(rowId.equals("row4")) {
+          checkMultiValues(4, complexValueFk);
+        } else {
+          assertTrue(false);
+        }
+      }     
+
+      Object[] row8 = {"row8", Column.AUTO_NUMBER, "some-data", "row8-memo",
+                       Column.AUTO_NUMBER, Column.AUTO_NUMBER};
+      t1.addRow(row8);
+
+      ComplexValueForeignKey row8ValFk = (ComplexValueForeignKey)
+        col.getRowValue(row8);
+      row8ValFk.addMultiValue("value1");
+      row8ValFk.addMultiValue("value2");
+      checkMultiValues(8, row8ValFk, "value1", "value2");
+
+      Cursor cursor = Cursor.createCursor(t1);
+      assertTrue(cursor.findRow(t1.getColumn("id"), "row2"));
+      ComplexValueForeignKey row2ValFk = (ComplexValueForeignKey)
+        cursor.getCurrentRowValue(col);
+      SingleValue v = row2ValFk.addMultiValue("value2");
+      row2ValFk.addMultiValue("value3");
+      checkMultiValues(2, row2ValFk, "value1", "value4", "value2", "value3");
+
+      v.set("value5");
+      v.update();
+      checkMultiValues(2, row2ValFk, "value1", "value4", "value5", "value3");
     
-    db.close();
+      db.close();
+    }
   }
   
   private static void checkVersions(
index e60bf96c5bf83eddbe7227b93826f38c4c7083eb..22dff2deca7294f3bd4c0d766f7aea4a5d6f23a5 100644 (file)
@@ -41,7 +41,8 @@ public class JetFormatTest extends TestCase {
     TEST2("test2"),
     INDEX_CODES("testIndexCodes"),
     INDEX_PROPERTIES("testIndexProperties"),
-    PROMOTION("testPromotion");
+    PROMOTION("testPromotion"),
+    COMPLEX("complexDataTest");
 
     private final String _basename;