@Test void testMoreNodes() { assertThatThrownBy(() -> assertThatJson("{\"test1\":2, \"test2\":1}").node("test1").isEqualTo(2).node("test2").isEqualTo(2)) .hasMessage("JSON documents are different:\nDifferent value found in node \"test2\", expected: <2> but was: <1>.\n"); }
private void assertJsonResponseBody(String body) { assertThatJson(body).isEqualTo("{" + "\"bookingId\":\"1\"," + "\"origin\":\"London\"," + "\"destination\":\"Singapore\"," + "\"time\":\"2011-09-01T12:30\"," + "\"_links\":{\"self\":{\"href\":\"http://localhost/api/bookings/1\"}}" + "}"); } }
@Test void shouldBeAbleToSimulateABookingQuery() throws Exception { final Request request = new Request.Builder() .url("http://www.my-test.com/api/bookings/1") .header("Content-Type", "text/plain; charset=utf-8") .build(); final Response response = client.newCall(request).execute(); assertThat(response.code()).isEqualTo(200); String body = response.body().string(); assertThatJson(body).node("id").isEqualTo(1); }
@Test void shouldImportSimulationFromDefaultLocation() throws IOException { final Request request = new Request.Builder() .url("http://www.my-test.com/api/bookings/1") .header("Content-Type", "text/plain; charset=utf-8") .build(); final Response response = client.newCall(request).execute(); String body = response.body().string(); assertThatJson(body).node("bookingId").isEqualTo("\"1\""); }
@Test public void shouldBeAbleToGetABookingUsingHttps() { //Given hoverflyRule.simulate(classpath("test-service.json")); // When final ResponseEntity<String> getBookingResponse = restTemplate.getForEntity("https://www.my-test.com/api/bookings/1", String.class); // Then assertThat(getBookingResponse.getStatusCode()).isEqualTo(OK); assertThatJson(getBookingResponse.getBody()).isEqualTo("{" + "\"bookingId\":\"1\"," + "\"origin\":\"London\"," + "\"destination\":\"Singapore\"," + "\"time\":\"2011-09-01T12:30\"," + "\"_links\":{\"self\":{\"href\":\"http://localhost/api/bookings/1\"}}" + "}"); }
@Test public void shouldWorkWithJerseyClient() { // Given WebResource resource = jerseyClient.resource("https://www.my-test.com/api/bookings/1"); // When ClientResponse response = resource.get(ClientResponse.class); // Then assertThat(response.getStatus()).isEqualTo(OK.value()); assertThatJson(response.getEntity(String.class)).isEqualTo("{" + "\"bookingId\":\"1\"," + "\"origin\":\"London\"," + "\"destination\":\"Singapore\"," + "\"time\":\"2011-09-01T12:30\"," + "\"_links\":{\"self\":{\"href\":\"http://localhost/api/bookings/1\"}}" + "}"); }
@Test public void shouldBeAbleToQueryBookingsUsingHoverfly() { // When URI uri = UriComponentsBuilder.fromHttpUrl("http://www.other-anotherservice.com") .path("/api/bookings") .queryParam("class", "business", "premium") .queryParam("destination", "new york") .build() .toUri(); final ResponseEntity<String> getBookingResponse = restTemplate.getForEntity(uri, String.class); // Then assertThat(getBookingResponse.getStatusCode()).isEqualTo(OK); assertThatJson(getBookingResponse.getBody()).isEqualTo("{" + "\"bookingId\":\"2\"," + "\"origin\":\"London\"," + "\"destination\":\"New York\"," + "\"class\":\"BUSINESS\"," + "\"time\":\"2011-09-01T12:30\"," + "\"_links\":{\"self\":{\"href\":\"http://localhost/api/bookings/2\"}}" + "}"); }
@Test public void shouldSerializeToJson() throws JsonProcessingException { ObjectMapper objectMapper = getObjectMapper(); Tweet tweet = Tweet.builder() .author("@artem_zin") .content("Immutability for everybody!") .build(); assertThatJson(objectMapper.writeValueAsString(tweet)) .isEqualTo("{\"author\":\"@artem_zin\",\"content\":\"Immutability for everybody!\"}"); }
@Test public void shouldConvertToJsonWithoutMetadata() throws IOException { // given Topic topic = topic("group.topic").build(); AvroUser avroUser = new AvroUser("Bob", 18, "blue"); Message source = message() .withData(avroUser.asBytes()) .withSchema(new CompiledSchema<>(avroUser.getSchema(), SchemaVersion.valueOf(0))) .withExternalMetadata(of()) .build(); AvroToJsonMessageConverter converter = new AvroToJsonMessageConverter(); // when Message target = converter.convert(source, topic); // then assertThatJson(new String(target.getData())).isEqualTo("{\"name\": \"Bob\", \"age\": 18, \"favoriteColor\": \"blue\"}"); }