-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test for composite key reference/refback
- Loading branch information
1 parent
01a3e4c
commit 719beff
Showing
1 changed file
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ class ColumnTypeRdfMapperTest { | |
static final String TEST_TABLE = "TestTable"; | ||
static final String REF_TABLE = "TestRefTable"; | ||
static final String REFBACK_TABLE = "TestRefBackTable"; | ||
static final String COMPOSITE_REF_TABLE = "TestCompositeRefTable"; | ||
static final String COMPOSITE_REFBACK_TABLE = "TestCompositeRefbackTable"; | ||
static final String ONT_TABLE = "TestOntology"; | ||
|
||
static final String BASE_URL = "http://localhost:8080/"; | ||
|
@@ -38,6 +40,10 @@ class ColumnTypeRdfMapperTest { | |
static final File TEST_FILE = | ||
new File(classLoader.getResource("testfiles/molgenis.png").getFile()); | ||
|
||
static final String COLUMN_COMPOSITE_REF = "composite_ref"; | ||
static final String COLUMN_COMPOSITE_REF_ARRAY = "composite_ref_array"; | ||
static final String COLUMN_COMPOSITE_REFBACK = "composite_refback"; | ||
|
||
static Database database; | ||
static Schema allColumnTypes; | ||
static Row firstRow; | ||
|
@@ -50,33 +56,49 @@ public static void setup() { | |
|
||
// Generates a column for each ColumnType. | ||
// Filters out REFBACK so that it can be added as last step when all REFs are generated. | ||
Column[] columns = | ||
List<Column> columnList = | ||
Arrays.stream(ColumnType.values()) | ||
.map((value) -> column(value.name(), value)) | ||
.filter((column -> !column.getColumnType().equals(ColumnType.REFBACK))) | ||
.toArray(Column[]::new); | ||
.collect(Collectors.toList()); | ||
|
||
// Defines column-specific settings. | ||
for (Column column : columns) { | ||
for (Column column : columnList) { | ||
switch (column.getColumnType()) { | ||
case STRING -> column.setPkey(); | ||
case REF, REF_ARRAY -> column.setRefTable(REF_TABLE); | ||
case ONTOLOGY, ONTOLOGY_ARRAY -> column.setRefTable(ONT_TABLE); | ||
} | ||
} | ||
|
||
// Add extra custom columns for additional tests. | ||
columnList.add(column(COLUMN_COMPOSITE_REF, ColumnType.REF).setRefTable(COMPOSITE_REF_TABLE)); | ||
columnList.add( | ||
column(COLUMN_COMPOSITE_REF_ARRAY, ColumnType.REF).setRefTable(COMPOSITE_REF_TABLE)); | ||
|
||
// Creates tables. | ||
allColumnTypes.create( | ||
// Ontology table | ||
table(ONT_TABLE).setTableType(TableType.ONTOLOGIES), | ||
// Table to ref towards | ||
table(REF_TABLE, column("id", ColumnType.STRING).setPkey()), | ||
// Table to test on | ||
table(TEST_TABLE, columns), | ||
table(TEST_TABLE, columnList.toArray(Column[]::new)), | ||
// Table to get refbacks from | ||
table( | ||
REFBACK_TABLE, | ||
column("id", ColumnType.STRING).setPkey(), | ||
column("ref", ColumnType.REF).setRefTable(TEST_TABLE)), | ||
// Table containing composite primary key to ref towards | ||
table( | ||
COMPOSITE_REF_TABLE, | ||
column("ids", ColumnType.STRING).setPkey(), | ||
column("idi", ColumnType.INT).setPkey()), | ||
// Table containing composite primary key to get refback from | ||
table( | ||
COMPOSITE_REFBACK_TABLE, | ||
column("id1", ColumnType.STRING).setPkey(), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
svandenhoek
Author
Contributor
|
||
column("id2", ColumnType.STRING).setPkey(), | ||
column("ref", ColumnType.REF).setRefTable(TEST_TABLE))); | ||
|
||
// Adds REFBACK. | ||
|
@@ -86,6 +108,9 @@ public static void setup() { | |
.add( | ||
column(ColumnType.REFBACK.name(), ColumnType.REFBACK) | ||
.setRefTable(REFBACK_TABLE) | ||
.setRefBack("ref"), | ||
column(COLUMN_COMPOSITE_REFBACK, ColumnType.REFBACK) | ||
.setRefTable(COMPOSITE_REFBACK_TABLE) | ||
.setRefBack("ref")); | ||
|
||
// Inserts table data | ||
|
@@ -98,6 +123,11 @@ public static void setup() { | |
|
||
allColumnTypes.getTable(REF_TABLE).insert(row("id", "1"), row("id", "2"), row("id", "3")); | ||
|
||
allColumnTypes | ||
.getTable(COMPOSITE_REF_TABLE) | ||
.insert( | ||
row("ids", "a", "idi", "1"), row("ids", "b", "idi", "2"), row("ids", "c", "idi", "3")); | ||
|
||
allColumnTypes | ||
.getTable(TEST_TABLE) | ||
.insert( | ||
|
@@ -171,9 +201,25 @@ public static void setup() { | |
ColumnType.HYPERLINK.name(), | ||
"https://molgenis.org", | ||
ColumnType.HYPERLINK_ARRAY.name(), | ||
"https://molgenis.org, https://github.com/molgenis")); | ||
"https://molgenis.org, https://github.com/molgenis", | ||
// Extra columns for composite key testing | ||
// -- no manual entry: COLUMN_COMPOSITE_REFBACK | ||
COLUMN_COMPOSITE_REF + ".ids", | ||
"a", | ||
COLUMN_COMPOSITE_REF + ".idi", | ||
"1", | ||
COLUMN_COMPOSITE_REF_ARRAY + ".id1", | ||
"b,c", | ||
COLUMN_COMPOSITE_REF_ARRAY + ".id2", | ||
"2,3"), | ||
row(ColumnType.STRING.name(), "secondRowKey")); | ||
|
||
allColumnTypes.getTable(REFBACK_TABLE).insert(row("id", "1", "ref", "lonelyString")); | ||
allColumnTypes | ||
.getTable(COMPOSITE_REFBACK_TABLE) | ||
.insert( | ||
row("id1", "a", "id2", "b", "ref", "lonelyString"), | ||
row("id1", "c", "id2", "d", "ref", "secondRowKey")); | ||
|
||
// Use query to explicitly retrieve all rows as the following would exclude REFBACK values: | ||
// allColumnTypes.getTable(TEST_TABLE).retrieveRows() | ||
|
@@ -251,7 +297,11 @@ void validateValueTypes() { | |
() -> Assertions.assertTrue(retrieveFirstValue(ColumnType.AUTO_ID.name()).isLiteral()), | ||
() -> Assertions.assertTrue(retrieveFirstValue(ColumnType.ONTOLOGY.name()).isIRI()), | ||
() -> Assertions.assertTrue(retrieveFirstValue(ColumnType.EMAIL.name()).isIRI()), | ||
() -> Assertions.assertTrue(retrieveFirstValue(ColumnType.HYPERLINK.name()).isIRI())); | ||
() -> Assertions.assertTrue(retrieveFirstValue(ColumnType.HYPERLINK.name()).isIRI()), | ||
|
||
// Composite keys | ||
() -> Assertions.assertTrue(retrieveFirstValue(COMPOSITE_REF_TABLE).isIRI()), | ||
() -> Assertions.assertTrue(retrieveFirstValue(COMPOSITE_REFBACK_TABLE).isIRI())); | ||
} | ||
|
||
@Test | ||
|
@@ -395,13 +445,13 @@ void validateValuesRetrieval() { | |
.matches("[0-9a-zA-Z]+")), | ||
() -> | ||
Assertions.assertEquals( | ||
Set.of(Values.iri(rdfApiUrlPrefix + ONT_TABLE + "?name=aa")), | ||
Set.of(Values.iri(RDF_API_URL_PREFIX + ONT_TABLE + "?name=aa")), | ||
retrieveValues(ColumnType.ONTOLOGY.name())), | ||
() -> | ||
Assertions.assertEquals( | ||
Set.of( | ||
Values.iri(rdfApiUrlPrefix + ONT_TABLE + "?name=bb"), | ||
Values.iri(rdfApiUrlPrefix + ONT_TABLE + "?name=cc")), | ||
Values.iri(RDF_API_URL_PREFIX + ONT_TABLE + "?name=bb"), | ||
Values.iri(RDF_API_URL_PREFIX + ONT_TABLE + "?name=cc")), | ||
retrieveValues(ColumnType.ONTOLOGY_ARRAY.name())), | ||
() -> | ||
Assertions.assertEquals( | ||
|
@@ -420,6 +470,23 @@ void validateValuesRetrieval() { | |
Assertions.assertEquals( | ||
Set.of( | ||
Values.iri("https://molgenis.org"), Values.iri("https://github.com/molgenis")), | ||
retrieveValues(ColumnType.HYPERLINK_ARRAY.name()))); | ||
retrieveValues(ColumnType.HYPERLINK_ARRAY.name())), | ||
// Composite reference / refback | ||
() -> | ||
Assertions.assertEquals( | ||
Set.of(Values.iri(RDF_API_URL_PREFIX + COMPOSITE_REF_TABLE + "?ids=a&idi=1")), | ||
retrieveValues(COLUMN_COMPOSITE_REF)), | ||
() -> | ||
Assertions.assertEquals( | ||
Set.of( | ||
Values.iri(RDF_API_URL_PREFIX + COMPOSITE_REF_TABLE + "?ids=b&idi=2"), | ||
Values.iri(RDF_API_URL_PREFIX + COMPOSITE_REF_TABLE + "?ids=c&idi=3")), | ||
retrieveValues(COLUMN_COMPOSITE_REF_ARRAY)), | ||
() -> | ||
Assertions.assertEquals( | ||
Set.of( | ||
Values.iri(RDF_API_URL_PREFIX + COMPOSITE_REFBACK_TABLE + "?id1=a&id2=b"), | ||
Values.iri(RDF_API_URL_PREFIX + COMPOSITE_REFBACK_TABLE + "?id1=c&id2=d")), | ||
retrieveValues(COLUMN_COMPOSITE_REFBACK))); | ||
} | ||
} |
There are also refbacks and refs and ref_arrays to tables with composite keys with 2+ columns as composite key. Should we also include tests to cover those? or is this covered?