diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2013-05-31 03:49:51 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2013-05-31 03:49:51 +0000 |
commit | 99f648a340dd45967550a511f8a27a16c2c5b5f3 (patch) | |
tree | 7ca6af53c65791cdc1b56035b24c2b8ed5f96ccd /test | |
parent | be3cd1952c56ca0396da609133016e93e44c1078 (diff) | |
download | jackcess-99f648a340dd45967550a511f8a27a16c2c5b5f3.tar.gz jackcess-99f648a340dd45967550a511f8a27a16c2c5b5f3.zip |
add more methods to Database for retrieving Relationships
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@732 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test')
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java | 60 |
1 files changed, 52 insertions, 8 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java b/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java index 4f3175f..e49b9bb 100644 --- a/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java @@ -27,24 +27,32 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; import java.util.List; -import junit.framework.TestCase; - import static com.healthmarketscience.jackcess.DatabaseTest.*; import static com.healthmarketscience.jackcess.JetFormatTest.*; +import junit.framework.TestCase; /** * @author James Ahlborn */ public class RelationshipTest extends TestCase { + 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); } - public void testSimple() throws Exception { + public void testTwoTables() throws Exception { for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { Database db = open(testDB); Table t1 = db.getTable("Table1"); @@ -64,11 +72,11 @@ public class RelationshipTest extends TestCase { assertTrue(rel.hasReferentialIntegrity()); assertEquals(4096, rel.getFlags()); assertTrue(rel.cascadeDeletes()); - assertSameRelationships(rels, db.getRelationships(t2, t1)); + assertSameRelationships(rels, db.getRelationships(t2, t1), true); rels = db.getRelationships(t2, t3); assertTrue(db.getRelationships(t2, t3).isEmpty()); - assertSameRelationships(rels, db.getRelationships(t3, t2)); + assertSameRelationships(rels, db.getRelationships(t3, t2), true); rels = db.getRelationships(t1, t3); assertEquals(1, rels.size()); @@ -83,7 +91,7 @@ public class RelationshipTest extends TestCase { assertTrue(rel.hasReferentialIntegrity()); assertEquals(256, rel.getFlags()); assertTrue(rel.cascadeUpdates()); - assertSameRelationships(rels, db.getRelationships(t3, t1)); + assertSameRelationships(rels, db.getRelationships(t3, t1), true); try { db.getRelationships(t1, t1); @@ -94,10 +102,46 @@ public class RelationshipTest extends TestCase { } } - private void assertSameRelationships( - List<Relationship> expected, List<Relationship> found) + public void testOneTable() throws Exception { + for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { + Database db = open(testDB); + Table t1 = db.getTable("Table1"); + Table t2 = db.getTable("Table2"); + Table t3 = db.getTable("Table3"); + + List<Relationship> expected = new ArrayList<Relationship>(); + expected.addAll(db.getRelationships(t1, t2)); + expected.addAll(db.getRelationships(t2, t3)); + + assertSameRelationships(expected, db.getRelationships(t2), false); + + } + } + + public void testNoTables() throws Exception { + for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) { + Database db = open(testDB); + Table t1 = db.getTable("Table1"); + Table t2 = db.getTable("Table2"); + Table t3 = db.getTable("Table3"); + + List<Relationship> expected = new ArrayList<Relationship>(); + expected.addAll(db.getRelationships(t1, t2)); + expected.addAll(db.getRelationships(t2, t3)); + expected.addAll(db.getRelationships(t1, t3)); + + assertSameRelationships(expected, db.getRelationships(), false); + } + } + + private static void assertSameRelationships( + List<Relationship> expected, List<Relationship> found, boolean ordered) { assertEquals(expected.size(), found.size()); + if(!ordered) { + Collections.sort(expected, REL_COMP); + Collections.sort(found, REL_COMP); + } for(int i = 0; i < expected.size(); ++i) { Relationship eRel = expected.get(i); Relationship fRel = found.get(i); |