protected void verifyRequestsMatches(HttpRequest[] httpRequests, HttpRequest... httpRequestMatchers) { if (httpRequests.length != httpRequestMatchers.length) { throw new AssertionError("Number of request matchers does not match number of requests, expected:<" + httpRequestMatchers.length + "> but was:<" + httpRequests.length + ">"); } else { for (int i = 0; i < httpRequestMatchers.length; i++) { if (!new HttpRequestMatcher(httpRequestMatchers[i], new MockServerLogger(this.getClass())).matches(null, httpRequests[i])) { throw new AssertionError("Request does not match request matcher, expected:<" + httpRequestMatchers[i] + "> but was:<" + httpRequests[i] + ">"); } } } }
private static String toJson(Object object) { String json = ""; try { json = ObjectMapperFactory.createObjectMapper().writeValueAsString(object); } catch (JsonProcessingException e) { new MockServerLogger(JsonBody.class).error("error mapping object for json body to JSON", e); } return json; }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (shouldNotIgnoreException(cause)) { new MockServerLogger(this.getClass()).error("Exception caught by " + server.getClass() + " handler -> closing pipeline " + ctx.channel(), cause); } closeOnFlush(ctx.channel()); } }
private static SchemaFactory buildSchemaFactory() { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "all"); schemaFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "all"); } catch (Exception e) { new MockServerLogger(XmlSchemaValidator.class).error("exception configuring schema factory", e); } return schemaFactory; }
Expectation[] recordedExpectations = new ExpectationSerializer(new MockServerLogger()).deserializeArray( mockServerClient.retrieveRecordedExpectations(request().withPath(calculatePath("some_path_one")), Format.JSON) ); assertThat(recordedExpectations[0].getHttpResponse().getBodyAsString(), is("some_body_one")); recordedExpectations = new ExpectationSerializer(new MockServerLogger()).deserializeArray( mockServerClient.retrieveRecordedExpectations(request(), Format.JSON) ); assertThat(recordedExpectations[1].getHttpResponse().getBodyAsString(), is("some_body_three")); recordedExpectations = new ExpectationSerializer(new MockServerLogger()).deserializeArray( mockServerClient.retrieveRecordedExpectations(null, Format.JSON) );
new HttpRequestSerializer(new MockServerLogger()).deserializeArray(mockServerClient.retrieveRecordedRequests(request().withPath(calculatePath("some_path.*")), Format.JSON)), request(calculatePath("some_path_one")), request(calculatePath("some_path_three")) new HttpRequestSerializer(new MockServerLogger()).deserializeArray(mockServerClient.retrieveRecordedRequests(request(), Format.JSON)), request(calculatePath("some_path_one")), request(calculatePath("not_found")), new HttpRequestSerializer(new MockServerLogger()).deserializeArray(mockServerClient.retrieveRecordedRequests(null, Format.JSON)), request(calculatePath("some_path_one")), request(calculatePath("not_found")),
is(new ExpectationSerializer(new MockServerLogger()).serialize(Arrays.asList( new Expectation(request().withPath(calculatePath("some_path.*")), exactly(4), TimeToLive.unlimited()) .thenRespond(response().withBody("some_body")), is(new ExpectationSerializer(new MockServerLogger()).serialize(Arrays.asList( new Expectation(request().withPath(calculatePath("some_path.*")), exactly(4), TimeToLive.unlimited()) .thenRespond(response().withBody("some_body")), is(new ExpectationSerializer(new MockServerLogger()).serialize(Arrays.asList( new Expectation(request().withPath(calculatePath("some_path.*")), exactly(4), TimeToLive.unlimited()) .thenRespond(response().withBody("some_body")),
.withBody("" + "[" + new ExpectationSerializer(new MockServerLogger()) .serialize( new Expectation(request("/path_one"), once(), TimeToLive.unlimited()) .thenRespond(response().withBody("some_body_one")) ) + "," + new ExpectationSerializer(new MockServerLogger()) .serialize( new Expectation(request("/path_two"), once(), TimeToLive.unlimited()) .thenRespond(response().withBody("some_body_two")) ) + "," + new ExpectationSerializer(new MockServerLogger()) .serialize( new Expectation(request("/path_three"), once(), TimeToLive.unlimited())
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (shouldNotIgnoreException(cause)) { new MockServerLogger(this.getClass()).error("Exception caught by " + server.getClass() + " handler -> closing pipeline " + ctx.channel(), cause); } closeOnFlush(ctx.channel()); } }
private static String toJson(Object object) { String json = ""; try { json = ObjectMapperFactory.createObjectMapper().writeValueAsString(object); } catch (JsonProcessingException e) { new MockServerLogger(JsonBody.class).error("error mapping object for json body to JSON", e); } return json; }