File tree Expand file tree Collapse file tree 7 files changed +63
-23
lines changed
src/main/java/org/everit/json/schema Expand file tree Collapse file tree 7 files changed +63
-23
lines changed Original file line number Diff line number Diff line change 39
39
<artifactId >org.everit.json.schema</artifactId >
40
40
<version >${project.version} </version >
41
41
</dependency >
42
+ <dependency >
43
+ <groupId >commons-io</groupId >
44
+ <artifactId >commons-io</artifactId >
45
+ <version >2.6</version >
46
+ </dependency >
42
47
<dependency >
43
48
<groupId >junit</groupId >
44
49
<artifactId >junit</artifactId >
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema ;
2
2
3
+ import java .io .IOException ;
4
+ import java .io .InputStreamReader ;
5
+
6
+ import org .apache .commons .io .IOUtils ;
3
7
import org .everit .json .schema .loader .SchemaLoader ;
4
8
import org .json .JSONObject ;
5
9
import org .json .JSONTokener ;
6
10
import org .junit .Test ;
7
11
8
12
public class EmptyObjectTest {
9
- @ Test
10
- public void validateEmptyObject () {
11
13
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" )))));
15
18
16
19
JSONObject jsonSubject = new JSONObject ("{\n " +
17
20
" \" type\" : \" object\" ,\n " +
@@ -21,4 +24,5 @@ public void validateEmptyObject() {
21
24
Schema schema = SchemaLoader .load (jsonSchema );
22
25
schema .validate (jsonSubject );
23
26
}
27
+
24
28
}
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema ;
2
2
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 ;
3
8
import org .everit .json .schema .loader .SchemaLoader ;
4
9
import org .json .JSONObject ;
5
10
import org .json .JSONTokener ;
9
14
public class InvalidObjectInArrayTest {
10
15
11
16
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
+ }
14
23
}
15
24
16
25
@ Test
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema ;
2
2
3
+ import java .io .File ;
4
+ import java .net .URISyntaxException ;
5
+
3
6
import org .eclipse .jetty .server .Server ;
4
7
import org .eclipse .jetty .servlet .ServletHandler ;
5
8
import org .eclipse .jetty .servlet .ServletHolder ;
6
9
7
- import java .io .File ;
8
-
9
10
/**
10
11
* @author erosb
11
12
*/
12
13
class JettyWrapper {
13
14
14
15
private Server server ;
15
16
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
+
16
26
JettyWrapper (String documentRootPath ) throws Exception {
17
- this (new File (JettyWrapper .class
18
- .getResource (documentRootPath ).toURI ()));
27
+ this (getDocumentRoot (documentRootPath ));
19
28
}
20
29
21
30
JettyWrapper (File documentRoot ) {
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema ;
2
2
3
+ import java .io .IOException ;
4
+ import java .io .InputStreamReader ;
5
+
6
+ import org .apache .commons .io .IOUtils ;
3
7
import org .everit .json .schema .loader .SchemaLoader ;
4
8
import org .json .JSONObject ;
5
9
import org .json .JSONTokener ;
8
12
public class MetaSchemaTest {
9
13
10
14
@ Test
11
- public void validateMetaSchema () {
15
+ public void validateMetaSchema () throws IOException {
12
16
13
17
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
+ ));
20
21
21
22
Schema schema = SchemaLoader .load (jsonSchema );
22
- schema .validate (jsonSubject );
23
+ schema .validate (jsonSchema );
23
24
}
24
25
25
26
}
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema ;
2
2
3
+ import org .apache .commons .io .IOUtils ;
3
4
import org .everit .json .schema .loader .SchemaLoader ;
4
5
import org .json .JSONObject ;
5
6
import org .json .JSONTokener ;
@@ -9,14 +10,17 @@ public class RelativeURITest {
9
10
10
11
@ Test
11
12
public void test () throws Exception {
13
+ System .out .println (JettyWrapper .class
14
+ .getResource ("/org/everit/json/schema/relative-uri/" ).toExternalForm ());
15
+
12
16
JettyWrapper jetty = new JettyWrapper ("/org/everit/json/schema/relative-uri/" );
13
17
jetty .start ();
14
18
try {
15
19
SchemaLoader .builder ()
16
20
.resolutionScope ("http://localhost:1234/schema/" )
17
21
.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" )))))
20
24
.build ().load ().build ();
21
25
} finally {
22
26
jetty .stop ();
Original file line number Diff line number Diff line change 1
1
package org .everit .json .schema ;
2
2
3
+ import java .io .IOException ;
3
4
import java .io .InputStream ;
5
+ import java .io .InputStreamReader ;
6
+ import java .io .UncheckedIOException ;
4
7
import java .util .ArrayList ;
5
8
import java .util .List ;
6
9
import java .util .Set ;
7
10
import java .util .regex .Pattern ;
8
11
12
+ import org .apache .commons .io .IOUtils ;
9
13
import org .everit .json .schema .loader .SchemaLoader ;
10
14
import org .json .JSONArray ;
11
15
import org .json .JSONException ;
19
23
*/
20
24
public class TestCase {
21
25
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
+ }
24
32
}
25
33
26
34
static List <Object []> loadAsParamsFromPackage (String packageName ) {
You can’t perform that action at this time.
0 commit comments