use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.
the class ContentTypeTest method adds_specific_charset_to_content_type_by_default.
@Test
public void adds_specific_charset_to_content_type_by_default() {
final AtomicReference<String> contentType = new AtomicReference<String>();
RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).config(RestAssuredMockMvc.config().encoderConfig(EncoderConfig.encoderConfig().defaultCharsetForContentType(StandardCharsets.UTF_16.toString(), ContentType.JSON))).contentType(ContentType.JSON).interceptor(new MockHttpServletRequestBuilderInterceptor() {
public void intercept(MockHttpServletRequestBuilder requestBuilder) {
MultiValueMap<String, Object> headers = Whitebox.getInternalState(requestBuilder, "headers");
contentType.set(String.valueOf(headers.getFirst("Content-Type")));
}
}).when().get("/greeting?name={name}", "Johan").then().statusCode(200);
assertThat(contentType.get()).isEqualTo("application/json;charset=" + StandardCharsets.UTF_16.toString());
assertThat(contentType.get()).doesNotContain(RestAssuredMockMvc.config().getEncoderConfig().defaultContentCharset());
}
use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.
the class ContentTypeTest method doesnt_add_default_charset_to_content_type_if_configured_not_to_do_so.
@Test
public void doesnt_add_default_charset_to_content_type_if_configured_not_to_do_so() {
final AtomicReference<String> contentType = new AtomicReference<String>();
RestAssuredMockMvc.given().config(RestAssuredMockMvc.config().encoderConfig(EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false))).standaloneSetup(new GreetingController()).contentType(ContentType.JSON).interceptor(new MockHttpServletRequestBuilderInterceptor() {
public void intercept(MockHttpServletRequestBuilder requestBuilder) {
MultiValueMap<String, Object> headers = Whitebox.getInternalState(requestBuilder, "headers");
contentType.set(String.valueOf(headers.getFirst("Content-Type")));
}
}).when().get("/greeting?name={name}", "Johan").then().statusCode(200);
assertThat(contentType.get()).isEqualTo("application/json");
}
use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.
the class ExtractTest method can_extract_spring_mvcs_response.
@Test
public void can_extract_spring_mvcs_response() {
MockHttpServletResponse response = RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).param("name", "Johan").when().get("/greeting").then().statusCode(200).body("id", equalTo(1)).extract().response().mockHttpServletResponse();
assertThat(response.getContentType()).contains("application/json");
}
use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.
the class GreetingControllerRestAssuredTest method param_with_int.
@Test
public void param_with_int() throws Exception {
MockMvc mockMvc = standaloneSetup(new GreetingController()).build();
RestAssuredMockMvc.given().mockMvc(mockMvc).param("name", 1).when().get("/greeting").then().body("id", equalTo(1)).body("content", equalTo("Hello, 1!"));
}
use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.
the class MockMvcStaticRequestAndResponseSpecTest method request_and_response_spec_can_be_defined_statically.
@Test
public void request_and_response_spec_can_be_defined_statically() {
RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().addQueryParam("name", "Johan").build();
RestAssuredMockMvc.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).expectBody("content", equalTo("Hello, Johan!")).build();
try {
// When
RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).when().get("/greeting").then().body("id", equalTo(1));
} finally {
RestAssuredMockMvc.reset();
}
}
Aggregations