-
Notifications
You must be signed in to change notification settings - Fork 2
/
JsonLdContextTest.java
52 lines (43 loc) · 2.25 KB
/
JsonLdContextTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cz.cvut.kbss.jsonld.serialization.context;
import cz.cvut.kbss.jsonld.environment.Vocabulary;
import cz.cvut.kbss.jsonld.environment.model.Person;
import cz.cvut.kbss.jsonld.serialization.JsonNodeFactory;
import cz.cvut.kbss.jsonld.serialization.model.CompositeNode;
import cz.cvut.kbss.jsonld.serialization.model.JsonNode;
import org.junit.jupiter.api.Test;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.*;
class JsonLdContextTest {
private final MappingJsonLdContext sut = new MappingJsonLdContext();
@Test
void registerTermMappingWithIriAddsTermMappingToLiteralJsonNode() throws Exception {
final String term = Person.getFirstNameField().getName();
sut.registerTermMapping(term, Vocabulary.FIRST_NAME);
assertTrue(sut.hasTermMapping(term));
final Optional<JsonNode> result = sut.getTermMapping(term);
assertTrue(result.isPresent());
assertEquals(result.get(), JsonNodeFactory.createLiteralNode(term, Vocabulary.FIRST_NAME));
}
@Test
void registerTermMappingWithIriTwiceDoesNotThrowException() throws Exception {
final String term = Person.getFirstNameField().getName();
sut.registerTermMapping(term, Vocabulary.FIRST_NAME);
assertDoesNotThrow(() -> sut.registerTermMapping(term, Vocabulary.FIRST_NAME));
}
@Test
void getContextNodeReturnsCompositeNodeWithRegisteredMappings() throws Exception {
final String firstName = Person.getFirstNameField().getName();
sut.registerTermMapping(firstName, Vocabulary.FIRST_NAME);
final String lastName = Person.getLastNameField().getName();
sut.registerTermMapping(lastName, Vocabulary.LAST_NAME);
final JsonNode result = sut.getContextNode();
assertThat(result, instanceOf(CompositeNode.class));
final CompositeNode<?> compositeResult = (CompositeNode<?>) result;
assertThat(compositeResult.getItems(),
hasItems(JsonNodeFactory.createLiteralNode(firstName, Vocabulary.FIRST_NAME),
JsonNodeFactory.createLiteralNode(lastName, Vocabulary.LAST_NAME)));
}
}