]> source.dussan.org Git - jackcess.git/commitdiff
reorg a bunch of utility code into the TestUtil class
authorJames Ahlborn <jtahlborn@yahoo.com>
Mon, 27 Apr 2015 02:27:15 +0000 (02:27 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Mon, 27 Apr 2015 02:27:15 +0000 (02:27 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@938 f203690c-595d-4dc9-a70b-905162fa7fd2

23 files changed:
src/test/java/com/healthmarketscience/jackcess/BigIndexTest.java
src/test/java/com/healthmarketscience/jackcess/ComplexColumnTest.java
src/test/java/com/healthmarketscience/jackcess/CursorTest.java
src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java
src/test/java/com/healthmarketscience/jackcess/IndexTest.java
src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java
src/test/java/com/healthmarketscience/jackcess/RelationshipTest.java
src/test/java/com/healthmarketscience/jackcess/TableTest.java
src/test/java/com/healthmarketscience/jackcess/TestUtil.java [new file with mode: 0644]
src/test/java/com/healthmarketscience/jackcess/impl/CalcFieldTest.java
src/test/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java
src/test/java/com/healthmarketscience/jackcess/impl/FKEnforcerTest.java
src/test/java/com/healthmarketscience/jackcess/impl/IndexCodesTest.java
src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java
src/test/java/com/healthmarketscience/jackcess/query/QueryTest.java
src/test/java/com/healthmarketscience/jackcess/util/ColumnValidatorTest.java
src/test/java/com/healthmarketscience/jackcess/util/ErrorHandlerTest.java
src/test/java/com/healthmarketscience/jackcess/util/ExportTest.java
src/test/java/com/healthmarketscience/jackcess/util/ImportTest.java
src/test/java/com/healthmarketscience/jackcess/util/JoinerTest.java
src/test/java/com/healthmarketscience/jackcess/util/MemFileChannelTest.java
src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java
src/test/java/com/healthmarketscience/jackcess/util/RowFilterTest.java

index edf950b3a56d7aefacde2faeb3d91bed07746329..0c5a22231a7c52030f934eca449151b7ab25e82f 100644 (file)
@@ -18,15 +18,14 @@ package com.healthmarketscience.jackcess;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.Random;
 
 import junit.framework.TestCase;
 
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import com.healthmarketscience.jackcess.impl.TableImpl;
 import com.healthmarketscience.jackcess.impl.IndexImpl;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  * @author james
@@ -63,7 +62,7 @@ public class BigIndexTest extends TestCase {
       assertEquals(0, index.getIndexData().getEntryCount());
       db.close();
 
-      DatabaseTest.setTestAutoSync(false);
+      TestUtil.setTestAutoSync(false);
       try {
 
         String extraText = " some random text to fill out the index and make it fill up pages with lots of extra bytes so i will keep typing until i think that i probably have enough text in the index entry so that i do not need to add as many entries in order";
@@ -192,7 +191,7 @@ public class BigIndexTest extends TestCase {
         db.close();
 
       } finally {
-        DatabaseTest.clearTestAutoSync();
+        TestUtil.clearTestAutoSync();
       }
     }
   }
index c7e134dde9ab0257d33ae5a608596ea16ef89786..a2fd2eb486b7d292d6d524fea90d852803d37191 100644 (file)
@@ -20,9 +20,7 @@ import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
-import java.util.Map;
 
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.complex.Attachment;
 import com.healthmarketscience.jackcess.complex.ComplexDataType;
 import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
@@ -31,9 +29,10 @@ import com.healthmarketscience.jackcess.complex.UnsupportedValue;
 import com.healthmarketscience.jackcess.complex.Version;
 import com.healthmarketscience.jackcess.impl.ByteUtil;
 import com.healthmarketscience.jackcess.impl.ColumnImpl;
-import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import com.healthmarketscience.jackcess.impl.PageChannel;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 
 
 /**
index 7834d18b410a3c01e7cd08b33d3d9f89021fe8d0..4ebe5f67b1ada9421689efbb637aff28b48601e5 100644 (file)
@@ -26,7 +26,6 @@ import java.util.NoSuchElementException;
 import java.util.TreeSet;
 
 import static com.healthmarketscience.jackcess.Database.*;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.impl.ColumnImpl;
 import com.healthmarketscience.jackcess.impl.JetFormatTest;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
@@ -36,6 +35,7 @@ import com.healthmarketscience.jackcess.util.ColumnMatcher;
 import com.healthmarketscience.jackcess.util.RowFilterTest;
 import com.healthmarketscience.jackcess.util.SimpleColumnMatcher;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  * @author James Ahlborn
@@ -52,12 +52,12 @@ public class CursorTest extends TestCase {
 
   @Override
   protected void setUp() {
-    DatabaseTest.setTestAutoSync(false);
+    TestUtil.setTestAutoSync(false);
   }
 
   @Override
   protected void tearDown() {
-    DatabaseTest.clearTestAutoSync();
+    TestUtil.clearTestAutoSync();
   }
 
   private static List<Map<String,Object>> createTestTableData()
index b78d7ff5dbebebf96d1b50d7c4aa58bb791ec364..95f4d6c94c0e921d0363585a15b222c383c6d07a 100644 (file)
@@ -16,19 +16,11 @@ limitations under the License.
 
 package com.healthmarketscience.jackcess;
 
-import java.io.DataInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
 import java.sql.Types;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -48,21 +40,17 @@ import java.util.TreeSet;
 import java.util.UUID;
 
 import static com.healthmarketscience.jackcess.Database.*;
-import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
-import com.healthmarketscience.jackcess.impl.ByteUtil;
 import com.healthmarketscience.jackcess.impl.ColumnImpl;
 import com.healthmarketscience.jackcess.impl.DatabaseImpl;
-import com.healthmarketscience.jackcess.impl.IndexData;
-import com.healthmarketscience.jackcess.impl.IndexImpl;
 import com.healthmarketscience.jackcess.impl.JetFormat;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import com.healthmarketscience.jackcess.impl.RowIdImpl;
 import com.healthmarketscience.jackcess.impl.RowImpl;
 import com.healthmarketscience.jackcess.impl.TableImpl;
 import com.healthmarketscience.jackcess.util.LinkResolver;
-import com.healthmarketscience.jackcess.util.MemFileChannel;
 import com.healthmarketscience.jackcess.util.RowFilterTest;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 
 /**
@@ -70,114 +58,10 @@ import junit.framework.TestCase;
  */
 public class DatabaseTest extends TestCase 
 {
-
-  public static final TimeZone TEST_TZ =
-    TimeZone.getTimeZone("America/New_York");
-  
-  private static final ThreadLocal<Boolean> _autoSync =         
-    new ThreadLocal<Boolean>();
-
-
   public DatabaseTest(String name) throws Exception {
     super(name);
   }
 
-  static void setTestAutoSync(boolean autoSync) {
-    _autoSync.set(autoSync);
-  }
-
-  static void clearTestAutoSync() {
-    _autoSync.remove();
-  }
-
-  static boolean getTestAutoSync() {
-    Boolean autoSync = _autoSync.get();
-    return ((autoSync != null) ? autoSync : Database.DEFAULT_AUTO_SYNC);
-  }
-
-  public static Database open(FileFormat fileFormat, File file) 
-    throws Exception 
-  {
-    return open(fileFormat, file, false);
-  }
-
-  private static Database open(FileFormat fileFormat, File file, 
-                               boolean inMem) 
-    throws Exception 
-  {
-    FileChannel channel = (inMem ? MemFileChannel.newChannel(file, "r") 
-                           : null);
-    final Database db = new DatabaseBuilder(file).setReadOnly(true)
-      .setAutoSync(getTestAutoSync()).setChannel(channel).open();
-    assertEquals("Wrong JetFormat.", 
-                 DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), 
-                 ((DatabaseImpl)db).getFormat());
-    assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat());
-    return db;
-  }
-
-  public static Database open(TestDB testDB) throws Exception {
-    return open(testDB.getExpectedFileFormat(), testDB.getFile());
-  }
-
-  public static Database openMem(TestDB testDB) throws Exception {
-    return open(testDB.getExpectedFileFormat(), testDB.getFile(), true);
-  }
-
-  public static Database create(FileFormat fileFormat) throws Exception {
-    return create(fileFormat, false);
-  }
-
-  public static Database create(FileFormat fileFormat, boolean keep) 
-    throws Exception 
-  {
-    return create(fileFormat, keep, false);
-  }
-
-  public static Database createMem(FileFormat fileFormat) throws Exception {
-    return create(fileFormat, false, true);
-  }
-
-  private static Database create(FileFormat fileFormat, boolean keep, 
-                                 boolean inMem) 
-    throws Exception 
-  {
-    FileChannel channel = (inMem ? MemFileChannel.newChannel() : null);
-    return new DatabaseBuilder(createTempFile(keep)).setFileFormat(fileFormat)
-      .setAutoSync(getTestAutoSync()).setChannel(channel).create();
-  }
-
-
-  public static Database openCopy(TestDB testDB) throws Exception {
-    return openCopy(testDB, false);
-  }
-
-  public static Database openCopy(TestDB testDB, boolean keep)
-    throws Exception
-  {
-    return openCopy(testDB.getExpectedFileFormat(), testDB.getFile(), keep);
-  }
-
-  public static Database openCopy(FileFormat fileFormat, File file)
-    throws Exception
-  {
-    return openCopy(fileFormat, file, false);
-  }
-
-  public static Database openCopy(FileFormat fileFormat, File file,
-                                  boolean keep)
-    throws Exception
-  {
-    File tmp = createTempFile(keep);
-    copyFile(file, tmp);
-    Database db = new DatabaseBuilder(tmp).setAutoSync(getTestAutoSync()).open();
-    assertEquals("Wrong JetFormat.", 
-                 DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(),
-                 ((DatabaseImpl)db).getFormat());
-    assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat());
-    return db;
-  }
-
 
   public void testInvalidTableDefs() throws Exception {
     for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
@@ -266,8 +150,9 @@ public class DatabaseTest extends TestCase
     }
   }
   
-  static void checkColumn(List<? extends Column> columns, int columnNumber, 
-                          String name, DataType dataType)
+  private static void checkColumn(
+      List<? extends Column> columns, int columnNumber, String name, 
+      DataType dataType)
     throws Exception
   {
     Column column = columns.get(columnNumber);
@@ -297,46 +182,6 @@ public class DatabaseTest extends TestCase
     }
   }
 
-  static void checkTestDBTable1RowABCDEFG(final TestDB testDB, final Table table, final Row row)
-          throws IOException {
-    assertEquals("testDB: " + testDB + "; table: " + table, "abcdefg", row.get("A"));
-    assertEquals("hijklmnop", row.get("B"));
-    assertEquals(new Byte((byte) 2), row.get("C"));
-    assertEquals(new Short((short) 222), row.get("D"));
-    assertEquals(new Integer(333333333), row.get("E"));
-    assertEquals(new Double(444.555d), row.get("F"));
-    final Calendar cal = Calendar.getInstance();
-    cal.setTime(row.getDate("G"));
-    assertEquals(Calendar.SEPTEMBER, cal.get(Calendar.MONTH));
-    assertEquals(21, cal.get(Calendar.DAY_OF_MONTH));
-    assertEquals(1974, cal.get(Calendar.YEAR));
-    assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
-    assertEquals(0, cal.get(Calendar.MINUTE));
-    assertEquals(0, cal.get(Calendar.SECOND));
-    assertEquals(0, cal.get(Calendar.MILLISECOND));
-    assertEquals(Boolean.TRUE, row.get("I"));
-  }
-
-  static void checkTestDBTable1RowA(final TestDB testDB, final Table table, final Row row)
-          throws IOException {
-    assertEquals("testDB: " + testDB + "; table: " + table, "a", row.get("A"));
-    assertEquals("b", row.get("B"));
-    assertEquals(new Byte((byte) 0), row.get("C"));
-    assertEquals(new Short((short) 0), row.get("D"));
-    assertEquals(new Integer(0), row.get("E"));
-    assertEquals(new Double(0d), row.get("F"));
-    final Calendar cal = Calendar.getInstance();
-    cal.setTime(row.getDate("G"));
-    assertEquals(Calendar.DECEMBER, cal.get(Calendar.MONTH));
-    assertEquals(12, cal.get(Calendar.DAY_OF_MONTH));
-    assertEquals(1981, cal.get(Calendar.YEAR));
-    assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
-    assertEquals(0, cal.get(Calendar.MINUTE));
-    assertEquals(0, cal.get(Calendar.SECOND));
-    assertEquals(0, cal.get(Calendar.MILLISECOND));
-    assertEquals(Boolean.FALSE, row.get("I"));
-  }
-
   public void testCreate() throws Exception {
     for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
       Database db = create(fileFormat);
@@ -1580,7 +1425,7 @@ public class DatabaseTest extends TestCase
     db.close();
   }
 
-  private void checkRawValue(String expected, Object val)
+  private static void checkRawValue(String expected, Object val)
   {
     if(expected != null) {
       assertTrue(ColumnImpl.isRawData(val));
@@ -1590,259 +1435,5 @@ public class DatabaseTest extends TestCase
     }
   }
     
-  static Object[] createTestRow(String col1Val) {
-    return new Object[] {col1Val, "R", "McCune", 1234, (byte) 0xad, 555.66d,
-        777.88f, (short) 999, new Date()};
-  }
-
-  static Object[] createTestRow() {
-    return createTestRow("Tim");
-  }
-  
-  static Map<String,Object> createTestRowMap(String col1Val) {
-    return createExpectedRow("A", col1Val, "B", "R", "C", "McCune",
-                             "D", 1234, "E", (byte) 0xad, "F", 555.66d,
-                             "G", 777.88f, "H", (short) 999, "I", new Date());
-  }
-
-  static void createTestTable(Database db) throws Exception {
-    new TableBuilder("test")
-      .addColumn(new ColumnBuilder("A", DataType.TEXT))
-      .addColumn(new ColumnBuilder("B", DataType.TEXT))
-      .addColumn(new ColumnBuilder("C", DataType.TEXT))
-      .addColumn(new ColumnBuilder("D", DataType.LONG))
-      .addColumn(new ColumnBuilder("E", DataType.BYTE))
-      .addColumn(new ColumnBuilder("F", DataType.DOUBLE))
-      .addColumn(new ColumnBuilder("G", DataType.FLOAT))
-      .addColumn(new ColumnBuilder("H", DataType.INT))
-      .addColumn(new ColumnBuilder("I", DataType.SHORT_DATE_TIME))
-      .toTable(db);
-  }
-
-  public static String createString(int len) {
-    return createString(len, 'a');
-  }
-
-  static String createNonAsciiString(int len) {
-    return createString(len, '\u0CC0');
-  }
-    
-  private static String createString(int len, char firstChar) {
-    StringBuilder builder = new StringBuilder(len);
-    for(int i = 0; i < len; ++i) {
-      builder.append((char)(firstChar + (i % 26)));
-    }
-    return builder.toString();
-  }
-
-  static void assertRowCount(int expectedRowCount, Table table)
-    throws Exception
-  {
-    assertEquals(expectedRowCount, countRows(table));
-    assertEquals(expectedRowCount, table.getRowCount());
-  }
-  
-  public static int countRows(Table table) throws Exception {
-    int rtn = 0;
-    for(Map<String, Object> row : CursorBuilder.createCursor(table)) {
-      rtn++;
-    }
-    return rtn;
-  }
-
-  public static void assertTable(
-      List<? extends Map<String, Object>> expectedTable, 
-      Table table)
-    throws IOException
-  {
-    assertCursor(expectedTable, CursorBuilder.createCursor(table));
-  }
-  
-  public static void assertCursor(
-      List<? extends Map<String, Object>> expectedTable, 
-      Cursor cursor)
-  {
-    List<Map<String, Object>> foundTable =
-      new ArrayList<Map<String, Object>>();
-    for(Map<String, Object> row : cursor) {
-      foundTable.add(row);
-    }
-    assertEquals(expectedTable.size(), foundTable.size());
-    for(int i = 0; i < expectedTable.size(); ++i) {
-      assertEquals(expectedTable.get(i), foundTable.get(i));
-    } 
-  }
-  
-  public static RowImpl createExpectedRow(Object... rowElements) {
-    RowImpl row = new RowImpl((RowIdImpl)null);
-    for(int i = 0; i < rowElements.length; i += 2) {
-      row.put((String)rowElements[i],
-              rowElements[i + 1]);
-    }
-    return row;
-  }    
-
-  @SuppressWarnings("unchecked")
-  public static List<Row> createExpectedTable(Row... rows) {
-    return Arrays.<Row>asList(rows);
-  }    
-  
-  static void dumpDatabase(Database mdb) throws Exception {
-    dumpDatabase(mdb, false);
-  }
-
-  static void dumpDatabase(Database mdb, boolean systemTables)
-    throws Exception
-  {
-    dumpDatabase(mdb, systemTables, new PrintWriter(System.out, true));
-  }
-
-  static void dumpTable(Table table) throws Exception {
-    dumpTable(table, new PrintWriter(System.out, true));
-  }
-
-  static void dumpDatabase(Database mdb, boolean systemTables,
-                           PrintWriter writer) throws Exception
-  {
-    writer.println("DATABASE:");
-    for(Table table : mdb) {
-      dumpTable(table, writer);
-    }
-    if(systemTables) {
-      for(String sysTableName : mdb.getSystemTableNames()) {
-        dumpTable(mdb.getSystemTable(sysTableName), writer);
-      }
-    }
-  }
-
-  static void dumpTable(Table table, PrintWriter writer) throws Exception {
-    // make sure all indexes are read
-    for(Index index : table.getIndexes()) {
-      ((IndexImpl)index).initialize();
-    }
-    
-    writer.println("TABLE: " + table.getName());
-    List<String> colNames = new ArrayList<String>();
-    for(Column col : table.getColumns()) {
-      colNames.add(col.getName());
-    }
-    writer.println("COLUMNS: " + colNames);
-    for(Map<String, Object> row : CursorBuilder.createCursor(table)) {
-      writer.println(massageRow(row));
-    }
-  }
-
-  private static Map<String,Object> massageRow(Map<String, Object> row)
-    throws IOException
-  {
-      for(Map.Entry<String, Object> entry : row.entrySet()) {
-        Object v = entry.getValue();
-        if(v instanceof byte[]) {
-          // make byte[] printable
-          byte[] bv = (byte[])v;
-          entry.setValue(ByteUtil.toHexString(ByteBuffer.wrap(bv), bv.length));
-        } else if(v instanceof ComplexValueForeignKey) {
-          // deref complex values
-          String str = "ComplexValue(" + v + ")" +
-            ((ComplexValueForeignKey)v).getValues();
-          entry.setValue(str);
-        }
-      }
-
-      return row;
-  }
-
-  static void dumpIndex(Index index) throws Exception {
-    dumpIndex(index, new PrintWriter(System.out, true));
-  }
-
-  static void dumpIndex(Index index, PrintWriter writer) throws Exception {
-    writer.println("INDEX: " + index);
-    IndexData.EntryCursor ec = ((IndexImpl)index).cursor();
-    IndexData.Entry lastE = ec.getLastEntry();
-    IndexData.Entry e = null;
-    while((e = ec.getNextEntry()) != lastE) {
-      writer.println(e);
-    }
-  }
-
-  static void assertSameDate(Date expected, Date found)
-  {
-    if(expected == found) {
-      return;
-    }
-    if((expected == null) || (found == null)) {
-      throw new AssertionError("Expected " + expected + ", found " + found);
-    }
-    long expTime = expected.getTime();
-    long foundTime = found.getTime();
-    // there are some rounding issues due to dates being stored as doubles,
-    // but it results in a 1 millisecond difference, so i'm not going to worry
-    // about it
-    if((expTime != foundTime) && (Math.abs(expTime - foundTime) > 1)) {
-      throw new AssertionError("Expected " + expTime + " (" + expected +
-                               "), found " + foundTime + " (" + found + ")");
-    }
-  }
-  
-  static void copyFile(File srcFile, File dstFile)
-    throws IOException
-  {
-    // FIXME should really be using commons io FileUtils here, but don't want
-    // to add dep for one simple test method
-    byte[] buf = new byte[1024];
-    OutputStream ostream = new FileOutputStream(dstFile);
-    InputStream istream = new FileInputStream(srcFile);
-    try {
-      int numBytes = 0;
-      while((numBytes = istream.read(buf)) >= 0) {
-        ostream.write(buf, 0, numBytes);
-      }
-    } finally {
-      ostream.close();
-    }
-  }
-
-  static File createTempFile(boolean keep) throws Exception {
-    File tmp = File.createTempFile("databaseTest", ".mdb");
-    if(keep) {
-      System.out.println("Created " + tmp);
-    } else {
-      tmp.deleteOnExit();
-    }
-    return tmp;
-  }
-
-  public static void clearTableCache(Database db) throws Exception
-  {
-    Field f = db.getClass().getDeclaredField("_tableCache");
-    f.setAccessible(true);
-    Object val = f.get(db);
-    f = val.getClass().getDeclaredField("_tables");
-    f.setAccessible(true);
-    val = f.get(val);
-    ((Map<?,?>)val).clear();
-  }
-  
-  public static byte[] toByteArray(File file)
-    throws IOException
-  {
-    return toByteArray(new FileInputStream(file), file.length());
-  }
-
-  public static byte[] toByteArray(InputStream in, long length)
-    throws IOException
-  {
-    // FIXME should really be using commons io IOUtils here, but don't want
-    // to add dep for one simple test method
-    try {
-      DataInputStream din = new DataInputStream(in);
-      byte[] bytes = new byte[(int)length];
-      din.readFully(bytes);
-      return bytes;
-    } finally {
-      in.close();
-    }
-  }
 
 }
index fbcd189769ee1a4ed9873f4c08dad603e261ceb9..28e2ff9dbb22792d467a3c97ea76bcd3b3954797 100644 (file)
@@ -26,7 +26,6 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 
 import static com.healthmarketscience.jackcess.Database.*;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.impl.ByteUtil;
 import com.healthmarketscience.jackcess.impl.IndexCodesTest;
 import com.healthmarketscience.jackcess.impl.IndexData;
@@ -35,6 +34,7 @@ import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import com.healthmarketscience.jackcess.impl.RowIdImpl;
 import com.healthmarketscience.jackcess.impl.TableImpl;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  * @author James Ahlborn
@@ -47,12 +47,12 @@ public class IndexTest extends TestCase {
 
   @Override
   protected void setUp() {
-    DatabaseTest.setTestAutoSync(false);
+    TestUtil.setTestAutoSync(false);
   }
 
   @Override
   protected void tearDown() {
-    DatabaseTest.clearTestAutoSync();
+    TestUtil.clearTestAutoSync();
   }
 
   public void testByteOrder() throws Exception {
@@ -390,9 +390,9 @@ public class IndexTest extends TestCase {
       // Row order is arbitrary, so v2007 row order difference is valid
       if (testDB.getExpectedFileFormat().ordinal() >= 
           Database.FileFormat.V2007.ordinal()) {
-        DatabaseTest.checkTestDBTable1RowA(testDB, table, row);
+        TestUtil.checkTestDBTable1RowA(testDB, table, row);
       } else {
-        DatabaseTest.checkTestDBTable1RowABCDEFG(testDB, table, row);
+        TestUtil.checkTestDBTable1RowABCDEFG(testDB, table, row);
       }
       c.deleteCurrentRow();
 
index bd74c6d85480166c06614e07d40c147f6544b68a..a5ec85909e3581ec780ce99da299dbe353c995cf 100644 (file)
@@ -31,6 +31,7 @@ import com.healthmarketscience.jackcess.impl.PropertyMapImpl;
 import com.healthmarketscience.jackcess.impl.PropertyMaps;
 import com.healthmarketscience.jackcess.impl.TableImpl;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  * @author James Ahlborn
@@ -348,7 +349,7 @@ public class PropertiesTest extends TestCase
   public void testCreateDbProperties() throws Exception
   {
     for(FileFormat ff : SUPPORTED_FILEFORMATS) {
-      File file = DatabaseTest.createTempFile(false);
+      File file = TestUtil.createTempFile(false);
       Database db = new DatabaseBuilder(file)
         .setFileFormat(ff)
         .putUserDefinedProperty("testing", "123")
index 2fe73fa5a3deffcad1399a39262fcad83472e804..0d7774d9031b02db73ef10660d05562207742b9d 100644 (file)
@@ -22,10 +22,10 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import com.healthmarketscience.jackcess.impl.RelationshipImpl;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  * @author James Ahlborn
index d3b9d2c29d07c240594d1ab99f0b76a66948bf28..339ba390407984d487c4a474b360c98cb288978b 100644 (file)
@@ -81,7 +81,7 @@ public class TableTest extends TestCase {
 
     String small = "this is a string";
     String smallNotAscii = "this is a string\0";
-    String large = DatabaseTest.createString(30);
+    String large = TestUtil.createString(30);
     String largeNotAscii = large + "\0";
 
     ByteBuffer[] buf1 = encodeColumns(small, large);
diff --git a/src/test/java/com/healthmarketscience/jackcess/TestUtil.java b/src/test/java/com/healthmarketscience/jackcess/TestUtil.java
new file mode 100644 (file)
index 0000000..25cb585
--- /dev/null
@@ -0,0 +1,455 @@
+/*
+Copyright (c) 2015 James Ahlborn
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package com.healthmarketscience.jackcess;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.lang.reflect.Field;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+
+import static com.healthmarketscience.jackcess.Database.*;
+import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
+import com.healthmarketscience.jackcess.impl.ByteUtil;
+import com.healthmarketscience.jackcess.impl.DatabaseImpl;
+import com.healthmarketscience.jackcess.impl.IndexData;
+import com.healthmarketscience.jackcess.impl.IndexImpl;
+import com.healthmarketscience.jackcess.impl.JetFormatTest.TestDB;
+import com.healthmarketscience.jackcess.impl.RowIdImpl;
+import com.healthmarketscience.jackcess.impl.RowImpl;
+import com.healthmarketscience.jackcess.util.MemFileChannel;
+import org.junit.Assert;
+
+/**
+ * Utilty code for the test cases.
+ *
+ * @author James Ahlborn
+ */
+public class TestUtil 
+{
+  public static final TimeZone TEST_TZ =
+    TimeZone.getTimeZone("America/New_York");
+  
+  private static final ThreadLocal<Boolean> _autoSync =         
+    new ThreadLocal<Boolean>();
+
+  private TestUtil() {}
+
+  static void setTestAutoSync(boolean autoSync) {
+    _autoSync.set(autoSync);
+  }
+
+  static void clearTestAutoSync() {
+    _autoSync.remove();
+  }
+
+  static boolean getTestAutoSync() {
+    Boolean autoSync = _autoSync.get();
+    return ((autoSync != null) ? autoSync : Database.DEFAULT_AUTO_SYNC);
+  }
+
+  public static Database open(FileFormat fileFormat, File file) 
+    throws Exception 
+  {
+    return open(fileFormat, file, false);
+  }
+
+  static Database open(FileFormat fileFormat, File file, boolean inMem) 
+    throws Exception 
+  {
+    FileChannel channel = (inMem ? MemFileChannel.newChannel(file, "r") 
+                           : null);
+    final Database db = new DatabaseBuilder(file).setReadOnly(true)
+      .setAutoSync(getTestAutoSync()).setChannel(channel).open();
+    Assert.assertEquals("Wrong JetFormat.", 
+                 DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), 
+                 ((DatabaseImpl)db).getFormat());
+    Assert.assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat());
+    return db;
+  }
+
+  public static Database open(TestDB testDB) throws Exception {
+    return open(testDB.getExpectedFileFormat(), testDB.getFile());
+  }
+
+  public static Database openMem(TestDB testDB) throws Exception {
+    return open(testDB.getExpectedFileFormat(), testDB.getFile(), true);
+  }
+
+  public static Database create(FileFormat fileFormat) throws Exception {
+    return create(fileFormat, false);
+  }
+
+  public static Database create(FileFormat fileFormat, boolean keep) 
+    throws Exception 
+  {
+    return create(fileFormat, keep, false);
+  }
+
+  public static Database createMem(FileFormat fileFormat) throws Exception {
+    return create(fileFormat, false, true);
+  }
+
+  private static Database create(FileFormat fileFormat, boolean keep, 
+                                 boolean inMem) 
+    throws Exception 
+  {
+    FileChannel channel = (inMem ? MemFileChannel.newChannel() : null);
+    return new DatabaseBuilder(createTempFile(keep)).setFileFormat(fileFormat)
+      .setAutoSync(getTestAutoSync()).setChannel(channel).create();
+  }
+
+
+  public static Database openCopy(TestDB testDB) throws Exception {
+    return openCopy(testDB, false);
+  }
+
+  public static Database openCopy(TestDB testDB, boolean keep)
+    throws Exception
+  {
+    return openCopy(testDB.getExpectedFileFormat(), testDB.getFile(), keep);
+  }
+
+  public static Database openCopy(FileFormat fileFormat, File file)
+    throws Exception
+  {
+    return openCopy(fileFormat, file, false);
+  }
+
+  public static Database openCopy(FileFormat fileFormat, File file,
+                                  boolean keep)
+    throws Exception
+  {
+    File tmp = createTempFile(keep);
+    copyFile(file, tmp);
+    Database db = new DatabaseBuilder(tmp).setAutoSync(getTestAutoSync()).open();
+    Assert.assertEquals("Wrong JetFormat.", 
+                 DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(),
+                 ((DatabaseImpl)db).getFormat());
+    Assert.assertEquals("Wrong FileFormat.", fileFormat, db.getFileFormat());
+    return db;
+  }
+
+
+  static Object[] createTestRow(String col1Val) {
+    return new Object[] {col1Val, "R", "McCune", 1234, (byte) 0xad, 555.66d,
+        777.88f, (short) 999, new Date()};
+  }
+
+  static Object[] createTestRow() {
+    return createTestRow("Tim");
+  }
+  
+  static Map<String,Object> createTestRowMap(String col1Val) {
+    return createExpectedRow("A", col1Val, "B", "R", "C", "McCune",
+                             "D", 1234, "E", (byte) 0xad, "F", 555.66d,
+                             "G", 777.88f, "H", (short) 999, "I", new Date());
+  }
+
+  static void createTestTable(Database db) throws Exception {
+    new TableBuilder("test")
+      .addColumn(new ColumnBuilder("A", DataType.TEXT))
+      .addColumn(new ColumnBuilder("B", DataType.TEXT))
+      .addColumn(new ColumnBuilder("C", DataType.TEXT))
+      .addColumn(new ColumnBuilder("D", DataType.LONG))
+      .addColumn(new ColumnBuilder("E", DataType.BYTE))
+      .addColumn(new ColumnBuilder("F", DataType.DOUBLE))
+      .addColumn(new ColumnBuilder("G", DataType.FLOAT))
+      .addColumn(new ColumnBuilder("H", DataType.INT))
+      .addColumn(new ColumnBuilder("I", DataType.SHORT_DATE_TIME))
+      .toTable(db);
+  }
+
+  public static String createString(int len) {
+    return createString(len, 'a');
+  }
+
+  static String createNonAsciiString(int len) {
+    return createString(len, '\u0CC0');
+  }
+    
+  private static String createString(int len, char firstChar) {
+    StringBuilder builder = new StringBuilder(len);
+    for(int i = 0; i < len; ++i) {
+      builder.append((char)(firstChar + (i % 26)));
+    }
+    return builder.toString();
+  }
+
+  static void assertRowCount(int expectedRowCount, Table table)
+    throws Exception
+  {
+    Assert.assertEquals(expectedRowCount, countRows(table));
+    Assert.assertEquals(expectedRowCount, table.getRowCount());
+  }
+  
+  public static int countRows(Table table) throws Exception {
+    int rtn = 0;
+    for(Map<String, Object> row : CursorBuilder.createCursor(table)) {
+      rtn++;
+    }
+    return rtn;
+  }
+
+  public static void assertTable(
+      List<? extends Map<String, Object>> expectedTable, 
+      Table table)
+    throws IOException
+  {
+    assertCursor(expectedTable, CursorBuilder.createCursor(table));
+  }
+  
+  public static void assertCursor(
+      List<? extends Map<String, Object>> expectedTable, 
+      Cursor cursor)
+  {
+    List<Map<String, Object>> foundTable =
+      new ArrayList<Map<String, Object>>();
+    for(Map<String, Object> row : cursor) {
+      foundTable.add(row);
+    }
+    Assert.assertEquals(expectedTable.size(), foundTable.size());
+    for(int i = 0; i < expectedTable.size(); ++i) {
+      Assert.assertEquals(expectedTable.get(i), foundTable.get(i));
+    } 
+  }
+  
+  public static RowImpl createExpectedRow(Object... rowElements) {
+    RowImpl row = new RowImpl((RowIdImpl)null);
+    for(int i = 0; i < rowElements.length; i += 2) {
+      row.put((String)rowElements[i],
+              rowElements[i + 1]);
+    }
+    return row;
+  }    
+
+  public static List<Row> createExpectedTable(Row... rows) {
+    return Arrays.<Row>asList(rows);
+  }    
+  
+  static void dumpDatabase(Database mdb) throws Exception {
+    dumpDatabase(mdb, false);
+  }
+
+  static void dumpDatabase(Database mdb, boolean systemTables)
+    throws Exception
+  {
+    dumpDatabase(mdb, systemTables, new PrintWriter(System.out, true));
+  }
+
+  static void dumpTable(Table table) throws Exception {
+    dumpTable(table, new PrintWriter(System.out, true));
+  }
+
+  static void dumpDatabase(Database mdb, boolean systemTables,
+                           PrintWriter writer) throws Exception
+  {
+    writer.println("DATABASE:");
+    for(Table table : mdb) {
+      dumpTable(table, writer);
+    }
+    if(systemTables) {
+      for(String sysTableName : mdb.getSystemTableNames()) {
+        dumpTable(mdb.getSystemTable(sysTableName), writer);
+      }
+    }
+  }
+
+  static void dumpTable(Table table, PrintWriter writer) throws Exception {
+    // make sure all indexes are read
+    for(Index index : table.getIndexes()) {
+      ((IndexImpl)index).initialize();
+    }
+    
+    writer.println("TABLE: " + table.getName());
+    List<String> colNames = new ArrayList<String>();
+    for(Column col : table.getColumns()) {
+      colNames.add(col.getName());
+    }
+    writer.println("COLUMNS: " + colNames);
+    for(Map<String, Object> row : CursorBuilder.createCursor(table)) {
+      writer.println(massageRow(row));
+    }
+  }
+
+  private static Map<String,Object> massageRow(Map<String, Object> row)
+    throws IOException
+  {
+      for(Map.Entry<String, Object> entry : row.entrySet()) {
+        Object v = entry.getValue();
+        if(v instanceof byte[]) {
+          // make byte[] printable
+          byte[] bv = (byte[])v;
+          entry.setValue(ByteUtil.toHexString(ByteBuffer.wrap(bv), bv.length));
+        } else if(v instanceof ComplexValueForeignKey) {
+          // deref complex values
+          String str = "ComplexValue(" + v + ")" +
+            ((ComplexValueForeignKey)v).getValues();
+          entry.setValue(str);
+        }
+      }
+
+      return row;
+  }
+
+  static void dumpIndex(Index index) throws Exception {
+    dumpIndex(index, new PrintWriter(System.out, true));
+  }
+
+  static void dumpIndex(Index index, PrintWriter writer) throws Exception {
+    writer.println("INDEX: " + index);
+    IndexData.EntryCursor ec = ((IndexImpl)index).cursor();
+    IndexData.Entry lastE = ec.getLastEntry();
+    IndexData.Entry e = null;
+    while((e = ec.getNextEntry()) != lastE) {
+      writer.println(e);
+    }
+  }
+
+  static void assertSameDate(Date expected, Date found)
+  {
+    if(expected == found) {
+      return;
+    }
+    if((expected == null) || (found == null)) {
+      throw new AssertionError("Expected " + expected + ", found " + found);
+    }
+    long expTime = expected.getTime();
+    long foundTime = found.getTime();
+    // there are some rounding issues due to dates being stored as doubles,
+    // but it results in a 1 millisecond difference, so i'm not going to worry
+    // about it
+    if((expTime != foundTime) && (Math.abs(expTime - foundTime) > 1)) {
+      throw new AssertionError("Expected " + expTime + " (" + expected +
+                               "), found " + foundTime + " (" + found + ")");
+    }
+  }
+  
+  static void copyFile(File srcFile, File dstFile)
+    throws IOException
+  {
+    // FIXME should really be using commons io FileUtils here, but don't want
+    // to add dep for one simple test method
+    byte[] buf = new byte[1024];
+    OutputStream ostream = new FileOutputStream(dstFile);
+    InputStream istream = new FileInputStream(srcFile);
+    try {
+      int numBytes = 0;
+      while((numBytes = istream.read(buf)) >= 0) {
+        ostream.write(buf, 0, numBytes);
+      }
+    } finally {
+      ostream.close();
+    }
+  }
+
+  static File createTempFile(boolean keep) throws Exception {
+    File tmp = File.createTempFile("databaseTest", ".mdb");
+    if(keep) {
+      System.out.println("Created " + tmp);
+    } else {
+      tmp.deleteOnExit();
+    }
+    return tmp;
+  }
+
+  public static void clearTableCache(Database db) throws Exception
+  {
+    Field f = db.getClass().getDeclaredField("_tableCache");
+    f.setAccessible(true);
+    Object val = f.get(db);
+    f = val.getClass().getDeclaredField("_tables");
+    f.setAccessible(true);
+    val = f.get(val);
+    ((Map<?,?>)val).clear();
+  }
+  
+  public static byte[] toByteArray(File file)
+    throws IOException
+  {
+    return toByteArray(new FileInputStream(file), file.length());
+  }
+
+  public static byte[] toByteArray(InputStream in, long length)
+    throws IOException
+  {
+    // FIXME should really be using commons io IOUtils here, but don't want
+    // to add dep for one simple test method
+    try {
+      DataInputStream din = new DataInputStream(in);
+      byte[] bytes = new byte[(int)length];
+      din.readFully(bytes);
+      return bytes;
+    } finally {
+      in.close();
+    }
+  }
+
+  static void checkTestDBTable1RowABCDEFG(final TestDB testDB, final Table table, final Row row)
+          throws IOException {
+    Assert.assertEquals("testDB: " + testDB + "; table: " + table, "abcdefg", row.get("A"));
+    Assert.assertEquals("hijklmnop", row.get("B"));
+    Assert.assertEquals(new Byte((byte) 2), row.get("C"));
+    Assert.assertEquals(new Short((short) 222), row.get("D"));
+    Assert.assertEquals(new Integer(333333333), row.get("E"));
+    Assert.assertEquals(new Double(444.555d), row.get("F"));
+    final Calendar cal = Calendar.getInstance();
+    cal.setTime(row.getDate("G"));
+    Assert.assertEquals(Calendar.SEPTEMBER, cal.get(Calendar.MONTH));
+    Assert.assertEquals(21, cal.get(Calendar.DAY_OF_MONTH));
+    Assert.assertEquals(1974, cal.get(Calendar.YEAR));
+    Assert.assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
+    Assert.assertEquals(0, cal.get(Calendar.MINUTE));
+    Assert.assertEquals(0, cal.get(Calendar.SECOND));
+    Assert.assertEquals(0, cal.get(Calendar.MILLISECOND));
+    Assert.assertEquals(Boolean.TRUE, row.get("I"));
+  }
+
+  static void checkTestDBTable1RowA(final TestDB testDB, final Table table, final Row row)
+          throws IOException {
+    Assert.assertEquals("testDB: " + testDB + "; table: " + table, "a", row.get("A"));
+    Assert.assertEquals("b", row.get("B"));
+    Assert.assertEquals(new Byte((byte) 0), row.get("C"));
+    Assert.assertEquals(new Short((short) 0), row.get("D"));
+    Assert.assertEquals(new Integer(0), row.get("E"));
+    Assert.assertEquals(new Double(0d), row.get("F"));
+    final Calendar cal = Calendar.getInstance();
+    cal.setTime(row.getDate("G"));
+    Assert.assertEquals(Calendar.DECEMBER, cal.get(Calendar.MONTH));
+    Assert.assertEquals(12, cal.get(Calendar.DAY_OF_MONTH));
+    Assert.assertEquals(1981, cal.get(Calendar.YEAR));
+    Assert.assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
+    Assert.assertEquals(0, cal.get(Calendar.MINUTE));
+    Assert.assertEquals(0, cal.get(Calendar.SECOND));
+    Assert.assertEquals(0, cal.get(Calendar.MILLISECOND));
+    Assert.assertEquals(Boolean.FALSE, row.get("I"));
+  }
+
+}
index 959662b1329830463627e3bc6936435a074ff2aa..b5afcd37800c07c6e0f88605b1b81b27d699d006 100644 (file)
@@ -27,13 +27,13 @@ import com.healthmarketscience.jackcess.Column;
 import com.healthmarketscience.jackcess.ColumnBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.PropertyMap;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.TableBuilder;
-import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 
 /**
  *
index 1ff7b18a08c1e2a9a939afe79c81f282d4216e9f..d6c788c463857786bd0e1d3e167dc72335fd561d 100644 (file)
@@ -29,13 +29,13 @@ import com.healthmarketscience.jackcess.Cursor;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
 import com.healthmarketscience.jackcess.DatabaseBuilder;
-import com.healthmarketscience.jackcess.DatabaseTest;
 import com.healthmarketscience.jackcess.IndexBuilder;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.TableBuilder;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import junit.framework.TestCase;
+import com.healthmarketscience.jackcess.TestUtil;
 
 /**
  *
@@ -72,7 +72,7 @@ public class CodecHandlerTest extends TestCase
   private static void doTestCodecHandler(boolean simple) throws Exception
   {
     for(Database.FileFormat ff : SUPPORTED_FILEFORMATS) {
-      Database db = DatabaseTest.create(ff);
+      Database db = TestUtil.create(ff);
       int pageSize = ((DatabaseImpl)db).getFormat().PAGE_SIZE;
       File dbFile = db.getFile();
       db.close();
@@ -115,8 +115,8 @@ public class CodecHandlerTest extends TestCase
     ((DatabaseImpl)db).getPageChannel().startWrite();
     try {
       for(int i = start; i < end; ++i) {
-        t1.addRow(null, "rowdata-" + i + DatabaseTest.createString(100));
-        t2.addRow(null, "rowdata-" + i + DatabaseTest.createString(100));
+        t1.addRow(null, "rowdata-" + i + TestUtil.createString(100));
+        t2.addRow(null, "rowdata-" + i + TestUtil.createString(100));
       }
     } finally {
       ((DatabaseImpl)db).getPageChannel().finishWrite();
index 66a0ae315c3d86270847c971976199d1abbb5d31..c3150ea64df415cddd6ca543bc3bea1db2d9c0f7 100644 (file)
@@ -25,11 +25,11 @@ import com.healthmarketscience.jackcess.Column;
 import com.healthmarketscience.jackcess.Cursor;
 import com.healthmarketscience.jackcess.CursorBuilder;
 import com.healthmarketscience.jackcess.Database;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  *
index ca1fde7b81ef3aa1ffdb77eebe0e030388565669..5b7a44036c473a77199b8e6eb15d61038a89b545 100644 (file)
@@ -31,13 +31,13 @@ import com.healthmarketscience.jackcess.Cursor;
 import com.healthmarketscience.jackcess.CursorBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.Index;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.TableBuilder;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  * @author James Ahlborn
index c73e777f592a0f6bc26cc39699441135435c3819..f84cc16c1815f028140148ad44e909472e30b592 100644 (file)
@@ -11,8 +11,8 @@ import java.util.Set;
 import com.healthmarketscience.jackcess.Database;
 import static com.healthmarketscience.jackcess.Database.*;
 import com.healthmarketscience.jackcess.DatabaseBuilder;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 
 /**
index d7129173eb17489c99d7e0ce94212d9e3162d46d..3af50ec22f2388227dd6488d2043e887f63394d1 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Map;
 
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
-import com.healthmarketscience.jackcess.DatabaseTest;
+import com.healthmarketscience.jackcess.TestUtil;
 import com.healthmarketscience.jackcess.impl.query.QueryImpl;
 import com.healthmarketscience.jackcess.impl.query.QueryImpl.Row;
 import junit.framework.TestCase;
@@ -245,7 +245,7 @@ public class QueryTest extends TestCase
           "DataDefinitionQuery", multiline(
               "CREATE TABLE Table5 (col1 CHAR, col2 CHAR);\0"));
 
-      Database db = DatabaseTest.open(testDB);
+      Database db = TestUtil.open(testDB);
 
       for(Query q : db.getQueries()) {
         assertEquals(expectedQueries.remove(q.getName()), q.toSQLString());
index d5ebbed7fdc2b4274f7bbbac7db333cc577908ca..e3634d009adc63f438d10b30f14577ec4f7586e3 100644 (file)
@@ -19,19 +19,19 @@ package com.healthmarketscience.jackcess.util;
 import java.util.List;
 import java.util.Map;
 
+import static com.healthmarketscience.jackcess.Database.*;
 import com.healthmarketscience.jackcess.Column;
 import com.healthmarketscience.jackcess.ColumnBuilder;
 import com.healthmarketscience.jackcess.CursorBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
-import static com.healthmarketscience.jackcess.Database.*;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.IndexCursor;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.TableBuilder;
-import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 
 /**
  *
index d95f6cff6d023d4624d43a88b8187abd660c23c1..dbc7f940292ae474aeafb04ba1eab21e5a3080dc 100644 (file)
@@ -22,20 +22,20 @@ import java.lang.reflect.Modifier;
 import java.nio.ByteOrder;
 import java.util.List;
 
+import static com.healthmarketscience.jackcess.Database.*;
 import com.healthmarketscience.jackcess.Column;
 import com.healthmarketscience.jackcess.ColumnBuilder;
 import com.healthmarketscience.jackcess.Cursor;
 import com.healthmarketscience.jackcess.CursorBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
-import static com.healthmarketscience.jackcess.Database.*;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.TableBuilder;
 import com.healthmarketscience.jackcess.impl.ColumnImpl;
 import com.healthmarketscience.jackcess.impl.JetFormatTest;
 import com.healthmarketscience.jackcess.impl.TableImpl;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  * @author James Ahlborn
index 128e81cc50ec648636437ccd0db501d07de6f5c7..754be060aec42650eab11f03bfb049aa10dd3b94 100644 (file)
@@ -22,16 +22,16 @@ import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
+import static com.healthmarketscience.jackcess.Database.*;
 import com.healthmarketscience.jackcess.ColumnBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
-import static com.healthmarketscience.jackcess.Database.*;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.TableBuilder;
 import com.healthmarketscience.jackcess.impl.JetFormatTest;
 import junit.framework.TestCase;
 import org.apache.commons.lang.SystemUtils;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  *
index 5ff9a5228c1252ea56c7a8f78e28fbe0561432ef..51241aacccec26b58598539b5a53a68ef7b2bddd 100644 (file)
@@ -33,11 +33,11 @@ import com.healthmarketscience.jackcess.ColumnBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
 import static com.healthmarketscience.jackcess.Database.*;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.TableBuilder;
 import com.healthmarketscience.jackcess.impl.JetFormatTest;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /** 
  *  @author Rob Di Marco
index e0c5575effef03d114a609e039f8913d57105265..986c8b555afe041382fbedfa27f781f9a11462e3 100644 (file)
@@ -25,13 +25,13 @@ import java.util.Map;
 import java.util.Set;
 
 import com.healthmarketscience.jackcess.Database;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.Index;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.impl.RowImpl;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  *
index 711ed8b3e65bbf7ed308aed7fdf024497d9027a0..58b8e603edd680c390c02d07d59e2741576ba26e 100644 (file)
@@ -19,7 +19,6 @@ package com.healthmarketscience.jackcess.util;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.NonWritableChannelException;
@@ -27,7 +26,7 @@ import java.util.Arrays;
 
 import junit.framework.TestCase;
 
-import com.healthmarketscience.jackcess.DatabaseTest;
+import com.healthmarketscience.jackcess.TestUtil;
 
 /**
  *
@@ -131,8 +130,8 @@ public class MemFileChannelTest extends TestCase
 
     assertEquals(testFile.length(), tmpFile.length());
 
-    assertTrue(Arrays.equals(DatabaseTest.toByteArray(testFile),
-                             DatabaseTest.toByteArray(tmpFile)));
+    assertTrue(Arrays.equals(TestUtil.toByteArray(testFile),
+                             TestUtil.toByteArray(tmpFile)));
 
     ch2.truncate(0L);
     assertTrue(ch2.isOpen());
index e9c2020033883ad7270031759e96bd4e486645a9..be3a0a9af2a610e37fba5b584e9d0f4d58e26690 100644 (file)
@@ -25,19 +25,18 @@ import com.healthmarketscience.jackcess.ColumnBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
 import com.healthmarketscience.jackcess.Database.FileFormat;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.TableBuilder;
 import com.healthmarketscience.jackcess.complex.Attachment;
-import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
 import com.healthmarketscience.jackcess.impl.ByteUtil;
 import com.healthmarketscience.jackcess.impl.CompoundOleUtil;
-import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import junit.framework.TestCase;
 import org.apache.poi.poifs.filesystem.DocumentEntry;
 import org.apache.poi.poifs.filesystem.DocumentInputStream;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
+import static com.healthmarketscience.jackcess.TestUtil.*;
+import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 
 /**
  *
index 85058cdfd66a5aa29e3be46e8bbab876e6ed7809..4a247d92a04e486c7077509b1344f318f91a6e06 100644 (file)
@@ -21,10 +21,10 @@ import java.util.Arrays;
 import java.util.List;
 
 import com.healthmarketscience.jackcess.DataType;
-import static com.healthmarketscience.jackcess.DatabaseTest.*;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.impl.ColumnImpl;
 import junit.framework.TestCase;
+import static com.healthmarketscience.jackcess.TestUtil.*;
 
 /**
  * @author James Ahlborn