Search in sources :

Example 56 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 57 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 58 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 59 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)

Example 60 with JsonPath

use of io.restassured.path.json.JsonPath in project rest-assured by rest-assured.

the class SimplePathITest method simpleJsonValidationWithJsonPath.

@Test
public void simpleJsonValidationWithJsonPath() throws Exception {
    final String body = get("/greetJSON?firstName=John&lastName=Doe").asString();
    final JsonPath json = new JsonPath(body).setRoot("greeting");
    final String firstName = json.getString("firstName");
    final String lastName = json.getString("lastName");
    assertThat(firstName, equalTo("John"));
    assertThat(lastName, equalTo("Doe"));
}
Also used : JsonPath(io.restassured.path.json.JsonPath) Test(org.junit.Test)

Aggregations

JsonPath (io.restassured.path.json.JsonPath)117 Test (org.junit.Test)101 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)82 Response (io.restassured.response.Response)9 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)8 Date (java.util.Date)6 Property (com.b2international.snowowl.fhir.core.model.codesystem.Property)4 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)4 SubProperty (com.b2international.snowowl.fhir.core.model.dt.SubProperty)4 CodeSystem (com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem)3 Uri (com.b2international.snowowl.fhir.core.model.dt.Uri)3 HashMap (java.util.HashMap)3 TranslateResult (com.b2international.snowowl.fhir.core.model.conceptmap.TranslateResult)2 BigDecimal (java.math.BigDecimal)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 OperationOutcomeCode (com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode)1