Skip to content

Commit 1bff853

Browse files
committed
Fixing loose ends after rebase
1 parent 3bf81cd commit 1bff853

File tree

4 files changed

+17
-63
lines changed

4 files changed

+17
-63
lines changed

src/main/java/fr/inria/corese/w3c/junit/dynamic/executor/impl/RdfNegativeTestExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void execute(W3cTestCase testCase) throws Exception {
4141
// Extract needed information from test case
4242
String testName = testCase.getName();
4343
URI actionFileUri = testCase.getActionFileUri();
44+
String actionBaseUriString = RDFTestUtils.getBaseUri(actionFileUri).toString();
4445

4546
try {
4647
// Load the action file
@@ -57,6 +58,7 @@ public void execute(W3cTestCase testCase) throws Exception {
5758
if(testCase.getProperty("baseUri", String.class) != null) {
5859
String baseUri = testCase.getProperty("baseUri", String.class);
5960
optionBuilder.base(baseUri);
61+
actionBaseUriString = baseUri;
6062
}
6163
if(testCase.getProperty("specVersion", String.class) != null) {
6264
String specVersion = testCase.getProperty("specVersion", String.class);
@@ -81,7 +83,7 @@ public void execute(W3cTestCase testCase) throws Exception {
8183

8284
// Attempt to parse the input file
8385
try (FileReader reader = new FileReader(actionFilePath)) {
84-
actionParser.parse(reader);
86+
actionParser.parse(reader, actionBaseUriString);
8587
}
8688

8789
// If we reach here, parsing succeeded when it should have failed

src/main/java/fr/inria/corese/w3c/junit/dynamic/executor/impl/RdfPositiveEvaluationTestExecutor.java

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.io.FileReader;
44
import java.net.URI;
55

6+
import com.apicatalog.jsonld.JsonLdVersion;
7+
import fr.inria.corese.core.next.impl.io.option.TitaniumJSONLDProcessorOption;
68
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
810

@@ -11,16 +13,9 @@
1113
import fr.inria.corese.core.next.api.io.parser.RDFParser;
1214
import fr.inria.corese.core.next.impl.exception.ParsingErrorException;
1315
import fr.inria.corese.w3c.junit.dynamic.executor.TestExecutor;
14-
import fr.inria.corese.w3c.junit.dynamic.model.TestType;
1516
import fr.inria.corese.w3c.junit.dynamic.model.W3cTestCase;
1617
import fr.inria.corese.w3c.junit.dynamic.utils.ModelIsomorphism;
1718
import fr.inria.corese.w3c.junit.dynamic.utils.RDFTestUtils;
18-
import fr.inria.corese.w3c.junit.dynamic.utils.RdfFormatDetector;
19-
import org.slf4j.Logger;
20-
import org.slf4j.LoggerFactory;
21-
22-
import java.io.FileReader;
23-
import java.net.URI;
2419

2520
/**
2621
* Specialized executor for positive RDF evaluation tests.
@@ -38,9 +33,6 @@ public class RdfPositiveEvaluationTestExecutor implements TestExecutor {
3833

3934
private static final Logger logger = LoggerFactory.getLogger(RdfPositiveEvaluationTestExecutor.class);
4035

41-
private static final String RDF11 = "rdf11/";
42-
private static final String URL_RDF11 = "https://w3c.github.io/rdf-tests/rdf/";
43-
4436
/**
4537
* Default constructor
4638
*/
@@ -57,6 +49,7 @@ public void execute(W3cTestCase testCase) throws Exception {
5749
try {
5850
// Load the action file
5951
String actionFilePath = RDFTestUtils.loadFile(actionFileUri);
52+
String actionBaseUriString = RDFTestUtils.getBaseUri(actionFileUri).toString();
6053

6154
// Get format and create parser
6255
Model actionModel = RDFTestUtils.createModel();
@@ -65,6 +58,7 @@ public void execute(W3cTestCase testCase) throws Exception {
6558

6659
// Load the result file
6760
String resultFilePath = RDFTestUtils.loadFile(resultFileUri);
61+
String resultBaseUriString = RDFTestUtils.getBaseUri(resultFileUri).toString();
6862

6963
// Detect format of result file and create parser
7064
Model resultModel = RDFTestUtils.createModel();
@@ -77,6 +71,8 @@ public void execute(W3cTestCase testCase) throws Exception {
7771
if(testCase.getProperty("baseUri", String.class) != null) {
7872
String baseUri = testCase.getProperty("baseUri", String.class);
7973
optionBuilder.base(baseUri);
74+
actionBaseUriString = baseUri;
75+
resultBaseUriString = baseUri;
8076
}
8177
if(testCase.getProperty("specVersion", String.class) != null) {
8278
String specVersion = testCase.getProperty("specVersion", String.class);
@@ -107,12 +103,12 @@ public void execute(W3cTestCase testCase) throws Exception {
107103

108104
// Parse the input file
109105
try (FileReader reader = new FileReader(actionFilePath)) {
110-
actionParser.parse(reader);
106+
actionParser.parse(reader, actionBaseUriString);
111107
}
112108

113109
// Parse the result file
114110
try (FileReader reader = new FileReader(resultFilePath)) {
115-
resultParser.parse(reader, baseUriForResult);
111+
resultParser.parse(reader, resultBaseUriString);
116112
}
117113

118114
// Test //
@@ -132,24 +128,4 @@ public void execute(W3cTestCase testCase) throws Exception {
132128
throw new AssertionError(msg);
133129
}
134130
}
135-
136-
/**
137-
* Converts a local file URI to the corresponding W3C test URI.
138-
*
139-
* @param localFileUri local file URI
140-
* @return W3C canonical URI
141-
*/
142-
private String convertToW3cUri(URI localFileUri) {
143-
String path = localFileUri.toString();
144-
145-
int rdf11Index = path.indexOf(RDF11);
146-
147-
if (rdf11Index != -1) {
148-
String relativePath = path.substring(rdf11Index);
149-
return URL_RDF11 + relativePath;
150-
}
151-
152-
logger.warn("Could not convert local URI to W3C URI: {}", path);
153-
return path;
154-
}
155131
}

src/main/java/fr/inria/corese/w3c/junit/dynamic/executor/impl/RdfPositiveSyntaxTestExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void execute(W3cTestCase testCase) throws Exception {
4141
// Extract all needed information from test case
4242
String testName = testCase.getName();
4343
URI actionFileUri = testCase.getActionFileUri();
44+
String actionBaseUriString = RDFTestUtils.getBaseUri(actionFileUri).toString();
4445

4546
try {
4647
// Load the action file
@@ -57,6 +58,7 @@ public void execute(W3cTestCase testCase) throws Exception {
5758
if(testCase.getProperty("baseUri", String.class) != null) {
5859
String baseUri = testCase.getProperty("baseUri", String.class);
5960
optionBuilder.base(baseUri);
61+
actionBaseUriString = baseUri;
6062
}
6163
if(testCase.getProperty("specVersion", String.class) != null) {
6264
String specVersion = testCase.getProperty("specVersion", String.class);
@@ -81,7 +83,7 @@ public void execute(W3cTestCase testCase) throws Exception {
8183

8284
// Parse the input file
8385
try (FileReader reader = new FileReader(actionFilePath)) {
84-
actionParser.parse(reader);
86+
actionParser.parse(reader, actionBaseUriString);
8587
}
8688

8789
// If we reach here, parsing succeeded as expected for positive syntax test

src/main/java/fr/inria/corese/w3c/junit/dynamic/utils/RDFTestUtils.java

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package fr.inria.corese.w3c.junit.dynamic.utils;
22

33
import java.net.URI;
4+
import java.net.URISyntaxException;
5+
import java.util.Optional;
46

57
import fr.inria.corese.core.next.api.Model;
68
import fr.inria.corese.core.next.api.ValueFactory;
@@ -91,34 +93,6 @@ public static String formatErrorMessage(String message, String testName,
9193
return sb.toString();
9294
}
9395

94-
95-
/**
96-
* Attempt to retrieve the base URI of a given URI object such as "https://docs.gradle.org/8.10.1/userguide/java_testing.html#sec:test_execution" will return "https://docs.gradle.org/8.10.1/userguide/"
97-
*
98-
* @param uri Full uri
99-
* @return The truncated URI
100-
*/
101-
public static URI getBaseUri(URI uri) {
102-
103-
StringBuilder sb = new StringBuilder();
104-
sb.append(uri.getScheme());
105-
sb.append("://");
106-
if (uri.getHost() != null) {
107-
sb.append(uri.getHost());
108-
}
109-
// Get path up to the last '/'
110-
String path = uri.getPath();
111-
if (path != null && !path.endsWith("/")) {
112-
int lastSlash = path.lastIndexOf('/');
113-
if (lastSlash >= 0) {
114-
path = path.substring(0, lastSlash + 1);
115-
} else {
116-
path = "/";
117-
}
118-
}
119-
sb.append(path);
120-
return URI.create(sb.toString());
121-
}
12296
/**
12397
* Try to guess the RDFFormat from a file name
12498
* @param filePath A URL or local path to an RDF file
@@ -182,7 +156,7 @@ public static String getFileExtension(String filename) {
182156
* @throws URISyntaxException if the string is not a standard URI
183157
*/
184158
public static String getBaseUri(String uriString) throws URISyntaxException {
185-
return getBaseUri(new URI(uriString));
159+
return getBaseUri(new URI(uriString)).toString();
186160
}
187161

188162
/**

0 commit comments

Comments
 (0)