1515 */
1616package org .metafacture .json ;
1717
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+
1830import org .junit .After ;
1931import org .junit .Before ;
32+ import org .junit .Rule ;
2033import org .junit .Test ;
2134import org .metafacture .framework .MetafactureException ;
2235import org .metafacture .framework .ObjectReceiver ;
2538import org .mockito .Mockito ;
2639import org .mockito .MockitoAnnotations ;
2740
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+
2846/**
2947 * Tests for {@link JsonValidator}.
3048 *
@@ -46,15 +64,32 @@ public final class JsonValidatorTest {
4664 private ObjectReceiver <String > receiver ;
4765 private InOrder inOrder ;
4866
67+ @ Rule
68+ public WireMockRule wireMockRule = new WireMockRule (WireMockConfiguration .wireMockConfig ()
69+ .jettyAcceptors (Runtime .getRuntime ().availableProcessors ()).dynamicPort ());
70+
4971 @ Before
50- public void setup () {
72+ public void setup () throws IOException {
5173 MockitoAnnotations .initMocks (this );
74+ WireMock .stubFor (WireMock .request ("GET" , WireMock .urlEqualTo ("/schema" ))
75+ .willReturn (WireMock .ok ().withBody (readToString (getClass ().getResource (SCHEMA )))));
5276 validator = new JsonValidator (SCHEMA );
5377 validator .setSchemaRoot ("/schemas/" );
5478 validator .setReceiver (receiver );
5579 inOrder = Mockito .inOrder (receiver );
5680 }
5781
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+
5893 @ Test
5994 public void testShouldValidate () {
6095 validator .process (JSON_VALID );
0 commit comments