Skip to content

Commit 12be013

Browse files
committed
the testrunner now works well (reproduces android compat problems)
1 parent d90469e commit 12be013

File tree

7 files changed

+63
-23
lines changed

7 files changed

+63
-23
lines changed

tests/vanilla/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
<artifactId>org.everit.json.schema</artifactId>
4040
<version>${project.version}</version>
4141
</dependency>
42+
<dependency>
43+
<groupId>commons-io</groupId>
44+
<artifactId>commons-io</artifactId>
45+
<version>2.6</version>
46+
</dependency>
4247
<dependency>
4348
<groupId>junit</groupId>
4449
<artifactId>junit</artifactId>
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package org.everit.json.schema;
22

3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
6+
import org.apache.commons.io.IOUtils;
37
import org.everit.json.schema.loader.SchemaLoader;
48
import org.json.JSONObject;
59
import org.json.JSONTokener;
610
import org.junit.Test;
711

812
public class EmptyObjectTest {
9-
@Test
10-
public void validateEmptyObject() {
1113

12-
JSONObject jsonSchema = new JSONObject(new JSONTokener(
13-
MetaSchemaTest.class
14-
.getResourceAsStream("/org/everit/json/schema/json-schema-draft-04.json")));
14+
@Test
15+
public void validateEmptyObject() throws IOException {
16+
JSONObject jsonSchema = new JSONObject(new JSONTokener(IOUtils.toString(
17+
new InputStreamReader(getClass().getResourceAsStream("/org/everit/json/schema/json-schema-draft-04.json")))));
1518

1619
JSONObject jsonSubject = new JSONObject("{\n" +
1720
" \"type\": \"object\",\n" +
@@ -21,4 +24,5 @@ public void validateEmptyObject() {
2124
Schema schema = SchemaLoader.load(jsonSchema);
2225
schema.validate(jsonSubject);
2326
}
27+
2428
}

tests/vanilla/src/main/java/org/everit/json/schema/InvalidObjectInArrayTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package org.everit.json.schema;
22

3+
import java.io.IOException;
4+
import java.io.UncheckedIOException;
5+
6+
import org.apache.commons.io.Charsets;
7+
import org.apache.commons.io.IOUtils;
38
import org.everit.json.schema.loader.SchemaLoader;
49
import org.json.JSONObject;
510
import org.json.JSONTokener;
@@ -9,8 +14,12 @@
914
public class InvalidObjectInArrayTest {
1015

1116
private JSONObject readObject(final String fileName) {
12-
return new JSONObject(new JSONTokener(getClass()
13-
.getResourceAsStream("/org/everit/json/schema/invalidobjectinarray/" + fileName)));
17+
try {
18+
return new JSONObject(new JSONTokener(IOUtils.toString(getClass()
19+
.getResourceAsStream("/org/everit/json/schema/invalidobjectinarray/" + fileName), Charsets.toCharset("UTF-8"))));
20+
} catch (IOException e) {
21+
throw new UncheckedIOException(e);
22+
}
1423
}
1524

1625
@Test

tests/vanilla/src/main/java/org/everit/json/schema/JettyWrapper.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
package org.everit.json.schema;
22

3+
import java.io.File;
4+
import java.net.URISyntaxException;
5+
36
import org.eclipse.jetty.server.Server;
47
import org.eclipse.jetty.servlet.ServletHandler;
58
import org.eclipse.jetty.servlet.ServletHolder;
69

7-
import java.io.File;
8-
910
/**
1011
* @author erosb
1112
*/
1213
class JettyWrapper {
1314

1415
private Server server;
1516

17+
private static File getDocumentRoot(String documentRootPath) throws URISyntaxException {
18+
try {
19+
return new File(JettyWrapper.class
20+
.getResource(documentRootPath).toURI());
21+
} catch (IllegalArgumentException e) {
22+
return new File(JettyWrapper.class.getResource(documentRootPath).toExternalForm());
23+
}
24+
}
25+
1626
JettyWrapper(String documentRootPath) throws Exception {
17-
this(new File(JettyWrapper.class
18-
.getResource(documentRootPath).toURI()));
27+
this(getDocumentRoot(documentRootPath));
1928
}
2029

2130
JettyWrapper(File documentRoot) {
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.everit.json.schema;
22

3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
6+
import org.apache.commons.io.IOUtils;
37
import org.everit.json.schema.loader.SchemaLoader;
48
import org.json.JSONObject;
59
import org.json.JSONTokener;
@@ -8,18 +12,15 @@
812
public class MetaSchemaTest {
913

1014
@Test
11-
public void validateMetaSchema() {
15+
public void validateMetaSchema() throws IOException {
1216

1317
JSONObject jsonSchema = new JSONObject(new JSONTokener(
14-
MetaSchemaTest.class
15-
.getResourceAsStream("/org/everit/json/schema/json-schema-draft-04.json")));
16-
17-
JSONObject jsonSubject = new JSONObject(new JSONTokener(
18-
MetaSchemaTest.class
19-
.getResourceAsStream("/org/everit/json/schema/json-schema-draft-04.json")));
18+
IOUtils.toString(
19+
new InputStreamReader(getClass().getResourceAsStream("/org/everit/json/schema/json-schema-draft-04.json")))
20+
));
2021

2122
Schema schema = SchemaLoader.load(jsonSchema);
22-
schema.validate(jsonSubject);
23+
schema.validate(jsonSchema);
2324
}
2425

2526
}

tests/vanilla/src/main/java/org/everit/json/schema/RelativeURITest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.everit.json.schema;
22

3+
import org.apache.commons.io.IOUtils;
34
import org.everit.json.schema.loader.SchemaLoader;
45
import org.json.JSONObject;
56
import org.json.JSONTokener;
@@ -9,14 +10,17 @@ public class RelativeURITest {
910

1011
@Test
1112
public void test() throws Exception {
13+
System.out.println(JettyWrapper.class
14+
.getResource("/org/everit/json/schema/relative-uri/").toExternalForm());
15+
1216
JettyWrapper jetty = new JettyWrapper("/org/everit/json/schema/relative-uri/");
1317
jetty.start();
1418
try {
1519
SchemaLoader.builder()
1620
.resolutionScope("http://localhost:1234/schema/")
1721
.schemaJson(
18-
new JSONObject(new JSONTokener(getClass().getResourceAsStream(
19-
"/org/everit/json/schema/relative-uri/schema/main.json"))))
22+
new JSONObject(new JSONTokener(IOUtils.toString(getClass().getResourceAsStream(
23+
"/org/everit/json/schema/relative-uri/schema/main.json")))))
2024
.build().load().build();
2125
} finally {
2226
jetty.stop();

tests/vanilla/src/main/java/org/everit/json/schema/TestCase.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package org.everit.json.schema;
22

3+
import java.io.IOException;
34
import java.io.InputStream;
5+
import java.io.InputStreamReader;
6+
import java.io.UncheckedIOException;
47
import java.util.ArrayList;
58
import java.util.List;
69
import java.util.Set;
710
import java.util.regex.Pattern;
811

12+
import org.apache.commons.io.IOUtils;
913
import org.everit.json.schema.loader.SchemaLoader;
1014
import org.json.JSONArray;
1115
import org.json.JSONException;
@@ -19,8 +23,12 @@
1923
*/
2024
public class TestCase {
2125

22-
private static JSONArray loadTests(final InputStream input) {
23-
return new JSONArray(new JSONTokener(input));
26+
private static JSONArray loadTests(InputStream input) {
27+
try {
28+
return new JSONArray(new JSONTokener(IOUtils.toString(new InputStreamReader(input))));
29+
} catch (IOException e) {
30+
throw new UncheckedIOException(e);
31+
}
2432
}
2533

2634
static List<Object[]> loadAsParamsFromPackage(String packageName) {

0 commit comments

Comments
 (0)