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_charset_is_defined_explicitly.
@Test
public void doesnt_add_default_charset_to_content_type_if_charset_is_defined_explicitly() {
final AtomicReference<String> contentType = new AtomicReference<String>();
RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).contentType(ContentType.JSON.withCharset("UTF-16")).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=UTF-16");
}
use of io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationImpl method spec.
public MockMvcRequestSpecification spec(MockMvcRequestSpecification requestSpecificationToMerge) {
notNull(requestSpecificationToMerge, MockMvcRequestSpecification.class);
if (!(requestSpecificationToMerge instanceof MockMvcRequestSpecificationImpl)) {
throw new IllegalArgumentException("requestSpecificationToMerge must be an instance of " + MockMvcRequestSpecificationImpl.class.getName());
}
MockMvcRequestSpecificationImpl that = (MockMvcRequestSpecificationImpl) requestSpecificationToMerge;
Object otherRequestBody = that.getRequestBody();
if (otherRequestBody != null) {
this.requestBody = otherRequestBody;
}
if (isNotEmpty(that.getBasePath())) {
this.basePath = that.getBasePath();
}
MockMvcFactory otherMockMvcFactory = that.getMockMvcFactory();
if (otherMockMvcFactory != null && otherMockMvcFactory.isAssigned()) {
this.changeMockMvcFactoryTo(otherMockMvcFactory);
}
this.cookies(that.getCookies());
this.headers(that.getRequestHeaders());
mergeConfig(this, that);
MockHttpServletRequestBuilderInterceptor otherInterceptor = that.getInterceptor();
if (otherInterceptor != null) {
this.interceptor = otherInterceptor;
}
this.formParams(that.getFormParams());
this.queryParams(that.getQueryParams());
this.params(that.getParams());
this.attributes(that.getAttributes());
this.multiParts.addAll(that.getMultiParts());
this.resultHandlers.addAll(that.getResultHandlers());
this.requestPostProcessors.addAll(that.getRequestPostProcessors());
RequestLoggingFilter otherRequestLoggingFilter = that.getRequestLoggingFilter();
if (otherRequestLoggingFilter != null) {
this.requestLoggingFilter = otherRequestLoggingFilter;
}
Object otherAuth = that.getAuthentication();
if (otherAuth != null) {
this.authentication = otherAuth;
}
AsyncConfig otherAsyncConfig = that.getAsyncConfig();
if (otherAsyncConfig != null) {
this.asyncConfig = otherAsyncConfig;
}
return this;
}
Aggregations