Skip to content

Commit c571530

Browse files
authored
Merge branch 'development' into wip-upgrade-apache-commons
2 parents ebaa2d7 + 72ed316 commit c571530

26 files changed

+221
-15
lines changed

.github/workflows/gradle.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
push:
88
branches: [ main, development ]
99
pull_request:
10-
branches: [ main ]
10+
branches: [ main, development ]
1111

1212
env:
1313
# JDK version used for building jar file
@@ -22,9 +22,9 @@ jobs:
2222
jdk: [ 17 ]
2323
steps:
2424
- name: Checkout repo
25-
uses: actions/checkout@v2
25+
uses: actions/checkout@v4
2626
- name: Set up OpenJDK version ...
27-
uses: actions/setup-java@v2
27+
uses: actions/setup-java@v4
2828
with:
2929
distribution: 'zulu'
3030
java-version: ${{ matrix.jdk }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ Now it should be possible to right click on the project and choose "Run as" -> "
3333

3434
## License
3535

36-
The WEB Server is licensed under the Apache License, Version 2.0.
36+
The WAP Server is licensed under the Apache License, Version 2.0.

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ dependencies {
9494

9595
implementation "org.apache.jena:jena-commonsrdf:4.10.0"
9696
implementation "org.apache.thrift:libthrift:0.18.1"
97+
9798
implementation "org.apache.commons:commons-rdf-jsonld-java:0.5.0"
9899
implementation "com.github.java-json-tools:json-schema-validator:2.2.8"
99100

@@ -116,6 +117,7 @@ dependencies {
116117
testImplementation "io.rest-assured:rest-assured"
117118
testImplementation "io.rest-assured:spring-mock-mvc"
118119
testImplementation "io.rest-assured:rest-assured"
120+
testImplementation "io.specto:hoverfly-java-junit5:0.17.1"
119121

120122
//Java 11 Support
121123
testImplementation "org.mockito:mockito-inline:4.10.0"

pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
<groupId>org.apache.jena</groupId>
110110
<artifactId>apache-jena-libs</artifactId>
111111
<type>pom</type>
112-
<version>3.7.0</version>
112+
<version>3.8.0</version>
113113
</dependency>
114114
<dependency>
115115
<groupId>org.thymeleaf</groupId>
@@ -133,13 +133,13 @@
133133
<dependency>
134134
<groupId>org.apache.jena</groupId>
135135
<artifactId>jena-fuseki</artifactId>
136-
<version>3.7.0</version>
136+
<version>3.8.0</version>
137137
<type>pom</type>
138138
</dependency>
139139
<dependency>
140140
<groupId>org.apache.jena</groupId>
141141
<artifactId>jena-fuseki-embedded</artifactId>
142-
<version>3.7.0</version>
142+
<version>3.8.0</version>
143143
</dependency>
144144
<dependency>
145145
<groupId>com.github.java-json-tools</groupId>
@@ -181,6 +181,13 @@
181181
<artifactId>spring-mock-mvc</artifactId>
182182
<scope>test</scope>
183183
</dependency>
184+
<!-- https://mvnrepository.com/artifact/io.specto/hoverfly-java-junit5 -->
185+
<dependency>
186+
<groupId>io.specto</groupId>
187+
<artifactId>hoverfly-java-junit5</artifactId>
188+
<version>0.17.1</version>
189+
<scope>test</scope>
190+
</dependency>
184191
<dependency>
185192
<groupId>org.apache.commons</groupId>
186193
<artifactId>commons-collections4</artifactId>

src/main/java/edu/kit/scc/dem/wapsrv/model/formats/JsonLdFormatter.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,10 @@ public String format(AnnotationList annoList) {
132132

133133
@Override
134134
public String format(FormattableObject obj) {
135-
// To be able to create correct JSON-LD, we cannot rely on the database output generated.
136-
// At least when using Jena, the actual state. This might change with different backends,
137-
// but not break the behavior. It might only not be necessary.
138-
final String nquadsString = obj.toString(Format.NQUADS);
135+
final String jsonldString = obj.toString(Format.JSON_LD);
139136
// Get the frame as JSON-LD string
140137
final String frameString = profileRegistry.getFrameString(obj.getType());
141-
final String jsonLdWithBlankNodeIds = applyProfiles(nquadsString, frameString);
138+
final String jsonLdWithBlankNodeIds = applyProfiles(jsonldString, frameString);
142139
// Details why this step is necessary is found within the method
143140
return removeBlankNodeIds(jsonLdWithBlankNodeIds);
144141
}
@@ -204,12 +201,12 @@ private String removeBlankNodeIds(String jsonLdWithBlankNodeIds) {
204201
private String applyProfiles(String jsonLd, String frameString) {
205202
try {
206203
final Object frameObject = frameString == null ? null : JsonUtils.fromString(frameString);
207-
Object jsonObject = JsonLdProcessor.fromRDF(jsonLd);
204+
Object jsonObject = JsonUtils.fromString(jsonLd);
208205
// Use precreated options with in memory profiles
209206
JsonLdOptions optionsWithContexts = profileRegistry.getJsonLdOptions();
210207
Map<String, Object> framed = null;
211208
if (frameObject != null) {
212-
final JsonLdOptions options = new JsonLdOptions();
209+
final JsonLdOptions options = profileRegistry.getJsonLdOptions();
213210
options.format = JsonLdConsts.APPLICATION_NQUADS;
214211
options.setCompactArrays(true);
215212
framed = JsonLdProcessor.frame(jsonObject, frameObject, options);

src/main/java/edu/kit/scc/dem/wapsrv/repository/jena/JenaRdfBackend.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.apache.jena.query.DatasetFactory;
1111
import org.apache.jena.riot.Lang;
1212
import org.apache.jena.riot.RDFDataMgr;
13+
import org.apache.jena.riot.RDFFormat;
1314
import org.apache.jena.riot.RiotException;
1415
import org.apache.jena.sys.JenaSystem;
1516
import org.slf4j.Logger;
@@ -69,6 +70,11 @@ public String getOutput(Dataset dataset, Format format) throws WapException {
6970
}
7071
Graph graph = JenaCommonsRDF.toJena(dataset.getGraph());
7172
StringWriter writer = new StringWriter();
73+
//Specifying format option to match behaviour of jsonld-java. Likely to break on dependency change / jena upgrade. See https://jena.apache.org/documentation/io/rdf-output.html#json-ld
74+
if(format == Format.JSON_LD) {
75+
RDFDataMgr.write(writer, graph, RDFFormat.JSONLD_EXPAND_PRETTY);
76+
return writer.toString();
77+
}
7278
RDFDataMgr.write(writer, graph, lang);
7379
// StringWriters do not have to be closed!
7480
return writer.toString();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"@context": "http://www.w3.org/ns/anno.jsonld",
3+
"type": "Annotation",
4+
"body": {
5+
"type": "TextualBody",
6+
"value": "{\"text\":\"Hello \\\"world\\\"!\"}",
7+
"purpose": "tagging"
8+
},
9+
"target": "http://example.com/page1"
10+
}

src/test/java/edu/kit/scc/dem/wapsrv/controller/AnnotationControllerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import static org.mockito.Mockito.when;
55
import java.util.Iterator;
66
import java.util.List;
7+
import io.specto.hoverfly.junit5.HoverflyExtension;
8+
import io.specto.hoverfly.junit5.api.HoverflySimulate;
79
import org.apache.commons.rdf.api.BlankNodeOrIRI;
810
import org.apache.commons.rdf.api.Dataset;
911
import org.apache.commons.rdf.api.IRI;
@@ -48,6 +50,8 @@
4850
@SpringBootTest(
4951
classes = {AnnotationController.class, WapServerConfig.class, JsonLdProfileRegistry.class, FormatRegistry.class,
5052
JsonLdFormatter.class, AnnotationServiceMock.class, TurtleFormatter.class, EtagFactory.class})
53+
@ExtendWith(HoverflyExtension.class)
54+
@HoverflySimulate(source = @HoverflySimulate.Source(value = "w3c_simulation.json", type = HoverflySimulate.SourceType.DEFAULT_PATH))
5155
@ActiveProfiles("test")
5256
class AnnotationControllerTest extends BasicWapControllerTest {
5357
@Autowired

src/test/java/edu/kit/scc/dem/wapsrv/controller/ContainerControllerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.List;
77
import java.util.Properties;
88
import java.util.Set;
9+
import io.specto.hoverfly.junit5.HoverflyExtension;
10+
import io.specto.hoverfly.junit5.api.HoverflySimulate;
911
import org.apache.commons.rdf.api.BlankNodeOrIRI;
1012
import org.apache.commons.rdf.api.Dataset;
1113
import org.apache.commons.rdf.api.IRI;
@@ -56,6 +58,8 @@
5658
@SpringBootTest(
5759
classes = {ContainerController.class, WapServerConfig.class, JsonLdProfileRegistry.class, FormatRegistry.class,
5860
JsonLdFormatter.class, ContainerServiceMock.class, TurtleFormatter.class, EtagFactory.class})
61+
@ExtendWith(HoverflyExtension.class)
62+
@HoverflySimulate(source = @HoverflySimulate.Source(value = "w3c_simulation.json", type = HoverflySimulate.SourceType.DEFAULT_PATH))
5963
@ActiveProfiles("test")
6064
class ContainerControllerTest extends BasicWapControllerTest {
6165
@Autowired

src/test/java/edu/kit/scc/dem/wapsrv/controller/PageControllerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static edu.kit.scc.dem.wapsrv.controller.ControllerTestHelper.checkException;
44
import static org.junit.jupiter.api.Assertions.*;
55
import static org.mockito.Mockito.when;
6+
import io.specto.hoverfly.junit5.HoverflyExtension;
7+
import io.specto.hoverfly.junit5.api.HoverflySimulate;
68
import org.apache.commons.rdf.api.Dataset;
79
import org.eclipse.jetty.http.HttpMethod;
810
import org.junit.jupiter.api.Test;
@@ -41,6 +43,8 @@
4143
@ExtendWith(SpringExtension.class)
4244
@SpringBootTest(classes = {PageController.class, WapServerConfig.class, JsonLdProfileRegistry.class,
4345
FormatRegistry.class, JsonLdFormatter.class, ContainerServiceMock.class, TurtleFormatter.class})
46+
@ExtendWith(HoverflyExtension.class)
47+
@HoverflySimulate(source = @HoverflySimulate.Source(value = "w3c_simulation.json", type = HoverflySimulate.SourceType.DEFAULT_PATH))
4448
@ActiveProfiles("test")
4549
class PageControllerTest extends BasicWapControllerTest {
4650
@Autowired

0 commit comments

Comments
 (0)