use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.
the class ResponseITest method jsonPathWithConfigReturnedByResponseOverridesConfigurationFromRestAssured.
@Test
public void jsonPathWithConfigReturnedByResponseOverridesConfigurationFromRestAssured() throws Exception {
// When
final JsonPath jsonPath = given().config(RestAssuredConfig.newConfig().with().jsonConfig(jsonConfig().with().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL))).expect().statusCode(200).body("store.book.price.min()", is(new BigDecimal("8.95"))).when().get("/jsonStore").jsonPath(JsonPathConfig.jsonPathConfig().with().numberReturnType(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE));
// Then
assertThat(jsonPath.<Float>get("store.book.price.min()"), is(8.95f));
assertThat(jsonPath.<Float>get("store.book.price.max()"), is(22.99f));
}
use of io.restassured.path.json.JsonPath in project vertx-openshift-it by cescoffier.
the class ConfigurationIT method testRetrievingConfigByListeningToChange.
@Test
public void testRetrievingConfigByListeningToChange() throws InterruptedException {
// So event bus config store has some time to load
ensureThat("we can retrieve the application configuration", () -> await().atMost(2, TimeUnit.MINUTES).until(() -> get("/all").getBody().jsonPath().getString("eventBus") != null));
ensureThat("the configuration is the expected configuration\n", () -> {
final JsonPath response = get("/all").getBody().jsonPath();
softly.assertThat(response.getDouble("date")).isNotNull().isPositive();
softly.assertThat(response.getString("key")).isEqualTo("value");
softly.assertThat(response.getString("HOSTNAME")).startsWith("config-service");
softly.assertThat(response.getString("KUBERNETES_NAMESPACE")).isEqualToIgnoringCase(client.getNamespace());
softly.assertThat(response.getInt("'http.port'")).isNotNull().isNotNegative();
softly.assertThat(response.getString("propertiesExampleOption")).isEqualTo("A properties example option");
softly.assertThat(response.getString("jsonExampleOption")).isEqualTo("A JSON example option");
softly.assertThat(response.getString("toBeOverwritten")).isEqualTo("This is defined in YAML file.");
softly.assertThat(response.getString("'map.items'.mapItem1")).isEqualTo("Overwrites value in JSON config file");
softly.assertThat(response.getInt("'map.items'.mapItem2")).isEqualTo(0);
softly.assertThat(response.getString("httpConfigContent")).isEqualTo(HTTP_CONFIG_EXPECTED_STRING);
softly.assertThat(response.getString("dirConfigKey2")).isEqualTo("How to achieve perfection");
softly.assertThat(response.getString("eventBus")).isEqualTo(EVENT_BUS_EXPECTED_STRING);
});
}
use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.
the class GreetingControllerVanillaMockMvcTest method mock_mvc_example_for_post_greeting_controller.
@Test
public void mock_mvc_example_for_post_greeting_controller() throws Exception {
MockMvc mockMvc = standaloneSetup(new PostController()).setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
String contentAsString = mockMvc.perform(post("/greetingPost").param("name", "Johan").contentType(MediaType.APPLICATION_FORM_URLENCODED)).andReturn().getResponse().getContentAsString();
JsonPath jsonPath = new JsonPath(contentAsString);
assertThat(jsonPath.getInt("id"), equalTo(1));
assertThat(jsonPath.getString("content"), equalTo("Hello, Johan!"));
}
use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.
the class GreetingControllerVanillaMockMvcTest method mock_mvc_example_for_get_greeting_controller.
@Test
public void mock_mvc_example_for_get_greeting_controller() throws Exception {
MockMvc mockMvc = standaloneSetup(new GreetingController()).setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
String contentAsString = mockMvc.perform(get("/greeting?name={name}", "Johan").accept(APPLICATION_JSON)).andReturn().getResponse().getContentAsString();
JsonPath jsonPath = new JsonPath(contentAsString);
assertThat(jsonPath.getInt("id"), equalTo(1));
assertThat(jsonPath.getString("content"), equalTo("Hello, Johan!"));
}
use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.
the class MultiPartFileUploadITest method object_serialization_works.
@Test
public void object_serialization_works() throws IOException {
File file = folder.newFile("something");
IOUtils.write("Something3210", new FileOutputStream(file));
Greeting greeting = new Greeting();
greeting.setFirstName("John");
greeting.setLastName("Doe");
String content = RestAssuredMockMvc.given().multiPart("controlName1", file, "mime-type1").multiPart("controlName2", greeting, "application/json").when().post("/multiFileUpload").then().root("[%d]").body("size", withArgs(0), is(13)).body("name", withArgs(0), equalTo("controlName1")).body("originalName", withArgs(0), equalTo("something")).body("mimeType", withArgs(0), equalTo("mime-type1")).body("content", withArgs(0), equalTo("Something3210")).body("size", withArgs(1), greaterThan(10)).body("name", withArgs(1), equalTo("controlName2")).body("originalName", withArgs(1), equalTo("file")).body("mimeType", withArgs(1), equalTo("application/json")).body("content", withArgs(1), notNullValue()).extract().path("[1].content");
JsonPath jsonPath = new JsonPath(content);
assertThat(jsonPath.getString("firstName"), equalTo("John"));
assertThat(jsonPath.getString("lastName"), equalTo("Doe"));
}
Aggregations