@@ -0,0 +1,2 @@ | |||
/target/ | |||
nb-configuration.xml |
@@ -10,6 +10,13 @@ | |||
<name>Jackcess</name> | |||
<description>A pure Java library for reading from and writing to MS Access databases.</description> | |||
<version>4.0.6-SNAPSHOT</version> | |||
<properties> | |||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |||
<junit.version>5.10.0</junit.version> | |||
</properties> | |||
<url>https://jackcess.sourceforge.io</url> | |||
<inceptionYear>2005</inceptionYear> | |||
<developers> | |||
@@ -255,9 +262,21 @@ | |||
<version>1.2</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>junit</groupId> | |||
<artifactId>junit</artifactId> | |||
<version>4.13.1</version> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter-api</artifactId> | |||
<version>${junit.version}</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter-params</artifactId> | |||
<version>${junit.version}</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter-engine</artifactId> | |||
<version>${junit.version}</version> | |||
<scope>test</scope> | |||
</dependency> | |||
@@ -20,22 +20,19 @@ import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Random; | |||
import junit.framework.TestCase; | |||
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.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author james | |||
*/ | |||
public class BigIndexTest extends TestCase { | |||
public BigIndexTest(String name) { | |||
super(name); | |||
} | |||
public class BigIndexTest | |||
{ | |||
@Test | |||
public void testComplexIndex() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX, true)) { | |||
@@ -50,6 +47,7 @@ public class BigIndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testBigIndex() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.BIG_INDEX)) { | |||
@@ -119,8 +117,7 @@ public class BigIndexTest extends TestCase { | |||
if(val == null) { | |||
val = firstValue; | |||
} | |||
assertTrue("" + prevValue + " <= " + val + " " + rowCount, | |||
prevValue.compareTo(val) <= 0); | |||
assertTrue(prevValue.compareTo(val) <= 0, "" + prevValue + " <= " + val + " " + rowCount); | |||
if(firstTwo.size() < 2) { | |||
firstTwo.add(origVal); | |||
} |
@@ -30,9 +30,10 @@ import com.healthmarketscience.jackcess.complex.Version; | |||
import com.healthmarketscience.jackcess.impl.ByteUtil; | |||
import com.healthmarketscience.jackcess.impl.ColumnImpl; | |||
import com.healthmarketscience.jackcess.impl.PageChannel; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
@@ -40,13 +41,9 @@ import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
* @author James Ahlborn | |||
*/ | |||
@SuppressWarnings("deprecation") | |||
public class ComplexColumnTest extends TestCase | |||
public class ComplexColumnTest | |||
{ | |||
public ComplexColumnTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testVersions() throws Exception | |||
{ | |||
for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { | |||
@@ -110,12 +107,7 @@ public class ComplexColumnTest extends TestCase | |||
"row3-memo-revised", new Date(1315876953077L), | |||
"row3-memo", new Date(1315876879126L)); | |||
try { | |||
v.update(); | |||
fail("UnsupportedOperationException should have been thrown"); | |||
} catch(UnsupportedOperationException expected) { | |||
// success | |||
} | |||
assertThrows(UnsupportedOperationException.class, () -> v.update()); | |||
checkVersions(3, row3ValFk, "new-value", | |||
"new-value", upTime, | |||
@@ -123,12 +115,7 @@ public class ComplexColumnTest extends TestCase | |||
"row3-memo-revised", new Date(1315876953077L), | |||
"row3-memo", new Date(1315876879126L)); | |||
try { | |||
v.delete(); | |||
fail("UnsupportedOperationException should have been thrown"); | |||
} catch(UnsupportedOperationException expected) { | |||
// success | |||
} | |||
assertThrows(UnsupportedOperationException.class, () -> v.delete()); | |||
checkVersions(3, row3ValFk, "new-value", | |||
"new-value", upTime, | |||
@@ -136,12 +123,8 @@ public class ComplexColumnTest extends TestCase | |||
"row3-memo-revised", new Date(1315876953077L), | |||
"row3-memo", new Date(1315876879126L)); | |||
try { | |||
v.getComplexValueForeignKey().deleteAllValues(); | |||
fail("UnsupportedOperationException should have been thrown"); | |||
} catch(UnsupportedOperationException expected) { | |||
// success | |||
} | |||
assertThrows(UnsupportedOperationException.class, | |||
() -> v.getComplexValueForeignKey().deleteAllValues()); | |||
checkVersions(3, row3ValFk, "new-value", | |||
"new-value", upTime, | |||
@@ -153,6 +136,7 @@ public class ComplexColumnTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testAttachments() throws Exception | |||
{ | |||
for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { | |||
@@ -238,6 +222,7 @@ public class ComplexColumnTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testMultiValues() throws Exception | |||
{ | |||
for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { | |||
@@ -316,6 +301,7 @@ public class ComplexColumnTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testUnsupported() throws Exception | |||
{ | |||
for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.UNSUPPORTED)) { |
@@ -16,20 +16,16 @@ limitations under the License. | |||
package com.healthmarketscience.jackcess; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import com.healthmarketscience.jackcess.impl.IndexImpl; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class CursorBuilderTest extends TestCase { | |||
public CursorBuilderTest(String name) throws Exception { | |||
super(name); | |||
} | |||
public class CursorBuilderTest | |||
{ | |||
private static void assertCursor( | |||
Cursor expected, Cursor found) | |||
{ | |||
@@ -43,6 +39,7 @@ public class CursorBuilderTest extends TestCase { | |||
found.getSavepoint().getCurrentPosition()); | |||
} | |||
@Test | |||
public void test() throws Exception | |||
{ | |||
for (final TestDB indexCursorDB : CursorTest.INDEX_CURSOR_DBS) { | |||
@@ -66,13 +63,8 @@ public class CursorBuilderTest extends TestCase { | |||
.toCursor(); | |||
assertCursor(expected, found); | |||
try { | |||
table.newCursor() | |||
.setIndexByName("foo"); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException ignored) { | |||
// success | |||
} | |||
assertThrows(IllegalArgumentException.class, | |||
() -> table.newCursor().setIndexByName("foo")); | |||
expected = CursorBuilder.createCursor(idx); | |||
found = table.newCursor() | |||
@@ -80,21 +72,11 @@ public class CursorBuilderTest extends TestCase { | |||
.toCursor(); | |||
assertCursor(expected, found); | |||
try { | |||
table.newCursor() | |||
.setIndexByColumns(table.getColumn("value")); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException ignored) { | |||
// success | |||
} | |||
try { | |||
table.newCursor() | |||
.setIndexByColumns(table.getColumn("id"), table.getColumn("value")); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException ignored) { | |||
// success | |||
} | |||
assertThrows(IllegalArgumentException.class, | |||
() -> table.newCursor().setIndexByColumns(table.getColumn("value"))); | |||
assertThrows(IllegalArgumentException.class, | |||
() -> table.newCursor().setIndexByColumns(table.getColumn("id"), table.getColumn("value"))); | |||
expected = CursorBuilder.createCursor(table); | |||
expected.beforeFirst(); |
@@ -36,29 +36,29 @@ import com.healthmarketscience.jackcess.util.CaseInsensitiveColumnMatcher; | |||
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.*; | |||
import static com.healthmarketscience.jackcess.DatabaseBuilder.*; | |||
import org.junit.jupiter.api.AfterEach; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.BeforeEach; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class CursorTest extends TestCase { | |||
public class CursorTest | |||
{ | |||
static final List<TestDB> INDEX_CURSOR_DBS = | |||
TestDB.getSupportedForBasename(Basename.INDEX_CURSOR); | |||
public CursorTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Override | |||
@BeforeEach | |||
protected void setUp() { | |||
TestUtil.setTestAutoSync(false); | |||
} | |||
@Override | |||
@AfterEach | |||
protected void tearDown() { | |||
TestUtil.clearTestAutoSync(); | |||
} | |||
@@ -188,6 +188,7 @@ public class CursorTest extends TestCase { | |||
.toCursor(); | |||
} | |||
@Test | |||
public void testRowId() throws Exception { | |||
// test special cases | |||
RowIdImpl rowId1 = new RowIdImpl(1, 2); | |||
@@ -204,6 +205,7 @@ public class CursorTest extends TestCase { | |||
sortedRowIds); | |||
} | |||
@Test | |||
public void testSimple() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createTestTable(fileFormat); | |||
@@ -231,6 +233,7 @@ public class CursorTest extends TestCase { | |||
assertEquals(expectedRows, foundRows); | |||
} | |||
@Test | |||
public void testMove() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createTestTable(fileFormat); | |||
@@ -290,6 +293,7 @@ public class CursorTest extends TestCase { | |||
assertEquals(expectedRow, cursor.getCurrentRow()); | |||
} | |||
@Test | |||
public void testMoveNoReset() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createTestTable(fileFormat); | |||
@@ -333,6 +337,7 @@ public class CursorTest extends TestCase { | |||
assertEquals(expectedRows, foundRows); | |||
} | |||
@Test | |||
public void testSearch() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createTestTable(fileFormat); | |||
@@ -417,6 +422,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testReverse() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createTestTable(fileFormat); | |||
@@ -446,6 +452,7 @@ public class CursorTest extends TestCase { | |||
assertEquals(expectedRows, foundRows); | |||
} | |||
@Test | |||
public void testLiveAddition() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createTestTable(fileFormat); | |||
@@ -487,6 +494,7 @@ public class CursorTest extends TestCase { | |||
} | |||
@Test | |||
public void testLiveDeletion() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createTestTable(fileFormat); | |||
@@ -580,6 +588,7 @@ public class CursorTest extends TestCase { | |||
assertTrue(cursor4.isCurrentRowDeleted()); | |||
} | |||
@Test | |||
public void testSimpleIndex() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
Database db = createTestIndexTable(indexCursorDB); | |||
@@ -596,6 +605,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testMoveIndex() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
Database db = createTestIndexTable(indexCursorDB); | |||
@@ -609,6 +619,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testReverseIndex() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
Database db = createTestIndexTable(indexCursorDB); | |||
@@ -622,6 +633,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testSearchIndex() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
Database db = createTestIndexTable(indexCursorDB); | |||
@@ -635,6 +647,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testLiveAdditionIndex() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
Database db = createTestIndexTable(indexCursorDB); | |||
@@ -650,6 +663,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testLiveDeletionIndex() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
Database db = createTestIndexTable(indexCursorDB); | |||
@@ -667,6 +681,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testSimpleIndexSubRange() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
for(int i = 0; i < 2; ++i) { | |||
@@ -687,6 +702,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testMoveIndexSubRange() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
for(int i = 0; i < 2; ++i) { | |||
@@ -707,6 +723,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testSearchIndexSubRange() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
for(int i = 0; i < 2; ++i) { | |||
@@ -724,6 +741,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testReverseIndexSubRange() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
for(int i = 0; i < 2; ++i) { | |||
@@ -744,6 +762,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testLiveAdditionIndexSubRange() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
for(int i = 0; i < 2; ++i) { | |||
@@ -762,6 +781,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testLiveDeletionIndexSubRange() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
for(int i = 0; i < 2; ++i) { | |||
@@ -782,6 +802,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testFindAllIndex() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createDupeTestTable(fileFormat); | |||
@@ -795,6 +816,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testFindAll() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
Database db = createDupeTestTable(indexCursorDB); | |||
@@ -906,6 +928,7 @@ public class CursorTest extends TestCase { | |||
assertTrue(rows.isEmpty()); | |||
} | |||
@Test | |||
public void testId() throws Exception | |||
{ | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
@@ -923,19 +946,9 @@ public class CursorTest extends TestCase { | |||
tCursor.restoreSavepoint(tSave); | |||
iCursor.restoreSavepoint(iSave); | |||
try { | |||
tCursor.restoreSavepoint(iSave); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
assertThrows(IllegalArgumentException.class, () -> tCursor.restoreSavepoint(iSave)); | |||
try { | |||
iCursor.restoreSavepoint(tSave); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
assertThrows(IllegalArgumentException.class, () -> iCursor.restoreSavepoint(tSave)); | |||
Cursor tCursor2 = CursorBuilder.createCursor(table); | |||
Cursor iCursor2 = CursorBuilder.createCursor(idx); | |||
@@ -947,6 +960,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testColumnMatcher() throws Exception { | |||
@@ -1068,6 +1082,7 @@ public class CursorTest extends TestCase { | |||
.setColumnMatcher(CaseInsensitiveColumnMatcher.INSTANCE))); | |||
} | |||
@Test | |||
public void testIndexCursor() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { | |||
@@ -1095,6 +1110,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testIndexCursorDelete() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) { | |||
@@ -1117,20 +1133,10 @@ public class CursorTest extends TestCase { | |||
iter.hasNext(); ) { | |||
expectedData.add(iter.next().getString("data")); | |||
iter.remove(); | |||
try { | |||
iter.remove(); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalStateException e) { | |||
// success | |||
} | |||
assertThrows(IllegalStateException.class, () -> iter.remove()); | |||
if(!iter.hasNext()) { | |||
try { | |||
iter.next(); | |||
fail("NoSuchElementException should have been thrown"); | |||
} catch(NoSuchElementException e) { | |||
// success | |||
} | |||
if (!iter.hasNext()) { | |||
assertThrows(NoSuchElementException.class, () -> iter.next()); | |||
} | |||
} | |||
@@ -1148,6 +1154,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testCursorDelete() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) { | |||
@@ -1171,21 +1178,11 @@ public class CursorTest extends TestCase { | |||
if(row.get("otherfk1").equals(1)) { | |||
expectedData.add(row.getString("data")); | |||
iter.remove(); | |||
try { | |||
iter.remove(); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalStateException e) { | |||
// success | |||
} | |||
assertThrows(IllegalStateException.class, () -> iter.remove()); | |||
} | |||
if(!iter.hasNext()) { | |||
try { | |||
iter.next(); | |||
fail("NoSuchElementException should have been thrown"); | |||
} catch(NoSuchElementException e) { | |||
// success | |||
} | |||
if (!iter.hasNext()) { | |||
assertThrows(NoSuchElementException.class, () -> iter.next()); | |||
} | |||
} | |||
@@ -1205,6 +1202,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testFindByRowId() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = createTestTable(fileFormat); | |||
@@ -1216,6 +1214,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testFindByRowIdIndex() throws Exception { | |||
for (final TestDB indexCursorDB : INDEX_CURSOR_DBS) { | |||
Database db = createTestIndexTable(indexCursorDB); | |||
@@ -1275,6 +1274,7 @@ public class CursorTest extends TestCase { | |||
assertEquals(id - 1, cursor.getCurrentRow().get("id")); | |||
} | |||
@Test | |||
public void testIterationEarlyExit() throws Exception { | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
@@ -1301,15 +1301,10 @@ public class CursorTest extends TestCase { | |||
IndexCursor cursor = CursorBuilder.createCursor( | |||
table.getIndex("value_idx")); | |||
try { | |||
cursor.newIterable() | |||
.addMatchPattern("value", "val-9") | |||
.addMatchPattern("memo", "anything") | |||
.iterator().hasNext(); | |||
fail("RuntimeIOException should have been thrown"); | |||
} catch(RuntimeIOException ignored) { | |||
// success | |||
} | |||
assertThrows(RuntimeIOException.class, () -> cursor.newIterable() | |||
.addMatchPattern("value", "val-9") | |||
.addMatchPattern("memo", "anything") | |||
.iterator().hasNext()); | |||
List<Row> rows = new ArrayList<Row>(); | |||
for (Row row : cursor.newIterable() | |||
@@ -1332,6 +1327,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testPartialIndexFind() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
@@ -1416,6 +1412,7 @@ public class CursorTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testPartialIndexLookup() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
@@ -1482,18 +1479,16 @@ public class CursorTest extends TestCase { | |||
doFindFirstByEntry(c, null, "C", 4, "K3"); | |||
} | |||
try { | |||
if(colCount > 2) { | |||
assertThrows(IllegalArgumentException.class, () -> | |||
{ | |||
if (colCount > 2) { | |||
c.findFirstRowByEntry("C", 4, "K1", 14); | |||
} else if(colCount > 1) { | |||
c.findFirstRowByEntry("C", 4, "K1"); | |||
} else { | |||
c.findFirstRowByEntry("C", 4); | |||
} | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException expected) { | |||
// scucess | |||
} | |||
}); | |||
doFindByEntryRange(c, 11, 20, "B"); | |||
doFindByEntry(c, new int[]{}, "Z"); |
@@ -47,77 +47,62 @@ import com.healthmarketscience.jackcess.impl.RowIdImpl; | |||
import com.healthmarketscience.jackcess.impl.RowImpl; | |||
import com.healthmarketscience.jackcess.impl.TableImpl; | |||
import com.healthmarketscience.jackcess.util.RowFilterTest; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author Tim McCune | |||
*/ | |||
@SuppressWarnings("deprecation") | |||
public class DatabaseTest extends TestCase | |||
public class DatabaseTest | |||
{ | |||
public DatabaseTest(String name) throws Exception { | |||
super(name); | |||
} | |||
public void testInvalidTableDefs() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
try { | |||
newTable("test").toTable(db); | |||
fail("created table with no columns?"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
try { | |||
newTable("test") | |||
.addColumn(newColumn("A", DataType.TEXT)) | |||
.addColumn(newColumn("a", DataType.MEMO)) | |||
.toTable(db); | |||
fail("created table with duplicate column names?"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
try { | |||
newTable("test") | |||
.addColumn(newColumn("A", DataType.TEXT) | |||
.setLengthInUnits(352)) | |||
.toTable(db); | |||
fail("created table with invalid column length?"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
@Test | |||
public void testInvalidTableDefs() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
assertThrows(IllegalArgumentException.class, | |||
() -> newTable("test").toTable(db), | |||
"created table with no columns?"); | |||
assertThrows(IllegalArgumentException.class, | |||
() -> newTable("test") | |||
.addColumn(newColumn("A", DataType.TEXT)) | |||
.addColumn(newColumn("a", DataType.MEMO)) | |||
.toTable(db), | |||
"created table with duplicate column names?"); | |||
assertThrows(IllegalArgumentException.class, | |||
() -> newTable("test") | |||
.addColumn(newColumn("A", DataType.TEXT) | |||
.setLengthInUnits(352)) | |||
.toTable(db), | |||
"created table with invalid column length?"); | |||
assertThrows(IllegalArgumentException.class, | |||
() -> newTable("test") | |||
.addColumn(newColumn("A_" + createString(70), DataType.TEXT)) | |||
.toTable(db), | |||
"created table with too long column name?"); | |||
try { | |||
newTable("test") | |||
.addColumn(newColumn("A_" + createString(70), DataType.TEXT)) | |||
.toTable(db); | |||
fail("created table with too long column name?"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
newTable("test") | |||
.addColumn(newColumn("A", DataType.TEXT)) | |||
.toTable(db); | |||
try { | |||
newTable("Test") | |||
.addColumn(newColumn("A", DataType.TEXT)) | |||
.toTable(db); | |||
fail("create duplicate tables?"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
.addColumn(newColumn("A", DataType.TEXT)) | |||
.toTable(db); | |||
assertThrows(IllegalArgumentException.class, | |||
() -> newTable("Test") | |||
.addColumn(newColumn("A", DataType.TEXT)) | |||
.toTable(db), | |||
"create duplicate tables?"); | |||
} | |||
db.close(); | |||
} | |||
} | |||
@Test | |||
public void testReadDeletedRows() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.DEL, true)) { | |||
Table table = open(testDB).getTable("Table"); | |||
@@ -130,6 +115,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testGetColumns() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
@@ -157,6 +143,7 @@ public class DatabaseTest extends TestCase | |||
assertEquals(dataType, column.getType()); | |||
} | |||
@Test | |||
public void testGetNextRow() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
final Database db = open(testDB); | |||
@@ -181,6 +168,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testCreate() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
@@ -189,6 +177,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testDeleteCurrentRow() throws Exception { | |||
// make sure correct row is deleted | |||
@@ -259,6 +248,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testDeleteRow() throws Exception { | |||
// make sure correct row is deleted | |||
@@ -291,18 +281,18 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testMissingFile() throws Exception { | |||
File bogusFile = new File("fooby-dooby.mdb"); | |||
assertTrue(!bogusFile.exists()); | |||
try { | |||
newDatabase(bogusFile).setReadOnly(true). | |||
setAutoSync(getTestAutoSync()).open(); | |||
fail("FileNotFoundException should have been thrown"); | |||
} catch(FileNotFoundException e) { | |||
} | |||
assertThrows(FileNotFoundException.class, | |||
() -> newDatabase(bogusFile).setReadOnly(true).setAutoSync(getTestAutoSync()).open()); | |||
assertTrue(!bogusFile.exists()); | |||
} | |||
@Test | |||
public void testReadWithDeletedCols() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.DEL_COL, true)) { | |||
Table table = open(testDB).getTable("Table1"); | |||
@@ -336,138 +326,135 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
public void testCurrency() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
Table table = newTable("test") | |||
.addColumn(newColumn("A", DataType.MONEY)) | |||
.toTable(db); | |||
@Test | |||
public void testCurrency() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (Database db = create(fileFormat)) | |||
{ | |||
Table table = newTable("test") | |||
.addColumn(newColumn("A", DataType.MONEY)) | |||
.toTable(db); | |||
table.addRow(new BigDecimal("-2341234.03450")); | |||
table.addRow(37L); | |||
table.addRow("10000.45"); | |||
table.reset(); | |||
List<Object> foundValues = new ArrayList<Object>(); | |||
Map<String, Object> row = null; | |||
while ((row = table.getNextRow()) != null) | |||
{ | |||
foundValues.add(row.get("A")); | |||
} | |||
table.addRow(new BigDecimal("-2341234.03450")); | |||
table.addRow(37L); | |||
table.addRow("10000.45"); | |||
assertEquals(Arrays.asList( | |||
new BigDecimal("-2341234.0345"), | |||
new BigDecimal("37.0000"), | |||
new BigDecimal("10000.4500")), | |||
foundValues); | |||
table.reset(); | |||
assertThrows(IOException.class, | |||
() -> table.addRow(new BigDecimal("342523234145343543.3453"))); | |||
List<Object> foundValues = new ArrayList<Object>(); | |||
Map<String, Object> row = null; | |||
while((row = table.getNextRow()) != null) { | |||
foundValues.add(row.get("A")); | |||
} | |||
assertEquals(Arrays.asList( | |||
new BigDecimal("-2341234.0345"), | |||
new BigDecimal("37.0000"), | |||
new BigDecimal("10000.4500")), | |||
foundValues); | |||
try { | |||
table.addRow(new BigDecimal("342523234145343543.3453")); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// ignored | |||
} | |||
db.close(); | |||
} | |||
} | |||
@Test | |||
public void testGUID() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
Table table = newTable("test") | |||
.addColumn(newColumn("A", DataType.GUID)) | |||
.toTable(db); | |||
table.addRow("{32A59F01-AA34-3E29-453F-4523453CD2E6}"); | |||
table.addRow("{32a59f01-aa34-3e29-453f-4523453cd2e6}"); | |||
table.addRow("{11111111-1111-1111-1111-111111111111}"); | |||
table.addRow(" {FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF} "); | |||
table.addRow(UUID.fromString("32a59f01-1234-3e29-4aaf-4523453cd2e6")); | |||
table.reset(); | |||
List<Object> foundValues = new ArrayList<Object>(); | |||
Map<String, Object> row = null; | |||
while((row = table.getNextRow()) != null) { | |||
foundValues.add(row.get("A")); | |||
} | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
Table table = newTable("test") | |||
.addColumn(newColumn("A", DataType.GUID)) | |||
.toTable(db); | |||
table.addRow("{32A59F01-AA34-3E29-453F-4523453CD2E6}"); | |||
table.addRow("{32a59f01-aa34-3e29-453f-4523453cd2e6}"); | |||
table.addRow("{11111111-1111-1111-1111-111111111111}"); | |||
table.addRow(" {FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF} "); | |||
table.addRow(UUID.fromString("32a59f01-1234-3e29-4aaf-4523453cd2e6")); | |||
table.reset(); | |||
List<Object> foundValues = new ArrayList<Object>(); | |||
Map<String, Object> row = null; | |||
while ((row = table.getNextRow()) != null) | |||
{ | |||
foundValues.add(row.get("A")); | |||
} | |||
assertEquals(Arrays.asList( | |||
"{32A59F01-AA34-3E29-453F-4523453CD2E6}", | |||
"{32A59F01-AA34-3E29-453F-4523453CD2E6}", | |||
"{11111111-1111-1111-1111-111111111111}", | |||
"{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}", | |||
"{32A59F01-1234-3E29-4AAF-4523453CD2E6}"), | |||
foundValues); | |||
assertEquals(Arrays.asList( | |||
"{32A59F01-AA34-3E29-453F-4523453CD2E6}", | |||
"{32A59F01-AA34-3E29-453F-4523453CD2E6}", | |||
"{11111111-1111-1111-1111-111111111111}", | |||
"{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}", | |||
"{32A59F01-1234-3E29-4AAF-4523453CD2E6}"), | |||
foundValues); | |||
try { | |||
table.addRow("3245234"); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// ignored | |||
assertThrows(IOException.class, () -> table.addRow("3245234")); | |||
} | |||
db.close(); | |||
} | |||
} | |||
@Test | |||
public void testNumeric() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
ColumnBuilder col = newColumn("A", DataType.NUMERIC) | |||
.setScale(4).setPrecision(8).toColumn(); | |||
assertTrue(col.getType().isVariableLength()); | |||
Table table = newTable("test") | |||
.addColumn(col) | |||
.addColumn(newColumn("B", DataType.NUMERIC) | |||
.setScale(8).setPrecision(28)) | |||
.toTable(db); | |||
table.addRow(new BigDecimal("-1234.03450"), | |||
new BigDecimal("23923434453436.36234219")); | |||
table.addRow(37L, 37L); | |||
table.addRow("1000.45", "-3452345321000"); | |||
table.reset(); | |||
List<Object> foundSmallValues = new ArrayList<Object>(); | |||
List<Object> foundBigValues = new ArrayList<Object>(); | |||
Map<String, Object> row = null; | |||
while((row = table.getNextRow()) != null) { | |||
foundSmallValues.add(row.get("A")); | |||
foundBigValues.add(row.get("B")); | |||
} | |||
assertEquals(Arrays.asList( | |||
new BigDecimal("-1234.0345"), | |||
new BigDecimal("37.0000"), | |||
new BigDecimal("1000.4500")), | |||
foundSmallValues); | |||
assertEquals(Arrays.asList( | |||
new BigDecimal("23923434453436.36234219"), | |||
new BigDecimal("37.00000000"), | |||
new BigDecimal("-3452345321000.00000000")), | |||
foundBigValues); | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
ColumnBuilder col = newColumn("A", DataType.NUMERIC) | |||
.setScale(4).setPrecision(8).toColumn(); | |||
assertTrue(col.getType().isVariableLength()); | |||
Table table = newTable("test") | |||
.addColumn(col) | |||
.addColumn(newColumn("B", DataType.NUMERIC) | |||
.setScale(8).setPrecision(28)) | |||
.toTable(db); | |||
table.addRow(new BigDecimal("-1234.03450"), | |||
new BigDecimal("23923434453436.36234219")); | |||
table.addRow(37L, 37L); | |||
table.addRow("1000.45", "-3452345321000"); | |||
table.reset(); | |||
List<Object> foundSmallValues = new ArrayList<>(); | |||
List<Object> foundBigValues = new ArrayList<>(); | |||
Map<String, Object> row = null; | |||
while ((row = table.getNextRow()) != null) | |||
{ | |||
foundSmallValues.add(row.get("A")); | |||
foundBigValues.add(row.get("B")); | |||
} | |||
try { | |||
table.addRow(new BigDecimal("3245234.234"), | |||
new BigDecimal("3245234.234")); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// ignored | |||
assertEquals(Arrays.asList( | |||
new BigDecimal("-1234.0345"), | |||
new BigDecimal("37.0000"), | |||
new BigDecimal("1000.4500")), | |||
foundSmallValues); | |||
assertEquals(Arrays.asList( | |||
new BigDecimal("23923434453436.36234219"), | |||
new BigDecimal("37.00000000"), | |||
new BigDecimal("-3452345321000.00000000")), | |||
foundBigValues); | |||
assertThrows(IOException.class, | |||
() -> table.addRow(new BigDecimal("3245234.234"), | |||
new BigDecimal("3245234.234"))); | |||
} | |||
db.close(); | |||
} | |||
} | |||
@Test | |||
public void testFixedNumeric() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.FIXED_NUMERIC)) { | |||
@@ -515,6 +502,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testMultiPageTableDef() throws Exception | |||
{ | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
@@ -523,6 +511,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testOverflow() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.OVERFLOW, true)) { | |||
@@ -555,6 +544,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
@Test | |||
public void testUsageMapPromotion() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.PROMOTION)) { | |||
Database db = openMem(testDB); | |||
@@ -587,6 +577,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
@Test | |||
public void testLargeTableDef() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
@@ -622,6 +613,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testWriteAndReadDate() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = createMem(fileFormat); | |||
@@ -684,6 +676,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testAncientDates() throws Exception | |||
{ | |||
TimeZone tz = TimeZone.getTimeZone("America/New_York"); | |||
@@ -736,6 +729,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
@Test | |||
public void testSystemTable() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -748,13 +742,13 @@ public class DatabaseTest extends TestCase | |||
"MSysRelationships")); | |||
if (fileFormat == FileFormat.GENERIC_JET4) { | |||
assertNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects")); | |||
assertNull(db.getSystemTable("MSysAccessObjects"), "file format: " + fileFormat); | |||
} else if (fileFormat.ordinal() < FileFormat.V2003.ordinal()) { | |||
assertNotNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects")); | |||
assertNotNull(db.getSystemTable("MSysAccessObjects"), "file format: " + fileFormat); | |||
sysTables.add("MSysAccessObjects"); | |||
} else { | |||
// v2003+ template files have no "MSysAccessObjects" table | |||
assertNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects")); | |||
assertNull(db.getSystemTable("MSysAccessObjects"), "file format: " + fileFormat); | |||
sysTables.addAll( | |||
Arrays.asList("MSysNavPaneGroupCategories", | |||
"MSysNavPaneGroups", "MSysNavPaneGroupToObjects", | |||
@@ -799,6 +793,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testFixedText() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.FIXED_TEXT)) { | |||
@@ -825,6 +820,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testDbSortOrder() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
@@ -836,6 +832,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testUnsupportedColumns() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.UNSUPPORTED)) { | |||
@@ -873,6 +870,7 @@ public class DatabaseTest extends TestCase | |||
return tableList; | |||
} | |||
@Test | |||
public void testTimeZone() throws Exception | |||
{ | |||
TimeZone tz = TimeZone.getTimeZone("America/New_York"); | |||
@@ -917,6 +915,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testToString() | |||
{ | |||
RowImpl row = new RowImpl(new RowIdImpl(1, 1)); | |||
@@ -925,6 +924,7 @@ public class DatabaseTest extends TestCase | |||
assertEquals("Row[1:1][{id=37,data=<null>}]", row.toString()); | |||
} | |||
@Test | |||
public void testIterateTableNames() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
final Database db = open(testDB); | |||
@@ -973,6 +973,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testTableDates() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
Table table = open(testDB).getTable("Table1"); | |||
@@ -990,6 +991,7 @@ public class DatabaseTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testBrokenIndex() throws Exception { | |||
TestDB testDb = TestDB.getSupportedForBasename(Basename.TEST).get(0); | |||
try (Database db = new DatabaseBuilder(testDb.getFile()) |
@@ -33,29 +33,29 @@ import com.healthmarketscience.jackcess.impl.IndexImpl; | |||
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.*; | |||
import static com.healthmarketscience.jackcess.DatabaseBuilder.*; | |||
import org.junit.jupiter.api.AfterEach; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.BeforeEach; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class IndexTest extends TestCase { | |||
public IndexTest(String name) { | |||
super(name); | |||
} | |||
@Override | |||
public class IndexTest | |||
{ | |||
@BeforeEach | |||
protected void setUp() { | |||
TestUtil.setTestAutoSync(false); | |||
} | |||
@Override | |||
@AfterEach | |||
protected void tearDown() { | |||
TestUtil.clearTestAutoSync(); | |||
} | |||
@Test | |||
public void testByteOrder() throws Exception { | |||
byte b1 = (byte)0x00; | |||
byte b2 = (byte)0x01; | |||
@@ -69,6 +69,7 @@ public class IndexTest extends TestCase { | |||
assertTrue(ByteUtil.asUnsignedByte(b4) < ByteUtil.asUnsignedByte(b5)); | |||
} | |||
@Test | |||
public void testByteCodeComparator() { | |||
byte[] b0 = null; | |||
byte[] b1 = new byte[]{(byte)0x00}; | |||
@@ -89,6 +90,7 @@ public class IndexTest extends TestCase { | |||
} | |||
@Test | |||
public void testPrimaryKey() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
Table table = open(testDB).getTable("Table1"); | |||
@@ -110,6 +112,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testLogicalIndexes() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { | |||
@@ -171,6 +174,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testComplexIndex() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMP_INDEX)) { | |||
@@ -192,6 +196,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testEntryDeletion() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST) { | |||
Table table = openCopy(testDB).getTable("Table1"); | |||
@@ -230,6 +235,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testIgnoreNulls() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX_PROPERTIES)) { | |||
@@ -282,6 +288,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testUnique() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX_PROPERTIES)) { | |||
@@ -348,6 +355,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testUniqueEntryCount() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST) { | |||
Database db = openCopy(testDB); | |||
@@ -410,6 +418,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testReplId() throws Exception | |||
{ | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST) { | |||
@@ -426,6 +435,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testIndexCreation() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -465,6 +475,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testIndexCreationSharedData() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -515,6 +526,7 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testGetForeignKeyIndex() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { | |||
@@ -548,176 +560,180 @@ public class IndexTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testConstraintViolation() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
Table t = newTable("TestTable") | |||
.addColumn(newColumn("id", DataType.LONG)) | |||
.addColumn(newColumn("data", DataType.TEXT)) | |||
.setPrimaryKey("id") | |||
.addIndex(newIndex("data_ind") | |||
.addColumns("data").setUnique()) | |||
.toTable(db); | |||
for(int i = 0; i < 5; ++i) { | |||
t.addRow(i, "row" + i); | |||
} | |||
try { | |||
t.addRow(3, "badrow"); | |||
fail("ConstraintViolationException should have been thrown"); | |||
} catch(ConstraintViolationException ce) { | |||
// success | |||
} | |||
assertEquals(5, t.getRowCount()); | |||
List<Row> expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"id", 0, "data", "row0"), | |||
createExpectedRow( | |||
"id", 1, "data", "row1"), | |||
createExpectedRow( | |||
"id", 2, "data", "row2"), | |||
createExpectedRow( | |||
"id", 3, "data", "row3"), | |||
createExpectedRow( | |||
"id", 4, "data", "row4")); | |||
assertTable(expectedRows, t); | |||
IndexCursor pkCursor = CursorBuilder.createPrimaryKeyCursor(t); | |||
assertCursor(expectedRows, pkCursor); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
List<Object[]> batch = new ArrayList<Object[]>(); | |||
batch.add(new Object[]{5, "row5"}); | |||
batch.add(new Object[]{6, "row6"}); | |||
batch.add(new Object[]{7, "row2"}); | |||
batch.add(new Object[]{8, "row8"}); | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
Table t = newTable("TestTable") | |||
.addColumn(newColumn("id", DataType.LONG)) | |||
.addColumn(newColumn("data", DataType.TEXT)) | |||
.setPrimaryKey("id") | |||
.addIndex(newIndex("data_ind") | |||
.addColumns("data").setUnique()) | |||
.toTable(db); | |||
for (int i = 0; i < 5; ++i) | |||
{ | |||
t.addRow(i, "row" + i); | |||
} | |||
try { | |||
t.addRows(batch); | |||
fail("BatchUpdateException should have been thrown"); | |||
} catch(BatchUpdateException be) { | |||
// success | |||
assertThrows(ConstraintViolationException.class, () -> t.addRow(3, "badrow")); | |||
assertEquals(5, t.getRowCount()); | |||
List<Row> expectedRows | |||
= createExpectedTable( | |||
createExpectedRow( | |||
"id", 0, "data", "row0"), | |||
createExpectedRow( | |||
"id", 1, "data", "row1"), | |||
createExpectedRow( | |||
"id", 2, "data", "row2"), | |||
createExpectedRow( | |||
"id", 3, "data", "row3"), | |||
createExpectedRow( | |||
"id", 4, "data", "row4")); | |||
assertTable(expectedRows, t); | |||
IndexCursor pkCursor = CursorBuilder.createPrimaryKeyCursor(t); | |||
assertCursor(expectedRows, pkCursor); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
List<Object[]> batch = new ArrayList<Object[]>(); | |||
batch.add(new Object[] | |||
{ | |||
5, "row5" | |||
}); | |||
batch.add(new Object[] | |||
{ | |||
6, "row6" | |||
}); | |||
batch.add(new Object[] | |||
{ | |||
7, "row2" | |||
}); | |||
batch.add(new Object[] | |||
{ | |||
8, "row8" | |||
}); | |||
final BatchUpdateException be = assertThrows(BatchUpdateException.class, | |||
() -> t.addRows(batch)); | |||
assertTrue(be.getCause() instanceof ConstraintViolationException); | |||
assertEquals(2, be.getUpdateCount()); | |||
} | |||
expectedRows = new ArrayList<Row>(expectedRows); | |||
expectedRows.add(createExpectedRow("id", 5, "data", "row5")); | |||
expectedRows.add(createExpectedRow("id", 6, "data", "row6")); | |||
assertTable(expectedRows, t); | |||
expectedRows = new ArrayList<Row>(expectedRows); | |||
expectedRows.add(createExpectedRow("id", 5, "data", "row5")); | |||
expectedRows.add(createExpectedRow("id", 6, "data", "row6")); | |||
assertCursor(expectedRows, pkCursor); | |||
assertTable(expectedRows, t); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
assertCursor(expectedRows, pkCursor); | |||
pkCursor.findFirstRowByEntry(4); | |||
Row row4 = pkCursor.getCurrentRow(); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
row4.put("id", 3); | |||
pkCursor.findFirstRowByEntry(4); | |||
Row row4 = pkCursor.getCurrentRow(); | |||
try { | |||
t.updateRow(row4); | |||
fail("ConstraintViolationException should have been thrown"); | |||
} catch(ConstraintViolationException ce) { | |||
// success | |||
} | |||
row4.put("id", 3); | |||
assertTable(expectedRows, t); | |||
assertThrows(ConstraintViolationException.class, () -> t.updateRow(row4)); | |||
assertCursor(expectedRows, pkCursor); | |||
assertTable(expectedRows, t); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
assertCursor(expectedRows, pkCursor); | |||
db.close(); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
} | |||
} | |||
} | |||
@Test | |||
public void testAutoNumberRecover() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
Table t = newTable("TestTable") | |||
.addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) | |||
.addColumn(newColumn("data", DataType.TEXT)) | |||
.setPrimaryKey("id") | |||
.addIndex(newIndex("data_ind") | |||
.addColumns("data").setUnique()) | |||
.toTable(db); | |||
for(int i = 1; i < 3; ++i) { | |||
t.addRow(null, "row" + i); | |||
} | |||
try { | |||
t.addRow(null, "row1"); | |||
fail("ConstraintViolationException should have been thrown"); | |||
} catch(ConstraintViolationException ce) { | |||
// success | |||
} | |||
t.addRow(null, "row3"); | |||
assertEquals(3, t.getRowCount()); | |||
List<Row> expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, "data", "row1"), | |||
createExpectedRow( | |||
"id", 2, "data", "row2"), | |||
createExpectedRow( | |||
"id", 3, "data", "row3")); | |||
assertTable(expectedRows, t); | |||
IndexCursor pkCursor = CursorBuilder.createPrimaryKeyCursor(t); | |||
assertCursor(expectedRows, pkCursor); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
List<Object[]> batch = new ArrayList<Object[]>(); | |||
batch.add(new Object[]{null, "row4"}); | |||
batch.add(new Object[]{null, "row5"}); | |||
batch.add(new Object[]{null, "row3"}); | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
Table t = newTable("TestTable") | |||
.addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) | |||
.addColumn(newColumn("data", DataType.TEXT)) | |||
.setPrimaryKey("id") | |||
.addIndex(newIndex("data_ind") | |||
.addColumns("data").setUnique()) | |||
.toTable(db); | |||
for (int i = 1; i < 3; ++i) | |||
{ | |||
t.addRow(null, "row" + i); | |||
} | |||
try { | |||
t.addRows(batch); | |||
fail("BatchUpdateException should have been thrown"); | |||
} catch(BatchUpdateException be) { | |||
// success | |||
assertThrows(ConstraintViolationException.class, () -> t.addRow(null, "row1")); | |||
t.addRow(null, "row3"); | |||
assertEquals(3, t.getRowCount()); | |||
List<Row> expectedRows | |||
= createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, "data", "row1"), | |||
createExpectedRow( | |||
"id", 2, "data", "row2"), | |||
createExpectedRow( | |||
"id", 3, "data", "row3")); | |||
assertTable(expectedRows, t); | |||
IndexCursor pkCursor = CursorBuilder.createPrimaryKeyCursor(t); | |||
assertCursor(expectedRows, pkCursor); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
List<Object[]> batch = new ArrayList<Object[]>(); | |||
batch.add(new Object[] | |||
{ | |||
null, "row4" | |||
}); | |||
batch.add(new Object[] | |||
{ | |||
null, "row5" | |||
}); | |||
batch.add(new Object[] | |||
{ | |||
null, "row3" | |||
}); | |||
BatchUpdateException be = assertThrows(BatchUpdateException.class, | |||
() -> t.addRows(batch)); | |||
assertTrue(be.getCause() instanceof ConstraintViolationException); | |||
assertEquals(2, be.getUpdateCount()); | |||
} | |||
expectedRows = new ArrayList<Row>(expectedRows); | |||
expectedRows.add(createExpectedRow("id", 4, "data", "row4")); | |||
expectedRows.add(createExpectedRow("id", 5, "data", "row5")); | |||
expectedRows = new ArrayList<Row>(expectedRows); | |||
expectedRows.add(createExpectedRow("id", 4, "data", "row4")); | |||
expectedRows.add(createExpectedRow("id", 5, "data", "row5")); | |||
assertTable(expectedRows, t); | |||
assertTable(expectedRows, t); | |||
assertCursor(expectedRows, pkCursor); | |||
assertCursor(expectedRows, pkCursor); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
assertCursor(expectedRows, | |||
CursorBuilder.createCursor(t.getIndex("data_ind"))); | |||
db.close(); | |||
} | |||
} | |||
} | |||
@Test | |||
public void testBinaryIndex() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.BINARY_INDEX)) { |
@@ -18,180 +18,166 @@ package com.healthmarketscience.jackcess; | |||
import java.io.File; | |||
import java.io.FileNotFoundException; | |||
import java.io.IOException; | |||
import java.util.List; | |||
import java.util.Map; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import com.healthmarketscience.jackcess.impl.DatabaseImpl; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import com.healthmarketscience.jackcess.util.LinkResolver; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class LinkedTableTest extends TestCase | |||
public class LinkedTableTest | |||
{ | |||
public void testLinkedTables() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.LINKED)) { | |||
Database db = openCopy(testDB); | |||
try { | |||
db.getTable("Table2"); | |||
fail("FileNotFoundException should have been thrown"); | |||
} catch(FileNotFoundException e) { | |||
// success | |||
} | |||
TableMetaData tmd = db.getTableMetaData("Table2"); | |||
assertEquals("Table2", tmd.getName()); | |||
assertTrue(tmd.isLinked()); | |||
assertFalse(tmd.isSystem()); | |||
assertEquals("Table1", tmd.getLinkedTableName()); | |||
assertNull(tmd.getConnectionName()); | |||
assertEquals(TableMetaData.Type.LINKED, tmd.getType()); | |||
assertEquals("Z:\\jackcess_test\\linkeeTest.accdb", tmd.getLinkedDbName()); | |||
assertNull(tmd.getTableDefinition(db)); | |||
tmd = db.getTableMetaData("FooTable"); | |||
assertNull(tmd); | |||
assertTrue(db.getLinkedDatabases().isEmpty()); | |||
final String linkeeDbName = "Z:\\jackcess_test\\linkeeTest.accdb"; | |||
final File linkeeFile = new File("src/test/data/linkeeTest.accdb"); | |||
db.setLinkResolver(new LinkResolver() { | |||
@Override | |||
public Database resolveLinkedDatabase(Database linkerdb, String dbName) | |||
throws IOException { | |||
@Test | |||
public void testLinkedTables() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.LINKED)) | |||
{ | |||
try (final Database db = openCopy(testDB)) | |||
{ | |||
assertThrows(FileNotFoundException.class, () -> db.getTable("Table2")); | |||
TableMetaData tmd = db.getTableMetaData("Table2"); | |||
assertEquals("Table2", tmd.getName()); | |||
assertTrue(tmd.isLinked()); | |||
assertFalse(tmd.isSystem()); | |||
assertEquals("Table1", tmd.getLinkedTableName()); | |||
assertNull(tmd.getConnectionName()); | |||
assertEquals(TableMetaData.Type.LINKED, tmd.getType()); | |||
assertEquals("Z:\\jackcess_test\\linkeeTest.accdb", tmd.getLinkedDbName()); | |||
assertNull(tmd.getTableDefinition(db)); | |||
tmd = db.getTableMetaData("FooTable"); | |||
assertNull(tmd); | |||
assertTrue(db.getLinkedDatabases().isEmpty()); | |||
final String linkeeDbName = "Z:\\jackcess_test\\linkeeTest.accdb"; | |||
final File linkeeFile = new File("src/test/data/linkeeTest.accdb"); | |||
db.setLinkResolver((Database linkerdb, String dbName) -> | |||
{ | |||
assertEquals(linkeeDbName, dbName); | |||
return DatabaseBuilder.open(linkeeFile); | |||
} | |||
}); | |||
Table t2 = db.getTable("Table2"); | |||
assertEquals(1, db.getLinkedDatabases().size()); | |||
Database linkeeDb = db.getLinkedDatabases().get(linkeeDbName); | |||
assertNotNull(linkeeDb); | |||
assertEquals(linkeeFile, linkeeDb.getFile()); | |||
assertEquals("linkeeTest.accdb", ((DatabaseImpl)linkeeDb).getName()); | |||
List<? extends Map<String, Object>> expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"ID", 1, | |||
"Field1", "bar")); | |||
assertTable(expectedRows, t2); | |||
db.createLinkedTable("FooTable", linkeeDbName, "Table2"); | |||
tmd = db.getTableMetaData("FooTable"); | |||
assertEquals("FooTable", tmd.getName()); | |||
assertTrue(tmd.isLinked()); | |||
assertFalse(tmd.isSystem()); | |||
assertEquals("Table2", tmd.getLinkedTableName()); | |||
assertEquals("Z:\\jackcess_test\\linkeeTest.accdb", tmd.getLinkedDbName()); | |||
Table t3 = db.getTable("FooTable"); | |||
assertEquals(1, db.getLinkedDatabases().size()); | |||
expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"ID", 1, | |||
"Field1", "buzz")); | |||
assertTable(expectedRows, t3); | |||
tmd = db.getTableMetaData("Table1"); | |||
assertEquals("Table1", tmd.getName()); | |||
assertFalse(tmd.isLinked()); | |||
assertFalse(tmd.isSystem()); | |||
assertNull(tmd.getLinkedTableName()); | |||
assertNull(tmd.getLinkedDbName()); | |||
Table t1 = tmd.open(db); | |||
assertFalse(db.isLinkedTable(null)); | |||
assertTrue(db.isLinkedTable(t2)); | |||
assertTrue(db.isLinkedTable(t3)); | |||
assertFalse(db.isLinkedTable(t1)); | |||
List<Table> tables = DatabaseTest.getTables(db.newIterable()); | |||
assertEquals(3, tables.size()); | |||
assertTrue(tables.contains(t1)); | |||
assertTrue(tables.contains(t2)); | |||
assertTrue(tables.contains(t3)); | |||
assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog())); | |||
tables = DatabaseTest.getTables(db.newIterable().setIncludeNormalTables(false)); | |||
assertEquals(2, tables.size()); | |||
assertFalse(tables.contains(t1)); | |||
assertTrue(tables.contains(t2)); | |||
assertTrue(tables.contains(t3)); | |||
assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog())); | |||
tables = DatabaseTest.getTables(db.newIterable().withLocalUserTablesOnly()); | |||
assertEquals(1, tables.size()); | |||
assertTrue(tables.contains(t1)); | |||
assertFalse(tables.contains(t2)); | |||
assertFalse(tables.contains(t3)); | |||
assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog())); | |||
tables = DatabaseTest.getTables(db.newIterable().withSystemTablesOnly()); | |||
assertTrue(tables.size() > 5); | |||
assertFalse(tables.contains(t1)); | |||
assertFalse(tables.contains(t2)); | |||
assertFalse(tables.contains(t3)); | |||
assertTrue(tables.contains(((DatabaseImpl)db).getSystemCatalog())); | |||
db.close(); | |||
}); | |||
Table t2 = db.getTable("Table2"); | |||
assertEquals(1, db.getLinkedDatabases().size()); | |||
Database linkeeDb = db.getLinkedDatabases().get(linkeeDbName); | |||
assertNotNull(linkeeDb); | |||
assertEquals(linkeeFile, linkeeDb.getFile()); | |||
assertEquals("linkeeTest.accdb", ((DatabaseImpl) linkeeDb).getName()); | |||
List<? extends Map<String, Object>> expectedRows | |||
= createExpectedTable( | |||
createExpectedRow( | |||
"ID", 1, | |||
"Field1", "bar")); | |||
assertTable(expectedRows, t2); | |||
db.createLinkedTable("FooTable", linkeeDbName, "Table2"); | |||
tmd = db.getTableMetaData("FooTable"); | |||
assertEquals("FooTable", tmd.getName()); | |||
assertTrue(tmd.isLinked()); | |||
assertFalse(tmd.isSystem()); | |||
assertEquals("Table2", tmd.getLinkedTableName()); | |||
assertEquals("Z:\\jackcess_test\\linkeeTest.accdb", tmd.getLinkedDbName()); | |||
Table t3 = db.getTable("FooTable"); | |||
assertEquals(1, db.getLinkedDatabases().size()); | |||
expectedRows | |||
= createExpectedTable( | |||
createExpectedRow( | |||
"ID", 1, | |||
"Field1", "buzz")); | |||
assertTable(expectedRows, t3); | |||
tmd = db.getTableMetaData("Table1"); | |||
assertEquals("Table1", tmd.getName()); | |||
assertFalse(tmd.isLinked()); | |||
assertFalse(tmd.isSystem()); | |||
assertNull(tmd.getLinkedTableName()); | |||
assertNull(tmd.getLinkedDbName()); | |||
Table t1 = tmd.open(db); | |||
assertFalse(db.isLinkedTable(null)); | |||
assertTrue(db.isLinkedTable(t2)); | |||
assertTrue(db.isLinkedTable(t3)); | |||
assertFalse(db.isLinkedTable(t1)); | |||
List<Table> tables = DatabaseTest.getTables(db.newIterable()); | |||
assertEquals(3, tables.size()); | |||
assertTrue(tables.contains(t1)); | |||
assertTrue(tables.contains(t2)); | |||
assertTrue(tables.contains(t3)); | |||
assertFalse(tables.contains(((DatabaseImpl) db).getSystemCatalog())); | |||
tables = DatabaseTest.getTables(db.newIterable().setIncludeNormalTables(false)); | |||
assertEquals(2, tables.size()); | |||
assertFalse(tables.contains(t1)); | |||
assertTrue(tables.contains(t2)); | |||
assertTrue(tables.contains(t3)); | |||
assertFalse(tables.contains(((DatabaseImpl) db).getSystemCatalog())); | |||
tables = DatabaseTest.getTables(db.newIterable().withLocalUserTablesOnly()); | |||
assertEquals(1, tables.size()); | |||
assertTrue(tables.contains(t1)); | |||
assertFalse(tables.contains(t2)); | |||
assertFalse(tables.contains(t3)); | |||
assertFalse(tables.contains(((DatabaseImpl) db).getSystemCatalog())); | |||
tables = DatabaseTest.getTables(db.newIterable().withSystemTablesOnly()); | |||
assertTrue(tables.size() > 5); | |||
assertFalse(tables.contains(t1)); | |||
assertFalse(tables.contains(t2)); | |||
assertFalse(tables.contains(t3)); | |||
assertTrue(tables.contains(((DatabaseImpl) db).getSystemCatalog())); | |||
} | |||
} | |||
} | |||
public void testOdbcLinkedTables() throws Exception { | |||
for (final TestDB testDB : | |||
TestDB.getSupportedForBasename(Basename.LINKED_ODBC)) { | |||
Database db = openCopy(testDB); | |||
@Test | |||
public void testOdbcLinkedTables() throws Exception | |||
{ | |||
for (final TestDB testDB | |||
: TestDB.getSupportedForBasename(Basename.LINKED_ODBC)) | |||
{ | |||
try (final Database db = openCopy(testDB)) | |||
{ | |||
TableMetaData tmd = db.getTableMetaData("Ordrar"); | |||
assertEquals(TableMetaData.Type.LINKED_ODBC, tmd.getType()); | |||
assertEquals("dbo.Ordrar", tmd.getLinkedTableName()); | |||
assertNull(tmd.getLinkedDbName()); | |||
assertEquals("DSN=Magnapinna;Description=Safexit;UID=safexit;PWD=DummyPassword;APP=Microsoft Office;DATABASE=safexit", tmd.getConnectionName()); | |||
assertFalse(tmd.toString().contains("DummyPassword")); | |||
TableMetaData tmd = db.getTableMetaData("Ordrar"); | |||
assertEquals(TableMetaData.Type.LINKED_ODBC, tmd.getType()); | |||
assertEquals("dbo.Ordrar", tmd.getLinkedTableName()); | |||
assertNull(tmd.getLinkedDbName()); | |||
assertEquals("DSN=Magnapinna;Description=Safexit;UID=safexit;PWD=DummyPassword;APP=Microsoft Office;DATABASE=safexit", tmd.getConnectionName()); | |||
assertFalse(tmd.toString().contains("DummyPassword")); | |||
TableDefinition t = tmd.getTableDefinition(db); | |||
TableDefinition t = tmd.getTableDefinition(db); | |||
List<? extends Column> cols = t.getColumns(); | |||
assertEquals(20, cols.size()); | |||
List<? extends Column> cols = t.getColumns(); | |||
assertEquals(20, cols.size()); | |||
List<? extends Index> idxs = t.getIndexes(); | |||
assertEquals(5, idxs.size()); | |||
List<? extends Index> idxs = t.getIndexes(); | |||
assertEquals(5, idxs.size()); | |||
Table tbl = db.getTable("Ordrar"); | |||
Table tbl = db.getTable("Ordrar"); | |||
assertThrows(UnsupportedOperationException.class, () -> tbl.iterator()); | |||
try { | |||
tbl.iterator(); | |||
fail("UnsupportedOperationException should have been thrown"); | |||
} catch(UnsupportedOperationException expected) { | |||
// expected | |||
} | |||
assertThrows(UnsupportedOperationException.class, () -> tbl.addRow(1L, "bar")); | |||
try { | |||
tbl.addRow(1L,"bar"); | |||
fail("UnsupportedOperationException should have been thrown"); | |||
} catch(UnsupportedOperationException expected) { | |||
// expected | |||
} | |||
db.close(); | |||
} | |||
} | |||
@@ -33,22 +33,20 @@ import java.util.TimeZone; | |||
import com.healthmarketscience.jackcess.impl.ColumnImpl; | |||
import com.healthmarketscience.jackcess.impl.DatabaseImpl; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static com.healthmarketscience.jackcess.Database.*; | |||
import static com.healthmarketscience.jackcess.DatabaseBuilder.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class LocalDateTimeTest extends TestCase | |||
public class LocalDateTimeTest | |||
{ | |||
public LocalDateTimeTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testWriteAndReadLocalDate() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = createMem(fileFormat); | |||
@@ -113,6 +111,7 @@ public class LocalDateTimeTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testAncientLocalDates() throws Exception | |||
{ | |||
ZoneId zoneId = ZoneId.of("America/New_York"); | |||
@@ -164,6 +163,7 @@ public class LocalDateTimeTest extends TestCase | |||
} | |||
@Test | |||
public void testZoneId() throws Exception | |||
{ | |||
ZoneId zoneId = ZoneId.of("America/New_York"); | |||
@@ -212,6 +212,7 @@ public class LocalDateTimeTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testWriteAndReadTemporals() throws Exception { | |||
ZoneId zoneId = ZoneId.of("America/New_York"); | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { |
@@ -25,26 +25,22 @@ import java.util.Map; | |||
import java.util.UUID; | |||
import static com.healthmarketscience.jackcess.Database.*; | |||
import com.healthmarketscience.jackcess.InvalidValueException; | |||
import com.healthmarketscience.jackcess.impl.DatabaseImpl; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
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.*; | |||
import static com.healthmarketscience.jackcess.DatabaseBuilder.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class PropertiesTest extends TestCase | |||
public class PropertiesTest | |||
{ | |||
public PropertiesTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testPropertyMaps() throws Exception | |||
{ | |||
PropertyMaps maps = new PropertyMaps(10, null, null, null); | |||
@@ -104,6 +100,7 @@ public class PropertiesTest extends TestCase | |||
colMap.get("buzz")), props); | |||
} | |||
@Test | |||
public void testInferTypes() throws Exception | |||
{ | |||
PropertyMaps maps = new PropertyMaps(10, null, null, null); | |||
@@ -122,6 +119,7 @@ public class PropertiesTest extends TestCase | |||
defMap.put("intprop", 37).getType()); | |||
} | |||
@Test | |||
public void testReadProperties() throws Exception | |||
{ | |||
byte[] nameMapBytes = null; | |||
@@ -190,6 +188,7 @@ public class PropertiesTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testParseProperties() throws Exception | |||
{ | |||
for(FileFormat ff : SUPPORTED_FILEFORMATS_FOR_READ) { | |||
@@ -230,6 +229,7 @@ public class PropertiesTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testWriteProperties() throws Exception | |||
{ | |||
for(TestDB testDb : SUPPORTED_DBS_TEST) { | |||
@@ -263,6 +263,7 @@ public class PropertiesTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testModifyProperties() throws Exception | |||
{ | |||
for(TestDB testDb : SUPPORTED_DBS_TEST) { | |||
@@ -351,6 +352,7 @@ public class PropertiesTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testCreateDbProperties() throws Exception | |||
{ | |||
for(FileFormat ff : SUPPORTED_FILEFORMATS) { | |||
@@ -407,116 +409,85 @@ public class PropertiesTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testEnforceProperties() throws Exception | |||
{ | |||
for(final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
final Table testReq = newTable("testReq") | |||
.addColumn(newColumn("id", DataType.LONG) | |||
.setAutoNumber(true) | |||
.putProperty(PropertyMap.REQUIRED_PROP, true)) | |||
.addColumn(newColumn("value", DataType.TEXT) | |||
.putProperty(PropertyMap.REQUIRED_PROP, true)) | |||
.toTable(db); | |||
Table t = newTable("testReq") | |||
.addColumn(newColumn("id", DataType.LONG) | |||
.setAutoNumber(true) | |||
.putProperty(PropertyMap.REQUIRED_PROP, true)) | |||
.addColumn(newColumn("value", DataType.TEXT) | |||
.putProperty(PropertyMap.REQUIRED_PROP, true)) | |||
.toTable(db); | |||
testReq.addRow(Column.AUTO_NUMBER, "v1"); | |||
t.addRow(Column.AUTO_NUMBER, "v1"); | |||
assertThrows(InvalidValueException.class, () -> testReq.addRow(Column.AUTO_NUMBER, null)); | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, null); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException expected) { | |||
// success | |||
} | |||
testReq.addRow(Column.AUTO_NUMBER, ""); | |||
t.addRow(Column.AUTO_NUMBER, ""); | |||
List<? extends Map<String, Object>> expectedRows | |||
= createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, | |||
"value", "v1"), | |||
createExpectedRow( | |||
"id", 2, | |||
"value", "")); | |||
assertTable(expectedRows, testReq); | |||
List<? extends Map<String, Object>> expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, | |||
"value", "v1"), | |||
createExpectedRow( | |||
"id", 2, | |||
"value", "")); | |||
assertTable(expectedRows, t); | |||
final Table testNz = newTable("testNz") | |||
.addColumn(newColumn("id", DataType.LONG) | |||
.setAutoNumber(true) | |||
.putProperty(PropertyMap.REQUIRED_PROP, true)) | |||
.addColumn(newColumn("value", DataType.TEXT) | |||
.putProperty(PropertyMap.ALLOW_ZERO_LEN_PROP, false)) | |||
.toTable(db); | |||
testNz.addRow(Column.AUTO_NUMBER, "v1"); | |||
t = newTable("testNz") | |||
.addColumn(newColumn("id", DataType.LONG) | |||
.setAutoNumber(true) | |||
.putProperty(PropertyMap.REQUIRED_PROP, true)) | |||
.addColumn(newColumn("value", DataType.TEXT) | |||
.putProperty(PropertyMap.ALLOW_ZERO_LEN_PROP, false)) | |||
.toTable(db); | |||
assertThrows(InvalidValueException.class, () -> testNz.addRow(Column.AUTO_NUMBER, "")); | |||
t.addRow(Column.AUTO_NUMBER, "v1"); | |||
testNz.addRow(Column.AUTO_NUMBER, null); | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, ""); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException expected) { | |||
// success | |||
} | |||
expectedRows = createExpectedTable(createExpectedRow("id", 1, "value", "v1"), | |||
createExpectedRow("id", 2, "value", null)); | |||
assertTable(expectedRows, testNz); | |||
t.addRow(Column.AUTO_NUMBER, null); | |||
final Table testReqNz = newTable("testReqNz") | |||
.addColumn(newColumn("id", DataType.LONG) | |||
.setAutoNumber(true) | |||
.putProperty(PropertyMap.REQUIRED_PROP, true)) | |||
.addColumn(newColumn("value", DataType.TEXT)) | |||
.toTable(db); | |||
expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, | |||
"value", "v1"), | |||
createExpectedRow( | |||
"id", 2, | |||
"value", null)); | |||
assertTable(expectedRows, t); | |||
Column col = testReqNz.getColumn("value"); | |||
PropertyMap props = col.getProperties(); | |||
props.put(PropertyMap.REQUIRED_PROP, true); | |||
props.put(PropertyMap.ALLOW_ZERO_LEN_PROP, false); | |||
props.save(); | |||
testReqNz.addRow(Column.AUTO_NUMBER, "v1"); | |||
t = newTable("testReqNz") | |||
.addColumn(newColumn("id", DataType.LONG) | |||
.setAutoNumber(true) | |||
.putProperty(PropertyMap.REQUIRED_PROP, true)) | |||
.addColumn(newColumn("value", DataType.TEXT)) | |||
.toTable(db); | |||
assertThrows(InvalidValueException.class, () -> testReqNz.addRow(Column.AUTO_NUMBER, "")); | |||
Column col = t.getColumn("value"); | |||
PropertyMap props = col.getProperties(); | |||
props.put(PropertyMap.REQUIRED_PROP, true); | |||
props.put(PropertyMap.ALLOW_ZERO_LEN_PROP, false); | |||
props.save(); | |||
assertThrows(InvalidValueException.class, () -> testReqNz.addRow(Column.AUTO_NUMBER, null)); | |||
t.addRow(Column.AUTO_NUMBER, "v1"); | |||
testReqNz.addRow(Column.AUTO_NUMBER, "v2"); | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, ""); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException expected) { | |||
// success | |||
} | |||
expectedRows = createExpectedTable(createExpectedRow("id", 1, "value", "v1"), | |||
createExpectedRow("id", 2, "value", "v2")); | |||
assertTable(expectedRows, testReqNz); | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, null); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException expected) { | |||
// success | |||
} | |||
t.addRow(Column.AUTO_NUMBER, "v2"); | |||
expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, | |||
"value", "v1"), | |||
createExpectedRow( | |||
"id", 2, | |||
"value", "v2")); | |||
assertTable(expectedRows, t); | |||
db.close(); | |||
} | |||
} | |||
@Test | |||
public void testEnumValues() throws Exception | |||
{ | |||
PropertyMaps maps = new PropertyMaps(10, null, null, null); |
@@ -31,24 +31,21 @@ import com.healthmarketscience.jackcess.expr.Value; | |||
import com.healthmarketscience.jackcess.impl.expr.DefaultFunctions; | |||
import com.healthmarketscience.jackcess.impl.expr.FunctionSupport; | |||
import com.healthmarketscience.jackcess.impl.expr.ValueSupport; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.Database.*; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static com.healthmarketscience.jackcess.DatabaseBuilder.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class PropertyExpressionTest extends TestCase | |||
public class PropertyExpressionTest | |||
{ | |||
public PropertyExpressionTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testDefaultValue() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -114,6 +111,7 @@ public class PropertyExpressionTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testCalculatedValue() throws Exception | |||
{ | |||
Database db = create(FileFormat.V2016); | |||
@@ -158,142 +156,125 @@ public class PropertyExpressionTest extends TestCase | |||
db.close(); | |||
} | |||
@Test | |||
public void testColumnValidator() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
db.setEvaluateExpressions(true); | |||
Table t = newTable("test") | |||
.addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) | |||
.addColumn(newColumn("data1", DataType.LONG) | |||
.putProperty(PropertyMap.VALIDATION_RULE_PROP, | |||
">37")) | |||
.addColumn(newColumn("data2", DataType.LONG) | |||
.putProperty(PropertyMap.VALIDATION_RULE_PROP, | |||
"between 7 and 10") | |||
.putProperty(PropertyMap.VALIDATION_TEXT_PROP, | |||
"You failed")) | |||
.toTable(db); | |||
t.addRow(Column.AUTO_NUMBER, 42, 8); | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, 42, 20); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException ive) { | |||
// success | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (Database db = create(fileFormat)) | |||
{ | |||
db.setEvaluateExpressions(true); | |||
Table t = newTable("test") | |||
.addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) | |||
.addColumn(newColumn("data1", DataType.LONG) | |||
.putProperty(PropertyMap.VALIDATION_RULE_PROP, | |||
">37")) | |||
.addColumn(newColumn("data2", DataType.LONG) | |||
.putProperty(PropertyMap.VALIDATION_RULE_PROP, | |||
"between 7 and 10") | |||
.putProperty(PropertyMap.VALIDATION_TEXT_PROP, | |||
"You failed")) | |||
.toTable(db); | |||
t.addRow(Column.AUTO_NUMBER, 42, 8); | |||
InvalidValueException ive = assertThrows(InvalidValueException.class, | |||
() -> t.addRow(Column.AUTO_NUMBER, 42, 20)); | |||
assertTrue(ive.getMessage().contains("You failed")); | |||
} | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, 3, 8); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException ive) { | |||
// success | |||
ive = assertThrows(InvalidValueException.class, () -> t.addRow(Column.AUTO_NUMBER, 3, 8)); | |||
assertFalse(ive.getMessage().contains("You failed")); | |||
} | |||
t.addRow(Column.AUTO_NUMBER, 54, 9); | |||
t.addRow(Column.AUTO_NUMBER, 54, 9); | |||
setProp(t, "data1", PropertyMap.VALIDATION_RULE_PROP, null); | |||
setProp(t, "data2", PropertyMap.VALIDATION_RULE_PROP, "<100"); | |||
setProp(t, "data2", PropertyMap.VALIDATION_TEXT_PROP, "Too big"); | |||
setProp(t, "data1", PropertyMap.VALIDATION_RULE_PROP, null); | |||
setProp(t, "data2", PropertyMap.VALIDATION_RULE_PROP, "<100"); | |||
setProp(t, "data2", PropertyMap.VALIDATION_TEXT_PROP, "Too big"); | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, 42, 200); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException ive) { | |||
// success | |||
ive = assertThrows(InvalidValueException.class, () -> t.addRow(Column.AUTO_NUMBER, 42, 200)); | |||
assertTrue(ive.getMessage().contains("Too big")); | |||
} | |||
t.addRow(Column.AUTO_NUMBER, 1, 9); | |||
List<Row> expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, | |||
"data1", 42, | |||
"data2", 8), | |||
createExpectedRow( | |||
"id", 2, | |||
"data1", 54, | |||
"data2", 9), | |||
createExpectedRow( | |||
"id", 3, | |||
"data1", 1, | |||
"data2", 9)); | |||
assertTable(expectedRows, t); | |||
db.close(); | |||
t.addRow(Column.AUTO_NUMBER, 1, 9); | |||
List<Row> expectedRows | |||
= createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, | |||
"data1", 42, | |||
"data2", 8), | |||
createExpectedRow( | |||
"id", 2, | |||
"data1", 54, | |||
"data2", 9), | |||
createExpectedRow( | |||
"id", 3, | |||
"data1", 1, | |||
"data2", 9)); | |||
assertTable(expectedRows, t); | |||
} | |||
} | |||
} | |||
@Test | |||
public void testRowValidator() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
db.setEvaluateExpressions(true); | |||
Table t = newTable("test") | |||
.addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) | |||
.addColumn(newColumn("data1", DataType.LONG)) | |||
.addColumn(newColumn("data2", DataType.LONG)) | |||
.putProperty(PropertyMap.VALIDATION_RULE_PROP, | |||
"([data1] > 10) and ([data2] < 100)") | |||
.putProperty(PropertyMap.VALIDATION_TEXT_PROP, | |||
"You failed") | |||
.toTable(db); | |||
t.addRow(Column.AUTO_NUMBER, 42, 8); | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, 1, 20); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException ive) { | |||
// success | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
db.setEvaluateExpressions(true); | |||
Table t = newTable("test") | |||
.addColumn(newColumn("id", DataType.LONG).setAutoNumber(true)) | |||
.addColumn(newColumn("data1", DataType.LONG)) | |||
.addColumn(newColumn("data2", DataType.LONG)) | |||
.putProperty(PropertyMap.VALIDATION_RULE_PROP, | |||
"([data1] > 10) and ([data2] < 100)") | |||
.putProperty(PropertyMap.VALIDATION_TEXT_PROP, | |||
"You failed") | |||
.toTable(db); | |||
t.addRow(Column.AUTO_NUMBER, 42, 8); | |||
InvalidValueException ive = assertThrows(InvalidValueException.class, | |||
() -> t.addRow(Column.AUTO_NUMBER, 1, 20)); | |||
assertTrue(ive.getMessage().contains("You failed")); | |||
} | |||
t.addRow(Column.AUTO_NUMBER, 54, 9); | |||
t.addRow(Column.AUTO_NUMBER, 54, 9); | |||
setTableProp(t, PropertyMap.VALIDATION_RULE_PROP, "[data2]<100"); | |||
setTableProp(t, PropertyMap.VALIDATION_TEXT_PROP, "Too big"); | |||
setTableProp(t, PropertyMap.VALIDATION_RULE_PROP, "[data2]<100"); | |||
setTableProp(t, PropertyMap.VALIDATION_TEXT_PROP, "Too big"); | |||
try { | |||
t.addRow(Column.AUTO_NUMBER, 42, 200); | |||
fail("InvalidValueException should have been thrown"); | |||
} catch(InvalidValueException ive) { | |||
// success | |||
ive = assertThrows(InvalidValueException.class, () -> t.addRow(Column.AUTO_NUMBER, 42, 200)); | |||
assertTrue(ive.getMessage().contains("Too big")); | |||
} | |||
t.addRow(Column.AUTO_NUMBER, 1, 9); | |||
t.addRow(Column.AUTO_NUMBER, 1, 9); | |||
List<Row> expectedRows | |||
= createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, | |||
"data1", 42, | |||
"data2", 8), | |||
createExpectedRow( | |||
"id", 2, | |||
"data1", 54, | |||
"data2", 9), | |||
createExpectedRow( | |||
"id", 3, | |||
"data1", 1, | |||
"data2", 9)); | |||
assertTable(expectedRows, t); | |||
List<Row> expectedRows = | |||
createExpectedTable( | |||
createExpectedRow( | |||
"id", 1, | |||
"data1", 42, | |||
"data2", 8), | |||
createExpectedRow( | |||
"id", 2, | |||
"data1", 54, | |||
"data2", 9), | |||
createExpectedRow( | |||
"id", 3, | |||
"data1", 1, | |||
"data2", 9)); | |||
assertTable(expectedRows, t); | |||
db.close(); | |||
} | |||
} | |||
} | |||
public static void testCustomEvalConfig() throws Exception | |||
@Test | |||
public void testCustomEvalConfig() throws Exception | |||
{ | |||
TemporalConfig tempConf = new TemporalConfig("[uuuu/]M/d", | |||
"uuuu-MMM-d", |
@@ -24,24 +24,22 @@ import java.util.List; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import com.healthmarketscience.jackcess.impl.RelationshipImpl; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class RelationshipTest extends TestCase { | |||
public class RelationshipTest | |||
{ | |||
private static final Comparator<Relationship> REL_COMP = new Comparator<Relationship>() { | |||
public int compare(Relationship r1, Relationship r2) { | |||
return String.CASE_INSENSITIVE_ORDER.compare(r1.getName(), r2.getName()); | |||
} | |||
}; | |||
public RelationshipTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testTwoTables() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { | |||
Database db = open(testDB); | |||
@@ -83,15 +81,11 @@ public class RelationshipTest extends TestCase { | |||
assertTrue(rel.cascadeUpdates()); | |||
assertSameRelationships(rels, db.getRelationships(t3, t1), true); | |||
try { | |||
db.getRelationships(t1, t1); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException ignored) { | |||
// success | |||
} | |||
assertThrows(IllegalArgumentException.class, () -> db.getRelationships(t1, t1)); | |||
} | |||
} | |||
@Test | |||
public void testOneTable() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { | |||
Database db = open(testDB); | |||
@@ -108,6 +102,7 @@ public class RelationshipTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testNoTables() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { | |||
Database db = open(testDB); |
@@ -28,24 +28,20 @@ import com.healthmarketscience.jackcess.impl.ColumnImpl; | |||
import com.healthmarketscience.jackcess.impl.JetFormat; | |||
import com.healthmarketscience.jackcess.impl.PageChannel; | |||
import com.healthmarketscience.jackcess.impl.TableImpl; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author Tim McCune | |||
*/ | |||
public class TableTest extends TestCase { | |||
public class TableTest | |||
{ | |||
private final PageChannel _pageChannel = new PageChannel(true) {}; | |||
private List<ColumnImpl> _columns = new ArrayList<ColumnImpl>(); | |||
private TestTable _testTable; | |||
private int _varLenIdx; | |||
private int _fixedOffset; | |||
public TableTest(String name) { | |||
super(name); | |||
} | |||
private void reset() { | |||
_testTable = null; | |||
_columns = new ArrayList<ColumnImpl>(); | |||
@@ -53,6 +49,7 @@ public class TableTest extends TestCase { | |||
_fixedOffset = 0; | |||
} | |||
@Test | |||
public void testCreateRow() throws Exception { | |||
reset(); | |||
newTestColumn(DataType.INT, false); | |||
@@ -73,6 +70,7 @@ public class TableTest extends TestCase { | |||
assertEquals((byte) 7, buffer.get(30)); | |||
} | |||
@Test | |||
public void testUnicodeCompression() throws Exception { | |||
reset(); | |||
newTestColumn(DataType.TEXT, false); |
@@ -26,21 +26,18 @@ import com.healthmarketscience.jackcess.Database.FileFormat; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import com.healthmarketscience.jackcess.impl.DatabaseImpl; | |||
import com.healthmarketscience.jackcess.impl.TableImpl; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.DatabaseBuilder.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class TableUpdaterTest extends TestCase | |||
public class TableUpdaterTest | |||
{ | |||
public TableUpdaterTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testTableUpdating() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
@@ -51,6 +48,7 @@ public class TableUpdaterTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testTableUpdatingOneToOne() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
@@ -61,6 +59,7 @@ public class TableUpdaterTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testTableUpdatingNoEnforce() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
@@ -71,6 +70,7 @@ public class TableUpdaterTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testTableUpdatingNamedRelationship() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
@@ -84,11 +84,11 @@ public class TableUpdaterTest extends TestCase | |||
private void doTestUpdating(Database db, boolean oneToOne, boolean enforce, String relationshipName) | |||
throws Exception | |||
{ | |||
Table t1 = newTable("TestTable") | |||
final Table t1 = newTable("TestTable") | |||
.addColumn(newColumn("id", DataType.LONG)) | |||
.toTable(db); | |||
Table t2 = newTable("TestTable2") | |||
final Table t2 = newTable("TestTable2") | |||
.addColumn(newColumn("id2", DataType.LONG)) | |||
.toTable(db); | |||
@@ -195,48 +195,37 @@ public class TableUpdaterTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testInvalidUpdate() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
Table t1 = newTable("TestTable") | |||
.addColumn(newColumn("id", DataType.LONG)) | |||
.toTable(db); | |||
try { | |||
newColumn("ID", DataType.TEXT) | |||
.addToTable(t1); | |||
fail("created table with no columns?"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
Table t1 = newTable("TestTable") | |||
.addColumn(newColumn("id", DataType.LONG)) | |||
.toTable(db); | |||
assertThrows(IllegalArgumentException.class, | |||
() -> newColumn("ID", DataType.TEXT).addToTable(t1), | |||
"created table with no columns?"); | |||
Table t2 = newTable("TestTable2") | |||
.addColumn(newColumn("id2", DataType.LONG)) | |||
.toTable(db); | |||
assertThrows(IllegalArgumentException.class, | |||
() -> newRelationship(t1, t2).toRelationship(db), | |||
"created rel with no columns?"); | |||
assertThrows(IllegalArgumentException.class, | |||
() -> newRelationship("TestTable", "TestTable2").addColumns("id", "id") .toRelationship(db), | |||
"created rel with wrong columns?"); | |||
} | |||
Table t2 = newTable("TestTable2") | |||
.addColumn(newColumn("id2", DataType.LONG)) | |||
.toTable(db); | |||
try { | |||
newRelationship(t1, t2) | |||
.toRelationship(db); | |||
fail("created rel with no columns?"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
try { | |||
newRelationship("TestTable", "TestTable2") | |||
.addColumns("id", "id") | |||
.toRelationship(db); | |||
fail("created rel with wrong columns?"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
db.close(); | |||
} | |||
} | |||
@Test | |||
public void testUpdateLargeTableDef() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { |
@@ -50,7 +50,7 @@ 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; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
/** | |||
* Utilty code for the test cases. | |||
@@ -201,12 +201,10 @@ public class TestUtil | |||
.setAutoSync(getTestAutoSync()).setChannel(channel) | |||
.setCharset(charset).open(); | |||
if(fileFormat != null) { | |||
Assert.assertEquals( | |||
"Wrong JetFormat.", | |||
DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), | |||
((DatabaseImpl)db).getFormat()); | |||
Assert.assertEquals( | |||
"Wrong FileFormat.", fileFormat, db.getFileFormat()); | |||
assertEquals(DatabaseImpl.getFileFormatDetails(fileFormat).getFormat(), | |||
((DatabaseImpl)db).getFormat(), | |||
"Wrong JetFormat."); | |||
assertEquals(fileFormat, db.getFileFormat(), "Wrong FileFormat."); | |||
} | |||
return db; | |||
} | |||
@@ -259,8 +257,8 @@ public class TestUtil | |||
static void assertRowCount(int expectedRowCount, Table table) | |||
throws Exception | |||
{ | |||
Assert.assertEquals(expectedRowCount, countRows(table)); | |||
Assert.assertEquals(expectedRowCount, table.getRowCount()); | |||
assertEquals(expectedRowCount, countRows(table)); | |||
assertEquals(expectedRowCount, table.getRowCount()); | |||
} | |||
public static int countRows(Table table) throws Exception { | |||
@@ -288,9 +286,9 @@ public class TestUtil | |||
for(Map<String, Object> row : cursor) { | |||
foundTable.add(row); | |||
} | |||
Assert.assertEquals(expectedTable.size(), foundTable.size()); | |||
assertEquals(expectedTable.size(), foundTable.size()); | |||
for(int i = 0; i < expectedTable.size(); ++i) { | |||
Assert.assertEquals(expectedTable.get(i), foundTable.get(i)); | |||
assertEquals(expectedTable.get(i), foundTable.get(i)); | |||
} | |||
} | |||
@@ -427,7 +425,7 @@ public class TestUtil | |||
Instant.ofEpochMilli(expected.getTime()), | |||
ZoneId.systemDefault()); | |||
Assert.assertEquals(expectedLdt, found); | |||
assertEquals(expectedLdt, found); | |||
} | |||
public static void copyFile(File srcFile, File dstFile) | |||
@@ -500,42 +498,42 @@ public class TestUtil | |||
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")); | |||
assertEquals("abcdefg", row.get("A"), "testDB: " + testDB + "; table: " + table); | |||
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")); | |||
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")); | |||
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 { | |||
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")); | |||
assertEquals("a", row.get("A"), "testDB: " + testDB + "; table: " + table); | |||
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")); | |||
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")); | |||
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")); | |||
} | |||
} |
@@ -33,20 +33,16 @@ import com.healthmarketscience.jackcess.Table; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class AutoNumberTest extends TestCase | |||
public class AutoNumberTest | |||
{ | |||
public AutoNumberTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testAutoNumber() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -64,6 +60,7 @@ public class AutoNumberTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testAutoNumberPK() throws Exception | |||
{ | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST) { | |||
@@ -125,6 +122,7 @@ public class AutoNumberTest extends TestCase | |||
assertTable(expectedRows, table); | |||
} | |||
@Test | |||
public void testAutoNumberGuid() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -153,6 +151,7 @@ public class AutoNumberTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testInsertLongAutoNumber() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -170,6 +169,7 @@ public class AutoNumberTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testInsertLongAutoNumberPK() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -232,12 +232,7 @@ public class AutoNumberTest extends TestCase | |||
assertEquals(13, ((TableImpl)table).getLastLongAutoNumber()); | |||
try { | |||
table.addRow("not a number", "nope"); | |||
fail("NumberFormatException should have been thrown"); | |||
} catch(NumberFormatException e) { | |||
// success | |||
} | |||
assertThrows(NumberFormatException.class, () -> table.addRow("not a number", "nope")); | |||
assertEquals(13, ((TableImpl)table).getLastLongAutoNumber()); | |||
@@ -273,6 +268,7 @@ public class AutoNumberTest extends TestCase | |||
} | |||
@Test | |||
public void testInsertComplexAutoNumber() throws Exception | |||
{ | |||
for(final TestDB testDB : TestDB.getSupportedForBasename(Basename.COMPLEX)) { | |||
@@ -311,76 +307,50 @@ public class AutoNumberTest extends TestCase | |||
assertEquals(13, ((TableImpl)t1).getLastComplexTypeAutoNumber()); | |||
try { | |||
t1.addRow("nope", "not a number"); | |||
fail("NumberFormatException should have been thrown"); | |||
} catch(NumberFormatException e) { | |||
// success | |||
} | |||
assertThrows(NumberFormatException.class, () -> t1.addRow("nope", "not a number")); | |||
assertEquals(13, ((TableImpl)t1).getLastComplexTypeAutoNumber()); | |||
try { | |||
t1.addRow("uh-uh", -10); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
assertThrows(IOException.class, () -> t1.addRow("uh-uh", -10)); | |||
assertEquals(13, ((TableImpl)t1).getLastComplexTypeAutoNumber()); | |||
try { | |||
t1.addRow("wut", 6, null, null, 40, 42); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
assertThrows(IOException.class, () -> t1.addRow("wut", 6, null, null, 40, 42)); | |||
row = t1.addRow("morerows"); | |||
checkAllComplexAutoNums(14, row); | |||
assertEquals(14, ((TableImpl)t1).getLastComplexTypeAutoNumber()); | |||
Row row13 = CursorBuilder.findRow( | |||
t1, Collections.singletonMap("id", "row13")); | |||
final Row row13 = CursorBuilder.findRow(t1, Collections.singletonMap("id", "row13")); | |||
row13.put("VersionHistory_F5F8918F-0A3F-4DA9-AE71-184EE5012880", "45"); | |||
row13.put("multi-value-data", "45"); | |||
row13.put("attach-data", "45"); | |||
row13 = t1.updateRow(row13); | |||
checkAllComplexAutoNums(45, row13); | |||
final Row row14 = t1.updateRow(row13); | |||
checkAllComplexAutoNums(45, row14); | |||
assertEquals(45, ((TableImpl)t1).getLastComplexTypeAutoNumber()); | |||
row13.put("attach-data", -1); | |||
row14.put("attach-data", -1); | |||
try { | |||
t1.updateRow(row13); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
assertThrows(IOException.class, () -> t1.updateRow(row14)); | |||
assertEquals(45, ((TableImpl)t1).getLastComplexTypeAutoNumber()); | |||
row13.put("attach-data", 55); | |||
row14.put("attach-data", 55); | |||
try { | |||
t1.updateRow(row13); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
assertThrows(IOException.class, () -> t1.updateRow(row14)); | |||
assertEquals(45, ((TableImpl)t1).getLastComplexTypeAutoNumber()); | |||
row13.put("VersionHistory_F5F8918F-0A3F-4DA9-AE71-184EE5012880", 55); | |||
row13.put("multi-value-data", 55); | |||
row14.put("VersionHistory_F5F8918F-0A3F-4DA9-AE71-184EE5012880", 55); | |||
row14.put("multi-value-data", 55); | |||
db.setAllowAutoNumberInsert(null); | |||
row13 = t1.updateRow(row13); | |||
checkAllComplexAutoNums(45, row13); | |||
final Row row15 = t1.updateRow(row14); | |||
checkAllComplexAutoNums(45, row15); | |||
assertEquals(45, ((TableImpl)t1).getLastComplexTypeAutoNumber()); | |||
@@ -397,91 +367,90 @@ public class AutoNumberTest extends TestCase | |||
private static void checkAllComplexAutoNums(int expected, Row row) | |||
{ | |||
assertEquals(expected, ((Number)row.get("VersionHistory_F5F8918F-0A3F-4DA9-AE71-184EE5012880")).intValue()); | |||
assertEquals(expected, ((Number)row.get("multi-value-data")).intValue()); | |||
assertEquals(expected, ((Number)row.get("attach-data")).intValue()); | |||
assertEquals(expected, ((Number)row.get("VersionHistory_F5F8918F-0A3F-4DA9-AE71-184EE5012880")).intValue()); | |||
assertEquals(expected, ((Number)row.get("multi-value-data")).intValue()); | |||
assertEquals(expected, ((Number)row.get("attach-data")).intValue()); | |||
} | |||
@Test | |||
public void testInsertGuidAutoNumber() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = createMem(fileFormat); | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = createMem(fileFormat)) | |||
{ | |||
Table table = newTable("test") | |||
.addColumn(newColumn("a", DataType.GUID) | |||
.setAutoNumber(true)) | |||
.addColumn(newColumn("b", DataType.TEXT)) | |||
.toTable(db); | |||
Table table = newTable("test") | |||
.addColumn(newColumn("a", DataType.GUID) | |||
.setAutoNumber(true)) | |||
.addColumn(newColumn("b", DataType.TEXT)) | |||
.toTable(db); | |||
db.setAllowAutoNumberInsert(true); | |||
table.setAllowAutoNumberInsert(false); | |||
assertFalse(table.isAllowAutoNumberInsert()); | |||
db.setAllowAutoNumberInsert(true); | |||
table.setAllowAutoNumberInsert(false); | |||
assertFalse(table.isAllowAutoNumberInsert()); | |||
Object[] row = {null, "row1"}; | |||
assertSame(row, table.addRow(row)); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
row = table.addRow(13, "row2"); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
row = table.addRow("flubber", "row3"); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
Object[] row = | |||
{ | |||
null, "row1" | |||
}; | |||
assertSame(row, table.addRow(row)); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
row = table.addRow(13, "row2"); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
row = table.addRow("flubber", "row3"); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
Object[] smallRow = {Column.AUTO_NUMBER}; | |||
row = table.addRow(smallRow); | |||
assertNotSame(row, smallRow); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
Object[] smallRow = | |||
{ | |||
Column.AUTO_NUMBER | |||
}; | |||
row = table.addRow(smallRow); | |||
assertNotSame(row, smallRow); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
table.setAllowAutoNumberInsert(null); | |||
assertTrue(table.isAllowAutoNumberInsert()); | |||
table.setAllowAutoNumberInsert(null); | |||
assertTrue(table.isAllowAutoNumberInsert()); | |||
Row row2 = CursorBuilder.findRow( | |||
table, Collections.singletonMap("b", "row2")); | |||
assertEquals("row2", row2.getString("b")); | |||
Row row2 = CursorBuilder.findRow( | |||
table, Collections.singletonMap("b", "row2")); | |||
assertEquals("row2", row2.getString("b")); | |||
String row2Guid = row2.getString("a"); | |||
table.deleteRow(row2); | |||
String row2Guid = row2.getString("a"); | |||
table.deleteRow(row2); | |||
row = table.addRow(Column.AUTO_NUMBER, "row4"); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
row = table.addRow(Column.AUTO_NUMBER, "row4"); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
row = table.addRow(row2Guid, "row2-redux"); | |||
assertEquals(row2Guid, row[0]); | |||
row = table.addRow(row2Guid, "row2-redux"); | |||
assertEquals(row2Guid, row[0]); | |||
row2 = CursorBuilder.findRow( | |||
table, Collections.singletonMap("a", row2Guid)); | |||
assertEquals("row2-redux", row2.getString("b")); | |||
row2 = CursorBuilder.findRow( | |||
table, Collections.singletonMap("a", row2Guid)); | |||
assertEquals("row2-redux", row2.getString("b")); | |||
try { | |||
table.addRow("not a guid", "nope"); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
assertThrows(IOException.class, () -> table.addRow("not a guid", "nope")); | |||
row = table.addRow(Column.AUTO_NUMBER, "row5"); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
row = table.addRow(Column.AUTO_NUMBER, "row5"); | |||
assertTrue(ColumnImpl.isGUIDValue(row[0])); | |||
row2Guid = UUID.randomUUID().toString(); | |||
row2.put("a", row2Guid); | |||
row2Guid = UUID.randomUUID().toString(); | |||
row2.put("a", row2Guid); | |||
row2 = table.updateRow(row2); | |||
assertEquals(row2Guid, row2.get("a")); | |||
final Row row3 = table.updateRow(row2); | |||
assertEquals(row2Guid, row3.get("a")); | |||
row2.put("a", "not a guid"); | |||
row3.put("a", "not a guid"); | |||
try { | |||
table.updateRow(row2); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
assertThrows(IOException.class, () -> table.updateRow(row3)); | |||
table.setAllowAutoNumberInsert(false); | |||
table.setAllowAutoNumberInsert(false); | |||
row2 = table.updateRow(row2); | |||
assertTrue(ColumnImpl.isGUIDValue(row2.get("a"))); | |||
assertFalse(row2Guid.equals(row2.get("a"))); | |||
final Row row4 = table.updateRow(row3); | |||
assertTrue(ColumnImpl.isGUIDValue(row4.get("a"))); | |||
assertFalse(row2Guid.equals(row4.get("a"))); | |||
db.close(); | |||
} | |||
} | |||
} | |||
@@ -18,7 +18,6 @@ package com.healthmarketscience.jackcess.impl; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.Comparator; | |||
import java.util.List; | |||
import java.util.Map; | |||
@@ -27,22 +26,18 @@ import com.healthmarketscience.jackcess.Cursor; | |||
import com.healthmarketscience.jackcess.DataType; | |||
import com.healthmarketscience.jackcess.Database; | |||
import com.healthmarketscience.jackcess.Table; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static com.healthmarketscience.jackcess.DatabaseBuilder.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class BigIntTest extends TestCase | |||
public class BigIntTest | |||
{ | |||
public BigIntTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testBigInt() throws Exception { | |||
for (final Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) { |
@@ -31,32 +31,26 @@ import com.healthmarketscience.jackcess.PropertyMap; | |||
import com.healthmarketscience.jackcess.Row; | |||
import com.healthmarketscience.jackcess.Table; | |||
import com.healthmarketscience.jackcess.TableBuilder; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class CalcFieldTest extends TestCase | |||
public class CalcFieldTest | |||
{ | |||
public CalcFieldTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testCreateCalcField() throws Exception { | |||
ColumnBuilder cb = new ColumnBuilder("calc_data", DataType.TEXT) | |||
.setCalculatedInfo("[id] & \"_\" & [data]"); | |||
try { | |||
cb.validate(JetFormat.VERSION_12); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException e) { | |||
assertTrue(e.getMessage().contains("")); | |||
} | |||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, | |||
() -> cb.validate(JetFormat.VERSION_12)); | |||
assertTrue(e.getMessage().contains("")); | |||
cb.validate(JetFormat.VERSION_14); | |||
@@ -145,6 +139,7 @@ public class CalcFieldTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testReadCalcFields() throws Exception { | |||
for(TestDB testDB : TestDB.getSupportedForBasename(Basename.CALC_FIELD)) { |
@@ -34,14 +34,15 @@ 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; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class CodecHandlerTest extends TestCase | |||
public class CodecHandlerTest | |||
{ | |||
private static final CodecProvider SIMPLE_PROVIDER = new CodecProvider() { | |||
public CodecHandler createHandler(PageChannel channel, Charset charset) | |||
@@ -59,10 +60,7 @@ public class CodecHandlerTest extends TestCase | |||
}; | |||
public CodecHandlerTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testCodecHandler() throws Exception | |||
{ | |||
doTestCodecHandler(true); |
@@ -36,19 +36,16 @@ import com.healthmarketscience.jackcess.TableBuilder; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import com.healthmarketscience.jackcess.util.RowFilterTest; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class DatabaseReadWriteTest extends TestCase | |||
public class DatabaseReadWriteTest | |||
{ | |||
public DatabaseReadWriteTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testWriteAndRead() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
@@ -57,6 +54,7 @@ public class DatabaseReadWriteTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testWriteAndReadInMem() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = createMem(fileFormat); | |||
@@ -92,6 +90,7 @@ public class DatabaseReadWriteTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testWriteAndReadInBatch() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = createMem(fileFormat); | |||
@@ -120,6 +119,7 @@ public class DatabaseReadWriteTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testUpdateRow() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
@@ -234,6 +234,7 @@ public class DatabaseReadWriteTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testDateMath() | |||
{ | |||
long now = System.currentTimeMillis(); |
@@ -35,20 +35,16 @@ import com.healthmarketscience.jackcess.Row; | |||
import com.healthmarketscience.jackcess.Table; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import junit.framework.TestCase; | |||
import org.junit.Assert; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class ExtendedDateTest extends TestCase | |||
public class ExtendedDateTest | |||
{ | |||
public ExtendedDateTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testReadExtendedDate() throws Exception { | |||
DateTimeFormatter dtfNoTime = DateTimeFormatter.ofPattern("M/d/yyy"); | |||
@@ -67,9 +63,9 @@ public class ExtendedDateTest extends TestCase | |||
String str1 = dtfNoTime.format(ldt); | |||
String str2 = dtfFull.format(ldt); | |||
Assert.assertTrue(str1.equals(str) || str2.equals(str)); | |||
assertTrue(str1.equals(str) || str2.equals(str)); | |||
} else { | |||
Assert.assertNull(str); | |||
assertNull(str); | |||
} | |||
} | |||
@@ -83,6 +79,7 @@ public class ExtendedDateTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testWriteExtendedDate() throws Exception { | |||
for (final Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) { |
@@ -12,8 +12,7 @@ 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.impl; | |||
import java.io.IOException; | |||
@@ -28,22 +27,21 @@ import com.healthmarketscience.jackcess.Database; | |||
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.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class FKEnforcerTest extends TestCase | |||
public class FKEnforcerTest | |||
{ | |||
public FKEnforcerTest(String name) throws Exception { | |||
super(name); | |||
} | |||
public void testNoEnforceForeignKeys() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) { | |||
@Test | |||
public void testNoEnforceForeignKeys() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) | |||
{ | |||
Database db = openCopy(testDB); | |||
db.setEnforceForeignKeys(false); | |||
@@ -66,78 +64,76 @@ public class FKEnforcerTest extends TestCase | |||
} | |||
public void testEnforceForeignKeys() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) { | |||
Database db = openCopy(testDB); | |||
db.setEvaluateExpressions(false); | |||
Table t1 = db.getTable("Table1"); | |||
Table t2 = db.getTable("Table2"); | |||
Table t3 = db.getTable("Table3"); | |||
try { | |||
t1.addRow(20, 0, 20, "some data", 20); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException ignored) { | |||
// success | |||
assertTrue(ignored.getMessage().contains("Table1[otherfk2]")); | |||
} | |||
try { | |||
Cursor c = CursorBuilder.createCursor(t2); | |||
c.moveToNextRow(); | |||
c.updateCurrentRow(30, "foo30"); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException ignored) { | |||
// success | |||
assertTrue(ignored.getMessage().contains("Table2[id]")); | |||
} | |||
@Test | |||
public void testEnforceForeignKeys() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) | |||
{ | |||
try (final Database db = openCopy(testDB)) | |||
{ | |||
db.setEvaluateExpressions(false); | |||
Table t1 = db.getTable("Table1"); | |||
Table t2 = db.getTable("Table2"); | |||
Table t3 = db.getTable("Table3"); | |||
IOException ioe = assertThrows(IOException.class, () -> t1.addRow(20, 0, 20, "some data", 20)); | |||
assertTrue(ioe.getMessage().contains("Table1[otherfk2]")); | |||
ioe = assertThrows(IOException.class, | |||
() -> | |||
{ | |||
Cursor c = CursorBuilder.createCursor(t2); | |||
c.moveToNextRow(); | |||
c.updateCurrentRow(30, "foo30"); | |||
}); | |||
assertTrue(ioe.getMessage().contains("Table2[id]")); | |||
ioe = assertThrows(IOException.class, | |||
() -> | |||
{ | |||
Cursor c = CursorBuilder.createCursor(t3); | |||
c.moveToNextRow(); | |||
c.deleteCurrentRow(); | |||
fail("IOException should have been thrown"); | |||
}); | |||
assertTrue(ioe.getMessage().contains("Table3[id]")); | |||
t1.addRow(21, null, null, "null fks", null); | |||
try { | |||
Cursor c = CursorBuilder.createCursor(t3); | |||
c.moveToNextRow(); | |||
c.deleteCurrentRow(); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException ignored) { | |||
// success | |||
assertTrue(ignored.getMessage().contains("Table3[id]")); | |||
} | |||
Column col = t3.getColumn("id"); | |||
for (Row row : c) | |||
{ | |||
int id = row.getInt("id"); | |||
id += 20; | |||
c.setCurrentRowValue(col, id); | |||
} | |||
List<? extends Map<String, Object>> expectedRows | |||
= createExpectedTable( | |||
createT1Row(0, 0, 30, "baz0", 0), | |||
createT1Row(1, 1, 31, "baz11", 0), | |||
createT1Row(2, 1, 31, "baz11-2", 0), | |||
createT1Row(3, 2, 33, "baz13", 0), | |||
createT1Row(21, null, null, "null fks", null)); | |||
assertTable(expectedRows, t1); | |||
c = CursorBuilder.createCursor(t2); | |||
for (Iterator<?> iter = c.iterator(); iter.hasNext();) | |||
{ | |||
iter.next(); | |||
iter.remove(); | |||
} | |||
assertEquals(1, t1.getRowCount()); | |||
t1.addRow(21, null, null, "null fks", null); | |||
Cursor c = CursorBuilder.createCursor(t3); | |||
Column col = t3.getColumn("id"); | |||
for(Row row : c) { | |||
int id = row.getInt("id"); | |||
id += 20; | |||
c.setCurrentRowValue(col, id); | |||
} | |||
List<? extends Map<String, Object>> expectedRows = | |||
createExpectedTable( | |||
createT1Row(0, 0, 30, "baz0", 0), | |||
createT1Row(1, 1, 31, "baz11", 0), | |||
createT1Row(2, 1, 31, "baz11-2", 0), | |||
createT1Row(3, 2, 33, "baz13", 0), | |||
createT1Row(21, null, null, "null fks", null)); | |||
assertTable(expectedRows, t1); | |||
c = CursorBuilder.createCursor(t2); | |||
for(Iterator<?> iter = c.iterator(); iter.hasNext(); ) { | |||
iter.next(); | |||
iter.remove(); | |||
} | |||
assertEquals(1, t1.getRowCount()); | |||
db.close(); | |||
} | |||
} | |||
private static Row createT1Row( | |||
int id1, Integer fk1, Integer fk2, String data, Integer fk3) | |||
int id1, Integer fk1, Integer fk2, String data, Integer fk3) | |||
{ | |||
return createExpectedRow("id", id1, "otherfk1", fk1, "otherfk2", fk2, | |||
"data", data, "otherfk3", fk3); |
@@ -37,16 +37,16 @@ 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 org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class IndexCodesTest extends TestCase { | |||
private static final Map<Character,String> SPECIAL_CHARS = | |||
new HashMap<Character,String>(); | |||
public class IndexCodesTest | |||
{ | |||
private static final Map<Character,String> SPECIAL_CHARS = new HashMap<>(); | |||
static { | |||
SPECIAL_CHARS.put('\b', "\\b"); | |||
SPECIAL_CHARS.put('\t', "\\t"); | |||
@@ -58,10 +58,7 @@ public class IndexCodesTest extends TestCase { | |||
SPECIAL_CHARS.put('\\', "\\\\"); | |||
} | |||
public IndexCodesTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testIndexCodes() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX_CODES, true)) { | |||
@@ -160,6 +157,7 @@ public class IndexCodesTest extends TestCase { | |||
// | |||
////// | |||
@Test | |||
public void testNothing() throws Exception { | |||
// keep this so build doesn't fail if other tests are disabled | |||
} |
@@ -17,8 +17,9 @@ import com.healthmarketscience.jackcess.JackcessException; | |||
import static com.healthmarketscience.jackcess.Database.*; | |||
import com.healthmarketscience.jackcess.DatabaseBuilder; | |||
import com.healthmarketscience.jackcess.PropertyMap; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
@@ -26,8 +27,8 @@ import static com.healthmarketscience.jackcess.TestUtil.*; | |||
* Date: Mar 5, 2010 | |||
* Time: 12:44:21 PM | |||
*/ | |||
public class JetFormatTest extends TestCase { | |||
public class JetFormatTest | |||
{ | |||
public static final File DIR_TEST_DATA = new File("src/test/data"); | |||
/** | |||
@@ -201,32 +202,30 @@ public class JetFormatTest extends TestCase { | |||
TestDB.getSupportedForBasename(Basename.TEST, true); | |||
public void testGetFormat() throws Exception { | |||
try { | |||
JetFormat.getFormat(null); | |||
fail("npe"); | |||
} catch (NullPointerException e) { | |||
// success | |||
} | |||
@Test | |||
public void testGetFormat() throws Exception | |||
{ | |||
assertThrows(NullPointerException.class, () -> JetFormat.getFormat(null)); | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
final FileChannel channel = DatabaseImpl.openChannel( | |||
testDB.dbFile.toPath(), false, false); | |||
try { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) | |||
{ | |||
final FileChannel channel = DatabaseImpl.openChannel(testDB.dbFile.toPath(), false, false); | |||
try | |||
{ | |||
JetFormat fmtActual = JetFormat.getFormat(channel); | |||
assertEquals("Unexpected JetFormat for dbFile: " + | |||
testDB.dbFile.getAbsolutePath(), | |||
testDB.getExpectedFormat(), fmtActual); | |||
} finally { | |||
assertEquals(testDB.getExpectedFormat(), | |||
fmtActual, | |||
"Unexpected JetFormat for dbFile: " + testDB.dbFile.getAbsolutePath()); | |||
} | |||
finally | |||
{ | |||
channel.close(); | |||
} | |||
} | |||
} | |||
@Test | |||
public void testReadOnlyFormat() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
@@ -259,6 +258,7 @@ public class JetFormatTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testFileFormat() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { | |||
@@ -286,6 +286,7 @@ public class JetFormatTest extends TestCase { | |||
} | |||
} | |||
@Test | |||
public void testSqlTypes() throws Exception { | |||
JetFormat v2000 = JetFormat.VERSION_4; |
@@ -34,19 +34,16 @@ import com.healthmarketscience.jackcess.Table; | |||
import com.healthmarketscience.jackcess.TableBuilder; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class LongValueTest extends TestCase | |||
public class LongValueTest | |||
{ | |||
public LongValueTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testReadLongValue() throws Exception { | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.TEST2, true)) { |
@@ -22,20 +22,16 @@ import java.util.Collections; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class TopoSorterTest extends TestCase | |||
public class TopoSorterTest | |||
{ | |||
public TopoSorterTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testTopoSort() throws Exception | |||
{ | |||
doTopoTest(Arrays.asList("A", "B", "C"), | |||
@@ -46,27 +42,19 @@ public class TopoSorterTest extends TestCase | |||
"B", "C", | |||
"A", "B"); | |||
try { | |||
doTopoTest(Arrays.asList("B", "A", "C"), | |||
Arrays.asList("C", "B", "A"), | |||
"B", "C", | |||
"A", "B", | |||
"C", "A"); | |||
fail("IllegalStateException should have been thrown"); | |||
} catch(IllegalStateException expected) { | |||
// success | |||
assertTrue(expected.getMessage().startsWith("Cycle")); | |||
} | |||
IllegalStateException expected = assertThrows(IllegalStateException.class, | |||
() -> doTopoTest(Arrays.asList("B", "A", "C"), | |||
Arrays.asList("C", "B", "A"), | |||
"B", "C", | |||
"A", "B", | |||
"C", "A")); | |||
assertTrue(expected.getMessage().startsWith("Cycle")); | |||
try { | |||
doTopoTest(Arrays.asList("B", "A", "C"), | |||
Arrays.asList("C", "B", "A"), | |||
"B", "D"); | |||
fail("IllegalStateException should have been thrown"); | |||
} catch(IllegalStateException expected) { | |||
// success | |||
assertTrue(expected.getMessage().startsWith("Unknown descendent")); | |||
} | |||
expected = assertThrows(IllegalStateException.class, | |||
() -> doTopoTest(Arrays.asList("B", "A", "C"), | |||
Arrays.asList("C", "B", "A"), | |||
"B", "D")); | |||
assertTrue(expected.getMessage().startsWith("Unknown descendent")); | |||
doTopoTest(Arrays.asList("B", "D", "A", "C"), | |||
Arrays.asList("D", "A", "B", "C"), | |||
@@ -107,7 +95,7 @@ public class TopoSorterTest extends TestCase | |||
List<String> expected, | |||
String... descs) { | |||
List<String> values = new ArrayList<String>(); | |||
List<String> values = new ArrayList<>(); | |||
values.addAll(original); | |||
TestTopoSorter tsorter = new TestTopoSorter(values, false); |
@@ -11,17 +11,20 @@ import com.healthmarketscience.jackcess.Database; | |||
import com.healthmarketscience.jackcess.DatabaseBuilder; | |||
import com.healthmarketscience.jackcess.Table; | |||
import com.healthmarketscience.jackcess.TableBuilder; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author Dan Rollo | |||
* Date: Mar 5, 2010 | |||
* Time: 2:21:22 PM | |||
*/ | |||
public final class UsageMapTest extends TestCase { | |||
public final class UsageMapTest | |||
{ | |||
@Test | |||
public void testRead() throws Exception { | |||
for (final TestDB testDB : SUPPORTED_DBS_TEST) { | |||
final int expectedFirstPage; | |||
@@ -55,12 +58,11 @@ public final class UsageMapTest extends TestCase { | |||
PageChannel.PAGE_GLOBAL_USAGE_MAP, | |||
PageChannel.ROW_GLOBAL_USAGE_MAP, | |||
true); | |||
assertEquals("Unexpected FirstPageNumber.", expectedFirstPage, | |||
usageMap.getFirstPageNumber()); | |||
assertEquals("Unexpected LastPageNumber.", expectedLastPage, | |||
usageMap.getLastPageNumber()); | |||
assertEquals(expectedFirstPage, usageMap.getFirstPageNumber(), "Unexpected FirstPageNumber."); | |||
assertEquals(expectedLastPage, usageMap.getLastPageNumber(), "Unexpected LastPageNumber."); | |||
} | |||
@Test | |||
public void testGobalReferenceUsageMap() throws Exception | |||
{ | |||
Database db = openCopy( |
@@ -21,22 +21,19 @@ import java.time.LocalDateTime; | |||
import java.util.Calendar; | |||
import com.healthmarketscience.jackcess.expr.EvalException; | |||
import junit.framework.AssertionFailedError; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.eval; | |||
import static com.healthmarketscience.jackcess.impl.expr.ExpressionatorTest.toBD; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
import org.opentest4j.AssertionFailedError; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class DefaultFunctionsTest extends TestCase | |||
public class DefaultFunctionsTest | |||
{ | |||
public DefaultFunctionsTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testFuncs() throws Exception | |||
{ | |||
assertEval("foo", "=IIf(10 > 1, \"foo\", \"bar\")"); | |||
@@ -58,12 +55,7 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval("-42", "=Str$(-42)"); | |||
assertNull(eval("=Str(Null)")); | |||
try { | |||
eval("=Str$(Null)"); | |||
fail("EvalException should have been thrown"); | |||
} catch(EvalException expected) { | |||
// success | |||
} | |||
assertThrows(EvalException.class, () -> eval("=Str$(Null)")); | |||
assertEval(-1, "=CBool(\"1\")"); | |||
assertEval(13, "=CByte(\"13\")"); | |||
@@ -184,19 +176,11 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval("bar", "=Switch(False,'foo', True, 'bar', True, 'blah')"); | |||
assertEval("blah", "=Switch(False,'foo', False, 'bar', True, 'blah')"); | |||
try { | |||
eval("=StrReverse('blah', 1)"); | |||
fail("EvalException should have been thrown"); | |||
} catch(EvalException e) { | |||
assertTrue(e.getMessage().contains("Invalid function call")); | |||
} | |||
EvalException e = assertThrows(EvalException.class, () -> eval("=StrReverse('blah', 1)")); | |||
assertTrue(e.getMessage().contains("Invalid function call")); | |||
try { | |||
eval("=StrReverse()"); | |||
fail("EvalException should have been thrown"); | |||
} catch(EvalException e) { | |||
assertTrue(e.getMessage().contains("Invalid function call")); | |||
} | |||
e = assertThrows(EvalException.class, () -> eval("=StrReverse()")); | |||
assertTrue(e.getMessage().contains("Invalid function call")); | |||
assertEval(1615198d, "=Val(' 1615 198th Street N.E.')"); | |||
assertEval(-1d, "=Val(' &HFFFFwhatever')"); | |||
@@ -266,6 +250,7 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval("13:37", "=FormatDateTime(#1/1/1973 1:37:25 PM#,4)"); | |||
} | |||
@Test | |||
public void testFormat() throws Exception | |||
{ | |||
assertEval("12345.6789", "=Format(12345.6789, 'General Number')"); | |||
@@ -330,6 +315,7 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval("19:00", "=Format(#01/02/2003 7:00:00 PM#, 'Short Time')"); | |||
} | |||
@Test | |||
public void testCustomFormat() throws Exception | |||
{ | |||
assertEval("07:00 a", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p')"); | |||
@@ -578,6 +564,7 @@ public class DefaultFunctionsTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testNumberFuncs() throws Exception | |||
{ | |||
assertEval(1, "=Abs(1)"); | |||
@@ -619,6 +606,7 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval(-4, "=Round(-4, 2)"); | |||
} | |||
@Test | |||
public void testDateFuncs() throws Exception | |||
{ | |||
assertEval("1/2/2003", "=CStr(DateValue(#01/02/2003 7:00:00 AM#))"); | |||
@@ -775,6 +763,7 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval(-83421497, "=DateDiff('s',#11/3/2018 2:15:30 PM#,#3/13/2016 1:37:13 AM#)"); | |||
} | |||
@Test | |||
public void testFinancialFuncs() throws Exception | |||
{ | |||
assertEval("-9.57859403981306", "=CStr(NPer(0.12/12,-100,-1000))"); |
@@ -37,13 +37,14 @@ import com.healthmarketscience.jackcess.expr.ParseException; | |||
import com.healthmarketscience.jackcess.expr.TemporalConfig; | |||
import com.healthmarketscience.jackcess.expr.Value; | |||
import com.healthmarketscience.jackcess.impl.BaseEvalContext; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class ExpressionatorTest extends TestCase | |||
public class ExpressionatorTest | |||
{ | |||
private static final double[] DBLS = { | |||
-10.3d,-9.0d,-8.234d,-7.11111d,-6.99999d,-5.5d,-4.0d,-3.4159265d,-2.84d, | |||
@@ -53,11 +54,7 @@ public class ExpressionatorTest extends TestCase | |||
private static final int TRUE_NUM = -1; | |||
private static final int FALSE_NUM = 0; | |||
public ExpressionatorTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testParseSimpleExprs() throws Exception | |||
{ | |||
validateExpr("\"A\"", "<ELiteralValue>{\"A\"}"); | |||
@@ -111,6 +108,7 @@ public class ExpressionatorTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testOrderOfOperations() throws Exception | |||
{ | |||
validateExpr("\"A\" Eqv \"B\"", | |||
@@ -149,6 +147,7 @@ public class ExpressionatorTest extends TestCase | |||
} | |||
@Test | |||
public void testSimpleMathExpressions() throws Exception | |||
{ | |||
for(int i = -10; i <= 10; ++i) { | |||
@@ -283,6 +282,7 @@ public class ExpressionatorTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testComparison() throws Exception | |||
{ | |||
assertEquals(TRUE_NUM, eval("='blah'<'fuzz'")); | |||
@@ -314,6 +314,7 @@ public class ExpressionatorTest extends TestCase | |||
assertEquals(TRUE_NUM, eval("=Not(True Eqv False)")); | |||
} | |||
@Test | |||
public void testDateArith() throws Exception | |||
{ | |||
assertEquals(LocalDateTime.of(2003,1,2,7,0), eval("=#01/02/2003# + #7:00:00 AM#")); | |||
@@ -327,6 +328,7 @@ public class ExpressionatorTest extends TestCase | |||
assertEquals("1/2/2003 1:10:00 PM", eval("=CStr(#01/02/2003# + #13:10:00#)")); | |||
} | |||
@Test | |||
public void testNull() throws Exception | |||
{ | |||
assertNull(eval("=37 + Null")); | |||
@@ -362,6 +364,7 @@ public class ExpressionatorTest extends TestCase | |||
assertNull(eval("=Null In (23, Null, 45)")); | |||
} | |||
@Test | |||
public void testTrickyMathExpressions() throws Exception | |||
{ | |||
assertEquals(37, eval("=30+7")); | |||
@@ -379,6 +382,7 @@ public class ExpressionatorTest extends TestCase | |||
assertEquals(toBD(-101d), eval("=-10E-1-10e+1")); | |||
} | |||
@Test | |||
public void testTypeCoercion() throws Exception | |||
{ | |||
assertEquals("foobar", eval("=\"foo\" + \"bar\"")); | |||
@@ -406,6 +410,7 @@ public class ExpressionatorTest extends TestCase | |||
assertEquals(128208, eval("=#1/1/2017# * 3")); | |||
} | |||
@Test | |||
public void testLikeExpression() throws Exception | |||
{ | |||
validateExpr("Like \"[abc]*\"", "<ELikeOp>{<EThisValue>{<THIS_COL>} Like \"[abc]*\"([abc].*)}", | |||
@@ -421,6 +426,7 @@ public class ExpressionatorTest extends TestCase | |||
assertFalse(evalCondition("Like \"[abc*\"", "")); | |||
} | |||
@Test | |||
public void testLiteralDefaultValue() throws Exception | |||
{ | |||
assertEquals("-28 blah ", eval("=CDbl(9)-37 & \" blah \"", | |||
@@ -432,6 +438,7 @@ public class ExpressionatorTest extends TestCase | |||
assertEquals(-28d, eval("CDbl(9)-37", Value.Type.DOUBLE)); | |||
} | |||
@Test | |||
public void testParseSomeExprs() throws Exception | |||
{ | |||
BufferedReader br = new BufferedReader(new FileReader("src/test/resources/test_exprs.txt")); | |||
@@ -473,6 +480,7 @@ public class ExpressionatorTest extends TestCase | |||
br.close(); | |||
} | |||
@Test | |||
public void testInvalidExpressions() throws Exception | |||
{ | |||
doTestEvalFail("", "empty"); | |||
@@ -490,14 +498,10 @@ public class ExpressionatorTest extends TestCase | |||
doTestEvalFail("=(3 + 5) Rnd()", "multiple expressions"); | |||
} | |||
private static void doTestEvalFail(String exprStr, String msgStr) { | |||
try { | |||
eval(exprStr); | |||
fail("ParseException should have been thrown"); | |||
} catch(ParseException pe) { | |||
// success | |||
assertTrue(pe.getMessage().contains(msgStr)); | |||
} | |||
private static void doTestEvalFail(String exprStr, String msgStr) | |||
{ | |||
final ParseException pe = assertThrows(ParseException.class, () -> eval(exprStr)); | |||
assertTrue(pe.getMessage().contains(msgStr)); | |||
} | |||
private static void validateExpr(String exprStr, String debugStr) { | |||
@@ -531,18 +535,13 @@ public class ExpressionatorTest extends TestCase | |||
return expr.eval(tc); | |||
} | |||
private static void evalFail( | |||
String exprStr, Class<? extends Exception> failure) | |||
private static void evalFail(String exprStr, Class<? extends Exception> failure) | |||
{ | |||
TestContext tc = new TestContext(); | |||
Expression expr = Expressionator.parse( | |||
Expressionator.Type.DEFAULT_VALUE, exprStr, null, tc); | |||
try { | |||
expr.eval(tc); | |||
fail(failure + " should have been thrown"); | |||
} catch(Exception e) { | |||
assertTrue(failure.isInstance(e)); | |||
} | |||
final TestContext tc = new TestContext(); | |||
Expression expr = Expressionator.parse(Expressionator.Type.DEFAULT_VALUE, exprStr, null, tc); | |||
final Exception e = assertThrows(Exception.class, () -> expr.eval(tc)); | |||
assertTrue(failure.isInstance(e)); | |||
} | |||
private static Boolean evalCondition(String exprStr, String thisVal) { |
@@ -18,21 +18,17 @@ package com.healthmarketscience.jackcess.impl.expr; | |||
import java.math.BigDecimal; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class NumberFormatterTest extends TestCase | |||
public class NumberFormatterTest | |||
{ | |||
public NumberFormatterTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testDoubleFormat() throws Exception | |||
{ | |||
assertEquals("894984737284944", NumberFormatter.format(894984737284944d)); | |||
@@ -60,6 +56,7 @@ public class NumberFormatterTest extends TestCase | |||
assertEquals("1.#QNAN", NumberFormatter.format(Double.NaN)); | |||
} | |||
@Test | |||
public void testFloatFormat() throws Exception | |||
{ | |||
assertEquals("8949847", NumberFormatter.format(8949847f)); | |||
@@ -87,6 +84,7 @@ public class NumberFormatterTest extends TestCase | |||
assertEquals("1.#QNAN", NumberFormatter.format(Float.NaN)); | |||
} | |||
@Test | |||
public void testDecimalFormat() throws Exception | |||
{ | |||
assertEquals("9874539485972.2342342234234", NumberFormatter.format(new BigDecimal("9874539485972.2342342234234"))); |
@@ -28,24 +28,21 @@ import com.healthmarketscience.jackcess.Database; | |||
import com.healthmarketscience.jackcess.TestUtil; | |||
import com.healthmarketscience.jackcess.impl.query.QueryImpl; | |||
import com.healthmarketscience.jackcess.impl.query.QueryImpl.Row; | |||
import junit.framework.TestCase; | |||
import org.apache.commons.lang3.StringUtils; | |||
import static com.healthmarketscience.jackcess.impl.query.QueryFormat.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class QueryTest extends TestCase | |||
public class QueryTest | |||
{ | |||
public QueryTest(String name) throws Exception { | |||
super(name); | |||
} | |||
@Test | |||
public void testUnionQuery() throws Exception | |||
{ | |||
String expr1 = "Select * from Table1"; | |||
@@ -77,15 +74,10 @@ public class QueryTest extends TestCase | |||
removeRows(query, TABLE_ATTRIBUTE); | |||
try { | |||
query.toSQLString(); | |||
fail("IllegalStateException should have been thrown"); | |||
} catch(IllegalStateException e) { | |||
// success | |||
} | |||
assertThrows(IllegalStateException.class, () -> query.toSQLString()); | |||
} | |||
@Test | |||
public void testPassthroughQuery() throws Exception | |||
{ | |||
String expr = "Select * from Table1"; | |||
@@ -98,6 +90,7 @@ public class QueryTest extends TestCase | |||
assertEquals(constr, query.getConnectionString()); | |||
} | |||
@Test | |||
public void testDataDefinitionQuery() throws Exception | |||
{ | |||
String expr = "Drop table Table1"; | |||
@@ -108,6 +101,7 @@ public class QueryTest extends TestCase | |||
assertEquals(expr, query.toSQLString()); | |||
} | |||
@Test | |||
public void testUpdateQuery() throws Exception | |||
{ | |||
UpdateQuery query = (UpdateQuery)newQuery( | |||
@@ -131,6 +125,7 @@ public class QueryTest extends TestCase | |||
query.toSQLString()); | |||
} | |||
@Test | |||
public void testSelectQuery() throws Exception | |||
{ | |||
SelectQuery query = (SelectQuery)newQuery( | |||
@@ -154,40 +149,32 @@ public class QueryTest extends TestCase | |||
doTestOrderings(query); | |||
} | |||
@Test | |||
public void testBadQueries() throws Exception | |||
{ | |||
List<Row> rowList = new ArrayList<Row>(); | |||
rowList.add(newRow(TYPE_ATTRIBUTE, null, -1, null, null)); | |||
QueryImpl query = QueryImpl.create(-1, "TestQuery", rowList, 13); | |||
try { | |||
query.toSQLString(); | |||
fail("UnsupportedOperationException should have been thrown"); | |||
} catch(UnsupportedOperationException e) { | |||
// success | |||
} | |||
addRows(query, newRow(TYPE_ATTRIBUTE, null, -1, null, null)); | |||
assertThrows(UnsupportedOperationException.class, () -> query.toSQLString()); | |||
try { | |||
query.getTypeRow(); | |||
fail("IllegalStateException should have been thrown"); | |||
} catch(IllegalStateException e) { | |||
// success | |||
} | |||
addRows(query, newRow(TYPE_ATTRIBUTE, null, -1, null, null)); | |||
try { | |||
new QueryImpl("TestQuery", rowList, 13, Query.Type.UNION.getObjectFlag(), | |||
Query.Type.UNION) { | |||
@Override protected void toSQLString(StringBuilder builder) { | |||
throw new UnsupportedOperationException(); | |||
}}; | |||
fail("IllegalStateException should have been thrown"); | |||
} catch(IllegalStateException e) { | |||
// success | |||
} | |||
assertThrows(IllegalStateException.class, () -> query.getTypeRow()); | |||
assertThrows(IllegalStateException.class, | |||
() -> new QueryImpl("TestQuery", rowList, 13, Query.Type.UNION.getObjectFlag(), | |||
Query.Type.UNION) | |||
{ | |||
@Override | |||
protected void toSQLString(StringBuilder builder) | |||
{ | |||
throw new UnsupportedOperationException(); | |||
} | |||
}); | |||
} | |||
@Test | |||
public void testReadQueries() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.QUERY, true)) { | |||
@@ -256,6 +243,7 @@ public class QueryTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testAppendQuery() throws Exception | |||
{ | |||
AppendQuery query = (AppendQuery)newQuery( | |||
@@ -336,12 +324,7 @@ public class QueryTest extends TestCase | |||
query.toSQLString()); | |||
addRows(query, newRow(PARAMETER_ATTRIBUTE, null, -1, "BadVal", null)); | |||
try { | |||
query.toSQLString(); | |||
fail("IllegalStateException should have been thrown"); | |||
} catch(IllegalStateException e) { | |||
// success | |||
} | |||
assertThrows(IllegalStateException.class, () -> query.toSQLString()); | |||
removeRows(query, PARAMETER_ATTRIBUTE); | |||
} | |||
@@ -395,12 +378,7 @@ public class QueryTest extends TestCase | |||
addRows(query, newRow(JOIN_ATTRIBUTE, "(Table1.id = Table3Val.id)", 5, "Table1", "Table3Val")); | |||
try { | |||
query.toSQLString(); | |||
fail("IllegalStateException should have been thrown"); | |||
} catch(IllegalStateException e) { | |||
// success | |||
} | |||
assertThrows(IllegalStateException.class, () -> query.toSQLString()); | |||
removeLastRows(query, 1); | |||
query.toSQLString(); | |||
@@ -463,6 +441,7 @@ public class QueryTest extends TestCase | |||
query.toSQLString()); | |||
} | |||
@Test | |||
public void testComplexJoins() throws Exception | |||
{ | |||
SelectQuery query = (SelectQuery)newQuery( | |||
@@ -491,12 +470,7 @@ public class QueryTest extends TestCase | |||
addJoinRows(query, 1, 2, 1, | |||
2, 1, 2); | |||
try { | |||
query.toSQLString(); | |||
fail("IllegalStateException should have been thrown"); | |||
} catch(IllegalStateException e) { | |||
// success | |||
} | |||
assertThrows(IllegalStateException.class, () -> query.toSQLString()); | |||
addJoinRows(query, 1, 2, 1, | |||
3, 4, 1, |
@@ -19,30 +19,28 @@ package com.healthmarketscience.jackcess.util; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.Map; | |||
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 com.healthmarketscience.jackcess.Database.FileFormat; | |||
import com.healthmarketscience.jackcess.IndexCursor; | |||
import com.healthmarketscience.jackcess.PropertyMap; | |||
import com.healthmarketscience.jackcess.Row; | |||
import com.healthmarketscience.jackcess.Table; | |||
import com.healthmarketscience.jackcess.TableBuilder; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class ColumnFormatterTest extends TestCase | |||
public class ColumnFormatterTest | |||
{ | |||
@Test | |||
public void testFormat() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { |
@@ -29,21 +29,18 @@ import com.healthmarketscience.jackcess.IndexCursor; | |||
import com.healthmarketscience.jackcess.Row; | |||
import com.healthmarketscience.jackcess.Table; | |||
import com.healthmarketscience.jackcess.TableBuilder; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class ColumnValidatorTest extends TestCase | |||
public class ColumnValidatorTest | |||
{ | |||
public ColumnValidatorTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testValidate() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
@@ -96,9 +93,9 @@ public class ColumnValidatorTest extends TestCase | |||
db.setColumnValidatorFactory(fact); | |||
table = db.getTable("Test"); | |||
final Table test = db.getTable("Test"); | |||
for(Column col : table.getColumns()) { | |||
for(Column col : test.getColumns()) { | |||
ColumnValidator cur = col.getColumnValidator(); | |||
assertNotNull(cur); | |||
if("num".equals(col.getName())) { | |||
@@ -108,26 +105,19 @@ public class ColumnValidatorTest extends TestCase | |||
} | |||
} | |||
Column idCol = table.getColumn("id"); | |||
Column dataCol = table.getColumn("data"); | |||
Column numCol = table.getColumn("num"); | |||
Column idCol = test.getColumn("id"); | |||
Column dataCol = test.getColumn("data"); | |||
Column numCol = test.getColumn("num"); | |||
assertThrows(IllegalArgumentException.class, () -> idCol.setColumnValidator(cv)); | |||
try { | |||
idCol.setColumnValidator(cv); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException e) { | |||
// success | |||
} | |||
assertSame(SimpleColumnValidator.INSTANCE, idCol.getColumnValidator()); | |||
try { | |||
table.addRow(Column.AUTO_NUMBER, "row4", -3); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException e) { | |||
assertEquals("not gonna happen", e.getMessage()); | |||
} | |||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, | |||
() -> test.addRow(Column.AUTO_NUMBER, "row4", -3)); | |||
assertEquals("not gonna happen", e.getMessage()); | |||
table.addRow(Column.AUTO_NUMBER, "row4", 4); | |||
test.addRow(Column.AUTO_NUMBER, "row4", 4); | |||
List<? extends Map<String, Object>> expectedRows = | |||
createExpectedTable( | |||
@@ -136,9 +126,9 @@ public class ColumnValidatorTest extends TestCase | |||
createExpectedRow("id", 3, "data", "row3", "num", 1), | |||
createExpectedRow("id", 4, "data", "row4", "num", 4)); | |||
assertTable(expectedRows, table); | |||
assertTable(expectedRows, test); | |||
IndexCursor pkCursor = CursorBuilder.createPrimaryKeyCursor(table); | |||
IndexCursor pkCursor = CursorBuilder.createPrimaryKeyCursor(test); | |||
assertNotNull(pkCursor.findRowByEntry(1)); | |||
pkCursor.setCurrentRowValue(dataCol, "row1_mod"); | |||
@@ -146,29 +136,22 @@ public class ColumnValidatorTest extends TestCase | |||
assertEquals(createExpectedRow("id", 1, "data", "row1_mod", "num", -1), | |||
pkCursor.getCurrentRow()); | |||
try { | |||
pkCursor.setCurrentRowValue(numCol, -2); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException e) { | |||
assertEquals("not gonna happen", e.getMessage()); | |||
} | |||
e = assertThrows(IllegalArgumentException.class, | |||
() -> pkCursor.setCurrentRowValue(numCol, -2)); | |||
assertEquals("not gonna happen", e.getMessage()); | |||
assertEquals(createExpectedRow("id", 1, "data", "row1_mod", "num", -1), | |||
pkCursor.getCurrentRow()); | |||
Row row3 = CursorBuilder.findRowByPrimaryKey(table, 3); | |||
Row row3 = CursorBuilder.findRowByPrimaryKey(test, 3); | |||
row3.put("num", -2); | |||
try { | |||
table.updateRow(row3); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException e) { | |||
assertEquals("not gonna happen", e.getMessage()); | |||
} | |||
e = assertThrows(IllegalArgumentException.class, () -> test.updateRow(row3)); | |||
assertEquals("not gonna happen", e.getMessage()); | |||
assertEquals(createExpectedRow("id", 3, "data", "row3", "num", 1), | |||
CursorBuilder.findRowByPrimaryKey(table, 3)); | |||
CursorBuilder.findRowByPrimaryKey(test, 3)); | |||
final ColumnValidator cv2 = (col, v1) -> { | |||
Number num = (Number)v1; | |||
@@ -180,7 +163,7 @@ public class ColumnValidatorTest extends TestCase | |||
numCol.setColumnValidator(cv2); | |||
table.addRow(Column.AUTO_NUMBER, "row5", -5); | |||
test.addRow(Column.AUTO_NUMBER, "row5", -5); | |||
expectedRows = | |||
createExpectedTable( | |||
@@ -190,7 +173,7 @@ public class ColumnValidatorTest extends TestCase | |||
createExpectedRow("id", 4, "data", "row4", "num", 4), | |||
createExpectedRow("id", 5, "data", "row5", "num", 0)); | |||
assertTable(expectedRows, table); | |||
assertTable(expectedRows, test); | |||
assertNotNull(pkCursor.findRowByEntry(3)); | |||
pkCursor.setCurrentRowValue(numCol, -10); |
@@ -26,66 +26,53 @@ import com.healthmarketscience.jackcess.Database; | |||
import com.healthmarketscience.jackcess.Database.FileFormat; | |||
import com.healthmarketscience.jackcess.Table; | |||
import com.healthmarketscience.jackcess.TableBuilder; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class CustomLinkResolverTest extends TestCase | |||
public class CustomLinkResolverTest | |||
{ | |||
@Test | |||
public void testCustomLinkResolver() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
db.setLinkResolver(new TestLinkResolver()); | |||
public CustomLinkResolverTest(String name) { | |||
super(name); | |||
} | |||
db.createLinkedTable("Table1", "testFile1.txt", "Table1"); | |||
db.createLinkedTable("Table2", "testFile2.txt", "OtherTable2"); | |||
db.createLinkedTable("Table3", "missingFile3.txt", "MissingTable3"); | |||
db.createLinkedTable("Table4", "testFile2.txt", "MissingTable4"); | |||
public void testCustomLinkResolver() throws Exception { | |||
for(final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
db.setLinkResolver(new TestLinkResolver()); | |||
db.createLinkedTable("Table1", "testFile1.txt", "Table1"); | |||
db.createLinkedTable("Table2", "testFile2.txt", "OtherTable2"); | |||
db.createLinkedTable("Table3", "missingFile3.txt", "MissingTable3"); | |||
db.createLinkedTable("Table4", "testFile2.txt", "MissingTable4"); | |||
Table t1 = db.getTable("Table1"); | |||
assertNotNull(t1); | |||
assertNotSame(db, t1.getDatabase()); | |||
assertTable(createExpectedTable(createExpectedRow("id", 0, | |||
"data1", "row0"), | |||
createExpectedRow("id", 1, | |||
"data1", "row1"), | |||
createExpectedRow("id", 2, | |||
"data1", "row2")), | |||
t1); | |||
Table t2 = db.getTable("Table2"); | |||
assertNotNull(t2); | |||
assertNotSame(db, t2.getDatabase()); | |||
assertTable(createExpectedTable(createExpectedRow("id", 3, | |||
"data2", "row3"), | |||
createExpectedRow("id", 4, | |||
"data2", "row4"), | |||
createExpectedRow("id", 5, | |||
"data2", "row5")), | |||
t2); | |||
assertNull(db.getTable("Table4")); | |||
try { | |||
db.getTable("Table3"); | |||
fail("FileNotFoundException should have been thrown"); | |||
} catch(FileNotFoundException e) { | |||
// success | |||
} | |||
Table t1 = db.getTable("Table1"); | |||
assertNotNull(t1); | |||
assertNotSame(db, t1.getDatabase()); | |||
assertTable(createExpectedTable(createExpectedRow("id", 0, "data1", "row0"), | |||
createExpectedRow("id", 1, "data1", "row1"), | |||
createExpectedRow("id", 2, "data1", "row2")), | |||
t1); | |||
db.close(); | |||
Table t2 = db.getTable("Table2"); | |||
assertNotNull(t2); | |||
assertNotSame(db, t2.getDatabase()); | |||
assertTable(createExpectedTable(createExpectedRow("id", 3, "data2", "row3"), | |||
createExpectedRow("id", 4, "data2", "row4"), | |||
createExpectedRow("id", 5, "data2", "row5")), | |||
t2); | |||
assertNull(db.getTable("Table4")); | |||
assertThrows(FileNotFoundException.class, () -> db.getTable("Table3")); | |||
} | |||
} | |||
} | |||
@@ -34,110 +34,76 @@ 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.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class ErrorHandlerTest extends TestCase | |||
public class ErrorHandlerTest | |||
{ | |||
public ErrorHandlerTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testErrorHandler() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
Database db = create(fileFormat); | |||
Table table = | |||
new TableBuilder("test") | |||
.addColumn(new ColumnBuilder("col", DataType.TEXT)) | |||
.addColumn(new ColumnBuilder("val", DataType.LONG)) | |||
.toTable(db); | |||
table.addRow("row1", 1); | |||
table.addRow("row2", 2); | |||
table.addRow("row3", 3); | |||
assertTable(createExpectedTable( | |||
createExpectedRow("col", "row1", | |||
"val", 1), | |||
createExpectedRow("col", "row2", | |||
"val", 2), | |||
createExpectedRow("col", "row3", | |||
"val", 3)), | |||
table); | |||
replaceColumn(table, "val"); | |||
table.reset(); | |||
try { | |||
table.getNextRow(); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) | |||
{ | |||
try (final Database db = create(fileFormat)) | |||
{ | |||
final Table table | |||
= new TableBuilder("test") | |||
.addColumn(new ColumnBuilder("col", DataType.TEXT)) | |||
.addColumn(new ColumnBuilder("val", DataType.LONG)) | |||
.toTable(db); | |||
table.reset(); | |||
table.setErrorHandler(new ReplacementErrorHandler()); | |||
assertTable(createExpectedTable( | |||
createExpectedRow("col", "row1", | |||
"val", null), | |||
createExpectedRow("col", "row2", | |||
"val", null), | |||
createExpectedRow("col", "row3", | |||
"val", null)), | |||
table); | |||
Cursor c1 = CursorBuilder.createCursor(table); | |||
Cursor c2 = CursorBuilder.createCursor(table); | |||
Cursor c3 = CursorBuilder.createCursor(table); | |||
c2.setErrorHandler(new DebugErrorHandler("#error")); | |||
c3.setErrorHandler(ErrorHandler.DEFAULT); | |||
assertCursor(createExpectedTable( | |||
createExpectedRow("col", "row1", | |||
"val", null), | |||
createExpectedRow("col", "row2", | |||
"val", null), | |||
createExpectedRow("col", "row3", | |||
"val", null)), | |||
c1); | |||
assertCursor(createExpectedTable( | |||
createExpectedRow("col", "row1", | |||
"val", "#error"), | |||
createExpectedRow("col", "row2", | |||
"val", "#error"), | |||
createExpectedRow("col", "row3", | |||
"val", "#error")), | |||
c2); | |||
try { | |||
c3.getNextRow(); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
table.addRow("row1", 1); | |||
table.addRow("row2", 2); | |||
table.addRow("row3", 3); | |||
table.setErrorHandler(null); | |||
c1.setErrorHandler(null); | |||
c1.reset(); | |||
try { | |||
c1.getNextRow(); | |||
fail("IOException should have been thrown"); | |||
} catch(IOException e) { | |||
// success | |||
} | |||
assertTable(createExpectedTable(createExpectedRow("col", "row1", "val", 1), | |||
createExpectedRow("col", "row2", "val", 2), | |||
createExpectedRow("col", "row3", "val", 3)), | |||
table); | |||
replaceColumn(table, "val"); | |||
table.reset(); | |||
assertThrows(IOException.class, () -> table.getNextRow()); | |||
table.reset(); | |||
table.setErrorHandler(new ReplacementErrorHandler()); | |||
db.close(); | |||
assertTable(createExpectedTable(createExpectedRow("col", "row1", "val", null), | |||
createExpectedRow("col", "row2", "val", null), | |||
createExpectedRow("col", "row3", "val", null)), | |||
table); | |||
Cursor c1 = CursorBuilder.createCursor(table); | |||
Cursor c2 = CursorBuilder.createCursor(table); | |||
Cursor c3 = CursorBuilder.createCursor(table); | |||
c2.setErrorHandler(new DebugErrorHandler("#error")); | |||
c3.setErrorHandler(ErrorHandler.DEFAULT); | |||
assertCursor(createExpectedTable(createExpectedRow("col", "row1", "val", null), | |||
createExpectedRow("col", "row2", "val", null), | |||
createExpectedRow("col", "row3", "val", null)), | |||
c1); | |||
assertCursor(createExpectedTable(createExpectedRow("col", "row1", "val", "#error"), | |||
createExpectedRow("col", "row2", "val", "#error"), | |||
createExpectedRow("col", "row3", "val", "#error")), | |||
c2); | |||
assertThrows(IOException.class, () -> c3.getNextRow()); | |||
table.setErrorHandler(null); | |||
c1.setErrorHandler(null); | |||
c1.reset(); | |||
assertThrows(IOException.class, () -> c1.getNextRow()); | |||
} | |||
} | |||
} | |||
@@ -30,22 +30,19 @@ import com.healthmarketscience.jackcess.DateTimeType; | |||
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.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class ExportTest extends TestCase | |||
public class ExportTest | |||
{ | |||
private static final String NL = System.lineSeparator(); | |||
public ExportTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testExportToFile() throws Exception | |||
{ | |||
DateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); |
@@ -36,19 +36,16 @@ import static com.healthmarketscience.jackcess.Database.*; | |||
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.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author Rob Di Marco | |||
*/ | |||
public class ImportTest extends TestCase | |||
public class ImportTest | |||
{ | |||
public ImportTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testImportFromFile() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
@@ -177,6 +174,7 @@ public class ImportTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testImportFromFileWithOnlyHeaders() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { | |||
@@ -201,6 +199,7 @@ public class ImportTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testCopySqlHeaders() throws Exception | |||
{ | |||
for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) { |
@@ -31,19 +31,17 @@ 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.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class JoinerTest extends TestCase { | |||
public JoinerTest(String name) { | |||
super(name); | |||
} | |||
public class JoinerTest | |||
{ | |||
@Test | |||
public void testJoiner() throws Exception | |||
{ | |||
for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) { |
@@ -24,49 +24,29 @@ import java.nio.channels.FileChannel; | |||
import java.nio.channels.NonWritableChannelException; | |||
import java.util.Arrays; | |||
import junit.framework.TestCase; | |||
import com.healthmarketscience.jackcess.TestUtil; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class MemFileChannelTest extends TestCase | |||
public class MemFileChannelTest | |||
{ | |||
public MemFileChannelTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testReadOnlyChannel() throws Exception | |||
{ | |||
File testFile = new File("src/test/data/V1997/compIndexTestV1997.mdb"); | |||
MemFileChannel ch = MemFileChannel.newChannel(testFile, "r"); | |||
final MemFileChannel ch = MemFileChannel.newChannel(testFile, "r"); | |||
assertEquals(testFile.length(), ch.size()); | |||
assertEquals(0L, ch.position()); | |||
try { | |||
ByteBuffer bb = ByteBuffer.allocate(1024); | |||
ch.write(bb); | |||
fail("NonWritableChannelException should have been thrown"); | |||
} catch(NonWritableChannelException ignored) { | |||
// success | |||
} | |||
assertThrows(NonWritableChannelException.class, () -> ch.write(ByteBuffer.allocate(1024))); | |||
try { | |||
ch.truncate(0L); | |||
fail("NonWritableChannelException should have been thrown"); | |||
} catch(NonWritableChannelException ignored) { | |||
// success | |||
} | |||
assertThrows(NonWritableChannelException.class, () -> ch.truncate(0L)); | |||
try { | |||
ch.transferFrom(null, 0L, 10L); | |||
fail("NonWritableChannelException should have been thrown"); | |||
} catch(NonWritableChannelException ignored) { | |||
// success | |||
} | |||
assertThrows(NonWritableChannelException.class, () -> ch.transferFrom(null, 0L, 10L)); | |||
assertEquals(testFile.length(), ch.size()); | |||
assertEquals(0L, ch.position()); | |||
@@ -74,11 +54,12 @@ public class MemFileChannelTest extends TestCase | |||
ch.close(); | |||
} | |||
@Test | |||
public void testChannel() throws Exception | |||
{ | |||
ByteBuffer bb = ByteBuffer.allocate(1024); | |||
MemFileChannel ch = MemFileChannel.newChannel(); | |||
final MemFileChannel ch = MemFileChannel.newChannel(); | |||
assertTrue(ch.isOpen()); | |||
assertEquals(0L, ch.size()); | |||
assertEquals(0L, ch.position()); | |||
@@ -89,36 +70,26 @@ public class MemFileChannelTest extends TestCase | |||
assertFalse(ch.isOpen()); | |||
File testFile = new File("src/test/data/V1997/compIndexTestV1997.mdb"); | |||
ch = MemFileChannel.newChannel(testFile, "r"); | |||
assertEquals(testFile.length(), ch.size()); | |||
assertEquals(0L, ch.position()); | |||
final MemFileChannel ch1 = MemFileChannel.newChannel(testFile, "r"); | |||
assertEquals(testFile.length(), ch1.size()); | |||
assertEquals(0L, ch1.position()); | |||
try { | |||
ch.position(-1); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException ignored) { | |||
// success | |||
} | |||
assertThrows(IllegalArgumentException.class, () -> ch1.position(-1)); | |||
MemFileChannel ch2 = MemFileChannel.newChannel(); | |||
ch.transferTo(ch2); | |||
final MemFileChannel ch2 = MemFileChannel.newChannel(); | |||
ch1.transferTo(ch2); | |||
ch2.force(true); | |||
assertEquals(testFile.length(), ch2.size()); | |||
assertEquals(testFile.length(), ch2.position()); | |||
try { | |||
ch2.truncate(-1L); | |||
fail("IllegalArgumentException should have been thrown"); | |||
} catch(IllegalArgumentException ignored) { | |||
// success | |||
} | |||
assertThrows(IllegalArgumentException.class, () -> ch2.truncate(-1L)); | |||
long trucSize = ch2.size()/3; | |||
ch2.truncate(trucSize); | |||
assertEquals(trucSize, ch2.size()); | |||
assertEquals(trucSize, ch2.position()); | |||
ch2.position(0L); | |||
copy(ch, ch2, bb); | |||
copy(ch1, ch2, bb); | |||
File tmpFile = File.createTempFile("chtest_", ".dat"); | |||
tmpFile.deleteOnExit(); |
@@ -31,24 +31,21 @@ import com.healthmarketscience.jackcess.TableBuilder; | |||
import com.healthmarketscience.jackcess.complex.Attachment; | |||
import com.healthmarketscience.jackcess.impl.ByteUtil; | |||
import com.healthmarketscience.jackcess.impl.CompoundOleUtil; | |||
import junit.framework.TestCase; | |||
import org.apache.poi.poifs.filesystem.DocumentEntry; | |||
import org.apache.poi.poifs.filesystem.DocumentInputStream; | |||
import org.apache.poi.poifs.filesystem.POIFSFileSystem; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class OleBlobTest extends TestCase | |||
public class OleBlobTest | |||
{ | |||
public OleBlobTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testCreateBlob() throws Exception | |||
{ | |||
File sampleFile = new File("src/test/data/sample-input.tab"); | |||
@@ -153,6 +150,7 @@ public class OleBlobTest extends TestCase | |||
} | |||
} | |||
@Test | |||
public void testReadBlob() throws Exception | |||
{ | |||
for(TestDB testDb : TestDB.getSupportedForBasename(Basename.BLOB, true)) { |
@@ -30,19 +30,16 @@ import com.healthmarketscience.jackcess.Table; | |||
import com.healthmarketscience.jackcess.TableBuilder; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; | |||
import junit.framework.TestCase; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* | |||
* @author James Ahlborn | |||
*/ | |||
public class PatternColumnPredicateTest extends TestCase | |||
public class PatternColumnPredicateTest | |||
{ | |||
public PatternColumnPredicateTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
public void testRegexPredicate() throws Exception { | |||
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { | |||
Database db = createTestDb(fileFormat); |
@@ -23,24 +23,21 @@ import java.util.List; | |||
import com.healthmarketscience.jackcess.DataType; | |||
import com.healthmarketscience.jackcess.Row; | |||
import com.healthmarketscience.jackcess.impl.ColumnImpl; | |||
import junit.framework.TestCase; | |||
import static com.healthmarketscience.jackcess.TestUtil.*; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
import org.junit.jupiter.api.Test; | |||
/** | |||
* @author James Ahlborn | |||
*/ | |||
public class RowFilterTest extends TestCase | |||
public class RowFilterTest | |||
{ | |||
private static final String ID_COL = "id"; | |||
private static final String COL1 = "col1"; | |||
private static final String COL2 = "col2"; | |||
private static final String COL3 = "col3"; | |||
public RowFilterTest(String name) { | |||
super(name); | |||
} | |||
@Test | |||
@SuppressWarnings("unchecked") | |||
public void testFilter() throws Exception | |||
{ |