Skip to content

Commit a6dc0f9

Browse files
fduttonfdutton
and
fdutton
authored
Moves JSON Schema Test Suite to a separate test-resources folder (#697)
Co-authored-by: fdutton <fdutton@noreply>
1 parent 39e5529 commit a6dc0f9

File tree

226 files changed

+117
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+117
-223
lines changed

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
<include>**/*</include>
165165
</includes>
166166
</testResource>
167+
<testResource>
168+
<directory>${project.basedir}/src/test/suite</directory>
169+
</testResource>
167170
</testResources>
168171
<plugins>
169172
<plugin>

src/test/java/com/networknt/schema/AbstractJsonSchemaTestSuite.java

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@
1717
package com.networknt.schema;
1818

1919
import com.fasterxml.jackson.core.type.TypeReference;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
2021
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
2122

22-
import io.undertow.Undertow;
23-
import io.undertow.server.handlers.resource.FileResourceManager;
24-
2523
import static com.networknt.schema.SpecVersionDetector.detectOptionalVersion;
2624

2725
import com.networknt.schema.SpecVersion.VersionFlag;
28-
import org.junit.jupiter.api.AfterAll;
2926
import org.junit.jupiter.api.AssertionFailureBuilder;
30-
import org.junit.jupiter.api.BeforeAll;
3127
import org.junit.jupiter.api.DynamicNode;
3228
import org.opentest4j.AssertionFailedError;
3329

34-
import java.io.File;
3530
import java.io.FileInputStream;
3631
import java.io.IOException;
3732
import java.io.InputStream;
@@ -51,11 +46,10 @@
5146
import java.util.stream.Stream;
5247
import java.util.stream.StreamSupport;
5348

54-
import static io.undertow.Handlers.resource;
5549
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
5650
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
5751

58-
public abstract class AbstractJsonSchemaTestSuite extends BaseSuiteJsonSchemaTest {
52+
public abstract class AbstractJsonSchemaTestSuite extends HTTPServiceSupport {
5953
protected static final TypeReference<List<TestCase>> testCaseType = new TypeReference<List<TestCase>>() {};
6054
protected static final Map<String, VersionFlag> supportedVersions = new HashMap<>();
6155
static {
@@ -66,33 +60,7 @@ public abstract class AbstractJsonSchemaTestSuite extends BaseSuiteJsonSchemaTes
6660
supportedVersions.put("draft7", VersionFlag.V7);
6761
}
6862

69-
protected static Undertow server = null;
70-
71-
@BeforeAll
72-
public static void setUp() {
73-
if (server == null) {
74-
server = Undertow.builder()
75-
.addHttpListener(1234, "localhost")
76-
.setHandler(resource(new FileResourceManager(
77-
new File("./src/test/resources/remotes"), 100)))
78-
.build();
79-
server.start();
80-
}
81-
}
82-
83-
@AfterAll
84-
public static void tearDown() throws Exception {
85-
if (server != null) {
86-
try {
87-
Thread.sleep(100);
88-
} catch (InterruptedException ignored) {
89-
Thread.currentThread().interrupt();
90-
91-
}
92-
server.stop();
93-
server = null;
94-
}
95-
}
63+
protected ObjectMapper mapper = new ObjectMapper();
9664

9765
protected Stream<DynamicNode> createTests(VersionFlag defaultVersion, String basePath) {
9866
return findTestCases(basePath)

src/test/java/com/networknt/schema/BaseSuiteJsonSchemaTest.java renamed to src/test/java/com/networknt/schema/HTTPServiceSupport.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,54 @@
1717
package com.networknt.schema;
1818

1919
import io.undertow.Undertow;
20+
import io.undertow.server.handlers.PathHandler;
2021
import io.undertow.server.handlers.resource.FileResourceManager;
2122

22-
import com.fasterxml.jackson.databind.ObjectMapper;
23-
2423
import org.junit.jupiter.api.AfterAll;
2524
import org.junit.jupiter.api.AfterEach;
2625
import org.junit.jupiter.api.BeforeAll;
2726
import java.io.File;
28-
import static io.undertow.Handlers.resource;
27+
import static io.undertow.Handlers.*;
2928

30-
public abstract class BaseSuiteJsonSchemaTest {
29+
public abstract class HTTPServiceSupport {
3130

3231
protected static Undertow server = null;
3332

34-
protected ObjectMapper mapper = new ObjectMapper();
35-
3633
@BeforeAll
3734
public static void setUp() {
3835
if (server == null) {
36+
PathHandler pathHandler = path(resource(
37+
new FileResourceManager(
38+
new File("./src/test/suite/remotes"),
39+
100
40+
))
41+
);
42+
43+
pathHandler.addPrefixPath("folder", resource(
44+
new FileResourceManager(
45+
new File("./src/test/resources/remotes/folder"),
46+
100
47+
))
48+
);
49+
50+
pathHandler.addPrefixPath("id_schema", resource(
51+
new FileResourceManager(
52+
new File("./src/test/resources/remotes/id_schema"),
53+
100
54+
))
55+
);
56+
57+
pathHandler.addPrefixPath("self_ref", resource(
58+
new FileResourceManager(
59+
new File("./src/test/resources/remotes/self_ref"),
60+
100
61+
))
62+
);
63+
3964
server = Undertow.builder()
40-
.addHttpListener(1234, "localhost")
41-
.setHandler(resource(new FileResourceManager(
42-
new File("./src/test/resources/remotes"), 100)))
43-
.build();
65+
.addHttpListener(1234, "localhost")
66+
.setHandler(pathHandler)
67+
.build();
4468
server.start();
4569
}
4670
}
@@ -52,7 +76,6 @@ public static void tearDown() throws Exception {
5276
Thread.sleep(100);
5377
} catch (InterruptedException ignored) {
5478
Thread.currentThread().interrupt();
55-
5679
}
5780
server.stop();
5881
server = null;

src/test/java/com/networknt/schema/Issue425Test.java

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,20 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.databind.node.ArrayNode;
6-
import io.undertow.Undertow;
7-
import io.undertow.server.handlers.resource.FileResourceManager;
8-
import org.junit.jupiter.api.AfterAll;
9-
import org.junit.jupiter.api.BeforeAll;
106
import org.junit.jupiter.api.Test;
117

12-
import java.io.File;
138
import java.io.InputStream;
149
import java.net.URI;
1510
import java.util.ArrayList;
1611
import java.util.List;
1712

18-
import static io.undertow.Handlers.resource;
1913
import static org.junit.jupiter.api.Assertions.assertEquals;
2014
import static org.junit.jupiter.api.Assertions.assertFalse;
2115

22-
public class Issue425Test {
16+
public class Issue425Test extends HTTPServiceSupport {
2317
protected ObjectMapper mapper = new ObjectMapper();
2418
protected JsonSchemaFactory validatorFactory = JsonSchemaFactory
2519
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4)).objectMapper(mapper).build();
26-
protected static Undertow server = null;
27-
28-
public Issue425Test() {
29-
}
30-
31-
@BeforeAll
32-
public static void setUp() {
33-
if (server == null) {
34-
server = Undertow.builder()
35-
.addHttpListener(1234, "localhost")
36-
.setHandler(resource(new FileResourceManager(
37-
new File("./src/test/resources/remotes"), 100)))
38-
.build();
39-
server.start();
40-
}
41-
}
42-
43-
@AfterAll
44-
public static void tearDown() throws Exception {
45-
if (server != null) {
46-
try {
47-
Thread.sleep(100);
48-
} catch (InterruptedException ignored) {
49-
Thread.currentThread().interrupt();
50-
51-
}
52-
server.stop();
53-
}
54-
}
5520

5621
private void runTestFile(String testCaseFile) throws Exception {
5722
final URI testCaseFileUri = URI.create("classpath:" + testCaseFile);

src/test/java/com/networknt/schema/Issue428Test.java

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,20 @@
33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.databind.node.ArrayNode;
6-
import io.undertow.Undertow;
7-
import io.undertow.server.handlers.resource.FileResourceManager;
8-
import org.junit.jupiter.api.AfterAll;
9-
import org.junit.jupiter.api.BeforeAll;
106
import org.junit.jupiter.api.Test;
117

12-
import java.io.File;
138
import java.io.InputStream;
149
import java.net.URI;
1510
import java.util.ArrayList;
1611
import java.util.List;
1712

18-
import static io.undertow.Handlers.resource;
1913
import static org.junit.jupiter.api.Assertions.assertEquals;
2014
import static org.junit.jupiter.api.Assertions.assertFalse;
2115

22-
public class Issue428Test {
16+
public class Issue428Test extends HTTPServiceSupport {
2317
protected ObjectMapper mapper = new ObjectMapper();
2418
protected JsonSchemaFactory validatorFactory = JsonSchemaFactory
2519
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4)).objectMapper(mapper).build();
26-
protected static Undertow server = null;
27-
28-
public Issue428Test() {
29-
}
30-
31-
@BeforeAll
32-
public static void setUp() {
33-
if (server == null) {
34-
server = Undertow.builder()
35-
.addHttpListener(1234, "localhost")
36-
.setHandler(resource(new FileResourceManager(
37-
new File("./src/test/resources/remotes"), 100)))
38-
.build();
39-
server.start();
40-
}
41-
}
42-
43-
@AfterAll
44-
public static void tearDown() throws Exception {
45-
if (server != null) {
46-
try {
47-
Thread.sleep(100);
48-
} catch (InterruptedException ignored) {
49-
Thread.currentThread().interrupt();
50-
51-
}
52-
server.stop();
53-
}
54-
}
5520

5621
private void runTestFile(String testCaseFile) throws Exception {
5722
final URI testCaseFileUri = URI.create("classpath:" + testCaseFile);

src/test/java/com/networknt/schema/Issue619Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void uriThatPointsToSchemaWithIdThatHasDifferentUri_Ref() throws Exceptio
120120
JsonNode oneArray = getJsonNodeFromStringContent("[[1]]");
121121
JsonNode textArray = getJsonNodeFromStringContent("[[\"a\"]]");
122122

123-
JsonSchema schemaWithIdFromRef = factory.getSchema("{ \"$ref\": \"resource:draft4/refRemote.json#/3/schema\" }");
123+
JsonSchema schemaWithIdFromRef = factory.getSchema("{ \"$ref\": \"resource:tests/draft4/refRemote.json#/3/schema\" }");
124124
assertTrue(schemaWithIdFromRef.validate(oneArray).isEmpty());
125125
assertFalse(schemaWithIdFromRef.validate(textArray).isEmpty());
126126
});
@@ -132,7 +132,7 @@ public void uriThatPointsToSchemaWithIdThatHasDifferentUri_Uri() throws Exceptio
132132
JsonNode oneArray = getJsonNodeFromStringContent("[[1]]");
133133
JsonNode textArray = getJsonNodeFromStringContent("[[\"a\"]]");
134134

135-
JsonSchema schemaWithIdFromUri = factory.getSchema(new URI("resource:draft4/refRemote.json#/3/schema"));
135+
JsonSchema schemaWithIdFromUri = factory.getSchema(new URI("resource:tests/draft4/refRemote.json#/3/schema"));
136136
assertTrue(schemaWithIdFromUri.validate(oneArray).isEmpty());
137137
assertFalse(schemaWithIdFromUri.validate(textArray).isEmpty());
138138
});

0 commit comments

Comments
 (0)