Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -63,6 +63,17 @@
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<!-- Shade Google Guava into jsonld-java to avoid downstream incompatibilities
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.github.jsonldjava.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.net.URL;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.github.jsonldjava.utils.JsonUtils;

public class ArrayContextToRDFTest {
class ArrayContextToRDFTest {
@Test
public void toRdfWithNamespace() throws Exception {
void toRdfWithNamespace() throws Exception {

final URL contextUrl = getClass().getResource("/custom/contexttest-0001.jsonld");
assertNotNull(contextUrl);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.github.jsonldjava.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.github.jsonldjava.utils.JsonUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;


public class ContextCompactionTest {
Expand Down Expand Up @@ -39,9 +39,9 @@ public void testCompaction() {
newContexts.add("http://schema.org/");
final Map<String, Object> compacted = JsonLdProcessor.compact(json, newContexts, options);

assertTrue("Compaction removed the context", compacted.containsKey("@context"));
assertFalse("Compaction of context should be a string, not a list",
compacted.get("@context") instanceof List);
assertTrue(compacted.containsKey("@context"), "Compaction removed the context");
assertFalse(compacted.get("@context") instanceof List,
"Compaction of context should be a string, not a list");
}

@Test
Expand All @@ -56,9 +56,9 @@ public void testCompactionSingleRemoteContext() throws Exception {

final Map<String, Object> compacted = JsonLdProcessor.compact(json, ctx, options);

assertEquals("Wrong returned context", "http://schema.org/", compacted.get("@context"));
assertEquals("Wrong type", "Person", compacted.get("type"));
assertEquals("Wrong number of Json entries",2, compacted.size());
assertEquals("http://schema.org/", compacted.get("@context"),"Wrong returned context");
assertEquals( "Person", compacted.get("type"),"Wrong type");
assertEquals(2, compacted.size(),"Wrong number of Json entries");
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.github.jsonldjava.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.github.jsonldjava.utils.JsonUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ContextFlatteningTest {

Expand Down Expand Up @@ -40,9 +40,9 @@ public void testFlatenning() throws Exception {

final Map<String, Object> flattened = ((Map<String, Object>)JsonLdProcessor.flatten(json, flatten, options));

assertTrue("Flattening removed the context", flattened.containsKey("@context"));
assertFalse("Flattening of context should be a string, not a list",
flattened.get("@context") instanceof List);
assertTrue(flattened.containsKey("@context"),"Flattening removed the context");
assertFalse(flattened.get("@context") instanceof List,
"Flattening of context should be a string, not a list");
}

@Test
Expand All @@ -59,8 +59,8 @@ public void testFlatteningRemoteContext() throws Exception {

final Map<String, Object> flattened = ((Map<String, Object>)JsonLdProcessor.flatten(json, flatten, options));

assertEquals("Wrong returned context", "http://schema.org/", flattened.get("@context"));
assertEquals("Wrong number of Json entries",2, flattened.size());
assertEquals("http://schema.org/", flattened.get("@context"),"Wrong returned context");
assertEquals(2, flattened.size(),"Wrong number of Json entries");
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.github.jsonldjava.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.github.jsonldjava.utils.JsonUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ContextFramingTest {

Expand Down Expand Up @@ -40,9 +40,9 @@ public void testFraming() throws Exception {

final Map<String, Object> framed = JsonLdProcessor.frame(json, frame, options);

assertTrue("Framing removed the context", framed.containsKey("@context"));
assertFalse("Framing of context should be a string, not a list",
framed.get("@context") instanceof List);
assertTrue(framed.containsKey("@context"), "Framing removed the context");
assertFalse(framed.get("@context") instanceof List,
"Framing of context should be a string, not a list");
}

@Test
Expand All @@ -58,10 +58,10 @@ public void testFramingRemoteContext() throws Exception {

final Map<String, Object> framed = JsonLdProcessor.frame(json, frame, options);

assertEquals("Wrong returned context", "http://schema.org/", framed.get("@context"));
assertEquals("Wrong id", "schema:myid", framed.get("id"));
assertEquals("Wrong type", "Person", framed.get("type"));
assertEquals("Wrong number of Json entries",3, framed.size());
assertEquals("http://schema.org/", framed.get("@context"),"Wrong returned context");
assertEquals("schema:myid", framed.get("id"),"Wrong id");
assertEquals( "Person", framed.get("type"),"Wrong type");
assertEquals(3, framed.size(),"Wrong number of Json entries");
}

}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package com.github.jsonldjava.core;

import com.github.jsonldjava.utils.JsonUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;


public class ContextRecursionTest {
class ContextRecursionTest {

@BeforeClass
public static void setup() {
@BeforeAll
static void setup() {
System.setProperty(DocumentLoader.DISALLOW_REMOTE_CONTEXT_LOADING, "true");
}

@AfterClass
public static void tearDown() {
@AfterAll
static void tearDown() {
System.setProperty(DocumentLoader.DISALLOW_REMOTE_CONTEXT_LOADING, "false");
}

@Test
public void testIssue302_allowedRecursion() throws IOException {
void issue302_allowedRecursion() throws IOException {

final String contextB = "{\"@context\": [\"http://localhost/d\", {\"b\": \"http://localhost/b\"} ] }";
final String contextC = "{\"@context\": [\"http://localhost/d\", {\"c\": \"http://localhost/c\"} ] }";
Expand All @@ -48,7 +48,7 @@ public void testIssue302_allowedRecursion() throws IOException {
}

@Test
public void testCyclicRecursion() throws IOException {
void cyclicRecursion() throws IOException {

final String contextC = "{\"@context\": [\"http://localhost/d\", {\"c\": \"http://localhost/c\"} ] }";
final String contextD = "{\"@context\": [\"http://localhost/e\", {\"d\": \"http://localhost/d\"} ] }";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.github.jsonldjava.core;

import com.github.jsonldjava.utils.JsonUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ContextSerializationTest {
class ContextSerializationTest {

@Test
// Added in order to have some coverage on the serialize method since is not used anywhere.
public void serializeTest() throws IOException {
final Map<String, Object> json = (Map<String, Object>)JsonUtils
@Test
void serializeTest() throws IOException {
final Map<String, Object> json = (Map<String, Object>) JsonUtils
.fromInputStream(getClass().getResourceAsStream("/custom/contexttest-0005.jsonld"));

final Map<String, Object> contextValue = (Map<String, Object>)json.get(JsonLdConsts.CONTEXT);
final Map<String, Object> serializedContext = new Context().parse(contextValue).serialize();

assertEquals("Wrong serialized context", json, serializedContext);
assertEquals(json, serializedContext, "Wrong serialized context");
}
}
61 changes: 36 additions & 25 deletions core/src/test/java/com/github/jsonldjava/core/ContextTest.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,54 @@
package com.github.jsonldjava.core;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.google.common.collect.ImmutableMap;

public class ContextTest {
class ContextTest {

@Test
public void testRemoveBase() {
void removeBase() {
// TODO: test if Context.removeBase actually works
}

// See https://github.com/jsonld-java/jsonld-java/issues/141

@Test(expected = JsonLdError.class)
public void testIssue141_errorOnEmptyKey_compact() {
JsonLdProcessor.compact(ImmutableMap.of(), ImmutableMap.of("", "http://example.com"),
new JsonLdOptions());
@Test
void issue141_errorOnEmptyKey_compact() {
assertThrows(JsonLdError.class, () -> {
JsonLdProcessor.compact(ImmutableMap.of(), ImmutableMap.of("", "http://example.com"),
new JsonLdOptions());
});
}

@Test(expected = JsonLdError.class)
public void testIssue141_errorOnEmptyKey_expand() {
JsonLdProcessor.expand(
ImmutableMap.of("@context", ImmutableMap.of("", "http://example.com")),
new JsonLdOptions());
@Test
void issue141_errorOnEmptyKey_expand() {
assertThrows(JsonLdError.class, () -> {
JsonLdProcessor.expand(
ImmutableMap.of("@context", ImmutableMap.of("", "http://example.com")),
new JsonLdOptions());
});
}

@Test(expected = JsonLdError.class)
public void testIssue141_errorOnEmptyKey_newContext1() {
new Context(ImmutableMap.of("", "http://example.com"));
@Test
void issue141_errorOnEmptyKey_newContext1() {
assertThrows(JsonLdError.class, () -> {
new Context(ImmutableMap.of("", "http://example.com"));
});
}

@Test(expected = JsonLdError.class)
public void testIssue141_errorOnEmptyKey_newContext2() {
new Context(ImmutableMap.of("", "http://example.com"), new JsonLdOptions());
@Test
void issue141_errorOnEmptyKey_newContext2() {
assertThrows(JsonLdError.class, () -> {
new Context(ImmutableMap.of("", "http://example.com"), new JsonLdOptions());
});
}

/*
Expand All @@ -52,14 +61,16 @@ public void testIssue141_errorOnEmptyKey_newContext2() {

// See https://github.com/jsonld-java/jsonld-java/issues/248

@Test(expected = IllegalArgumentException.class)
public void testIssue248_uriExpected() {
JsonLdProcessor
.expand(ImmutableMap.of("roleName", "Production Company", "@context", schemaOrg));
@Test
void issue248_uriExpected() {
assertThrows(IllegalArgumentException.class, () -> {
JsonLdProcessor
.expand(ImmutableMap.of("roleName", "Production Company", "@context", schemaOrg));
});
}

@Test
public void testIssue248_forceValue() {
void issue248_forceValue() {
final List<?> value = Arrays.asList(ImmutableMap.of("@value", "Production Company"));
final Map<String, Object> input = ImmutableMap.of("roleName", value, "@context", schemaOrg);
final Object output = JsonLdProcessor.expand(input);
Expand All @@ -68,7 +79,7 @@ public void testIssue248_forceValue() {
}

@Test
public void testIssue248_overrideContext() {
void issue248_overrideContext() {
final List<?> context = Arrays.asList(schemaOrg,
ImmutableMap.of("roleName", ImmutableMap.of("@id", "http://schema.org/roleName")));
final Map<String, Object> input = ImmutableMap.of("roleName", "Production Company",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.jsonldjava.core;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class DecimalLiteralCanonicalTest {

Expand Down
Loading