Skip to content

Commit c8d89de

Browse files
committed
test: corner cases for entity<->context validation
1 parent 19d878e commit c8d89de

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/main/java/edu/kit/datamanager/ro_crate/context/RoCrateMetadataContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public boolean checkEntity(AbstractEntity entity) {
122122
if (s.equals("@id")) {
123123
// @id will refer to the value of the id of the node
124124
// so we need to extract this value
125-
s = node.path(s).asText(s);
125+
s = entity.getId();
126126
}
127127
if (s.equals("@json")) {
128128
// A linked data builtin type, which is fine.

src/test/java/edu/kit/datamanager/ro_crate/context/ContextTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.databind.node.ObjectNode;
77

88
import edu.kit.datamanager.ro_crate.HelpFunctions;
9+
import edu.kit.datamanager.ro_crate.entities.AbstractEntity;
910
import edu.kit.datamanager.ro_crate.entities.contextual.ContextualEntity;
1011
import edu.kit.datamanager.ro_crate.entities.data.DataEntity;
1112
import edu.kit.datamanager.ro_crate.objectmapper.MyObjectMapper;
@@ -190,4 +191,37 @@ void creationFromUrlAndPairsTest() {
190191
// house is in the context
191192
assertTrue(newContext.checkEntity(data));
192193
}
194+
195+
@Test
196+
void testIdType() {
197+
AbstractEntity validEntity = new DataEntity.DataEntityBuilder()
198+
.setId("Airline") // this is defined in the context!
199+
.addType("@id") // this is a JSON-LD feature to refer to the ID ("Airline") as a type
200+
.addType("@json") // this is a JSON-LD built-in type
201+
.build();
202+
assertTrue(this.context.checkEntity(validEntity));
203+
204+
AbstractEntity invalidEntity = new DataEntity.DataEntityBuilder()
205+
.setId("Something which is definitely not in the context")
206+
.addType("@id")
207+
.build();
208+
assertFalse(this.context.checkEntity(invalidEntity));
209+
}
210+
211+
@Test
212+
void testJsonType() {
213+
AbstractEntity validEntity = new DataEntity.DataEntityBuilder()
214+
.addType("@json") // this is a JSON-LD built-in type
215+
.build();
216+
assertTrue(this.context.checkEntity(validEntity));
217+
}
218+
219+
@Test
220+
void testAbsoluteUrlType() {
221+
AbstractEntity validEntity = new DataEntity.DataEntityBuilder()
222+
.addType("http://example.org/Person") // this is not in the context!
223+
.addProperty("http://example.org/Thing", "Some thing")
224+
.build();
225+
assertTrue(this.context.checkEntity(validEntity));
226+
}
193227
}

0 commit comments

Comments
 (0)