Skip to content

Commit

Permalink
[Enhancement #43] Do not replicate inherited term mapping when overri…
Browse files Browse the repository at this point in the history
…ding terms in embedded context.
  • Loading branch information
ledsoft committed Feb 8, 2023
1 parent 7d4717a commit a224325
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ boolean canRegisterTermMapping(String term, JsonNode mappedNode) {
void registerTermMapping(String term, JsonNode mappedNode) {
Objects.requireNonNull(term);
Objects.requireNonNull(mappedNode);
if (parentContext.hasTermMapping(term, mappedNode)) {
// Already mapped in parent
return;
}
if (!isRoot() && !parentContext.hasTermMapping(term)) {
parentContext.registerTermMapping(term, mappedNode);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import cz.cvut.kbss.jsonld.serialization.JsonNodeFactory;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.*;

class EmbeddedTermMappingHolderTest {
Expand All @@ -21,4 +24,13 @@ void registerTermMappingThrowsAmbiguousTermMappingExceptionWhenRootHolderAlready
JsonNodeFactory.createStringLiteralNode(term, DC.Terms.TITLE)));
}

@Test
void registerTermMappingDoesNothingWhenParentContextAlreadyHasEquivalentMappingForSpecifiedTerm() {
final EmbeddedTermMappingHolder child = new EmbeddedTermMappingHolder(sut);
final String term = "name";
sut.registerTermMapping(term, JsonNodeFactory.createStringLiteralNode(term, RDFS.LABEL));
child.registerTermMapping(term, JsonNodeFactory.createStringLiteralNode(term, RDFS.LABEL));
assertThat(child.getMapping(), not(hasKey(term)));
assertTrue(child.hasTermMapping(term));
}
}

0 comments on commit a224325

Please sign in to comment.