Search in sources :

Example 6 with JsonPath

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));
}
Also used : JsonPath(io.restassured.path.json.JsonPath) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 7 with JsonPath

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);
    });
}
Also used : JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 8 with JsonPath

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!"));
}
Also used : PostController(io.restassured.module.mockmvc.http.PostController) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) JsonPath(io.restassured.path.json.JsonPath) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 9 with JsonPath

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!"));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) GreetingController(io.restassured.module.mockmvc.http.GreetingController) JsonPath(io.restassured.path.json.JsonPath) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 10 with JsonPath

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"));
}
Also used : Greeting(io.restassured.examples.springmvc.support.Greeting) FileOutputStream(java.io.FileOutputStream) JsonPath(io.restassured.path.json.JsonPath) File(java.io.File) Test(org.junit.Test)

Aggregations

JsonPath (io.restassured.path.json.JsonPath)14 Test (org.junit.Test)12 BigDecimal (java.math.BigDecimal)2 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 Route (io.fabric8.openshift.api.model.Route)1 ResponseBuilder (io.restassured.builder.ResponseBuilder)1 Greeting (io.restassured.examples.springmvc.support.Greeting)1 GreetingController (io.restassured.module.mockmvc.http.GreetingController)1 PostController (io.restassured.module.mockmvc.http.PostController)1 Response (io.restassured.response.Response)1 JsonObject (io.vertx.core.json.JsonObject)1 Transport (io.vertx.ext.web.handler.sockjs.Transport)1 Kube.urlForRoute (io.vertx.it.openshift.utils.Kube.urlForRoute)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1