15
15
*/
16
16
package org .metafacture .json ;
17
17
18
+ import static org .hamcrest .CoreMatchers .both ;
19
+ import static org .hamcrest .CoreMatchers .containsString ;
20
+ import static org .junit .Assert .assertThat ;
21
+
22
+ import java .io .BufferedReader ;
23
+ import java .io .IOException ;
24
+ import java .io .InputStreamReader ;
25
+ import java .net .MalformedURLException ;
26
+ import java .net .URL ;
27
+ import java .nio .charset .StandardCharsets ;
28
+ import java .util .stream .Collectors ;
29
+
18
30
import org .junit .After ;
19
31
import org .junit .Before ;
32
+ import org .junit .Rule ;
20
33
import org .junit .Test ;
21
34
import org .metafacture .framework .MetafactureException ;
22
35
import org .metafacture .framework .ObjectReceiver ;
25
38
import org .mockito .Mockito ;
26
39
import org .mockito .MockitoAnnotations ;
27
40
41
+ import com .github .tomakehurst .wiremock .client .WireMock ;
42
+ import com .github .tomakehurst .wiremock .core .WireMockConfiguration ;
43
+ import com .github .tomakehurst .wiremock .junit .WireMockRule ;
44
+
45
+
28
46
/**
29
47
* Tests for {@link JsonValidator}.
30
48
*
@@ -46,15 +64,32 @@ public final class JsonValidatorTest {
46
64
private ObjectReceiver <String > receiver ;
47
65
private InOrder inOrder ;
48
66
67
+ @ Rule
68
+ public WireMockRule wireMockRule = new WireMockRule (WireMockConfiguration .wireMockConfig ()
69
+ .jettyAcceptors (Runtime .getRuntime ().availableProcessors ()).dynamicPort ());
70
+
49
71
@ Before
50
- public void setup () {
72
+ public void setup () throws IOException {
51
73
MockitoAnnotations .initMocks (this );
74
+ WireMock .stubFor (WireMock .request ("GET" , WireMock .urlEqualTo ("/schema" ))
75
+ .willReturn (WireMock .ok ().withBody (readToString (getClass ().getResource (SCHEMA )))));
52
76
validator = new JsonValidator (SCHEMA );
53
77
validator .setSchemaRoot ("/schemas/" );
54
78
validator .setReceiver (receiver );
55
79
inOrder = Mockito .inOrder (receiver );
56
80
}
57
81
82
+ private String readToString (final URL url ) throws IOException {
83
+ return new BufferedReader (new InputStreamReader (url .openStream (), StandardCharsets .UTF_8 ))
84
+ .lines ().collect (Collectors .joining ("\n " ));
85
+ }
86
+
87
+ @ Test
88
+ public void callWireMockSchema () throws MalformedURLException , IOException {
89
+ final String schemaContent = readToString (new URL (wireMockRule .baseUrl () + "/schema" ));
90
+ assertThat (schemaContent , both (containsString ("$schema" )).and (containsString ("$ref" )));
91
+ }
92
+
58
93
@ Test
59
94
public void testShouldValidate () {
60
95
validator .process (JSON_VALID );
0 commit comments