use of io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor 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.intercept.MockHttpServletRequestBuilderInterceptor 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.intercept.MockHttpServletRequestBuilderInterceptor in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method interception_is_overwritten_when_defined_in_specification.
@Test
public void interception_is_overwritten_when_defined_in_specification() {
// Given
MockHttpServletRequestBuilderInterceptor otherInterceptor = new MockHttpServletRequestBuilderInterceptor() {
public void intercept(MockHttpServletRequestBuilder requestBuilder) {
}
};
MockHttpServletRequestBuilderInterceptor thisInterceptor = new MockHttpServletRequestBuilderInterceptor() {
public void intercept(MockHttpServletRequestBuilder requestBuilder) {
}
};
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setMockHttpServletRequestBuilderInterceptor(otherInterceptor).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().interceptor(thisInterceptor).spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getInterceptor()).isEqualTo(otherInterceptor);
}
use of io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method interception_is_not_overwritten_when_not_defined_in_specification.
@Test
public void interception_is_not_overwritten_when_not_defined_in_specification() {
// Given
MockHttpServletRequestBuilderInterceptor thisInterceptor = new MockHttpServletRequestBuilderInterceptor() {
public void intercept(MockHttpServletRequestBuilder requestBuilder) {
}
};
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().interceptor(thisInterceptor).spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getInterceptor()).isEqualTo(thisInterceptor);
Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
use of io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor in project rest-assured by rest-assured.
the class ContentTypeTest method adds_default_charset_to_content_type_by_default.
@Test
public void adds_default_charset_to_content_type_by_default() {
final AtomicReference<String> contentType = new AtomicReference<String>();
RestAssuredMockMvc.given().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;charset=" + RestAssuredMockMvc.config().getEncoderConfig().defaultContentCharset());
}
Aggregations