use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method mock_mvc_instance_is_overwritten_when_defined_in_specification.
@Test
public void mock_mvc_instance_is_overwritten_when_defined_in_specification() {
// Given
MockMvc otherMockMvcInstance = MockMvcBuilders.standaloneSetup(new PostController()).build();
MockMvc thisMockMvcInstance = MockMvcBuilders.standaloneSetup(new GreetingController()).build();
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setMockMvc(otherMockMvcInstance).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().mockMvc(thisMockMvcInstance).spec(specToMerge);
// Then
assertThat(Whitebox.getInternalState(implOf(spec).getMockMvcFactory(), "mockMvc")).isSameAs(otherMockMvcInstance);
}
use of io.restassured.module.mockmvc.http.GreetingController in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method mock_mvc_factory_is_not_overwritten_when_not_defined_in_specification.
@Test
public void mock_mvc_factory_is_not_overwritten_when_not_defined_in_specification() {
// Given
MockMvc mockMvcInstance = MockMvcBuilders.standaloneSetup(new GreetingController()).build();
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().mockMvc(mockMvcInstance).spec(specToMerge);
// Then
assertThat(Whitebox.getInternalState(implOf(spec).getMockMvcFactory(), "mockMvc")).isSameAs(mockMvcInstance);
Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
use of io.restassured.module.mockmvc.http.GreetingController 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());
}
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_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.http.GreetingController in project rest-assured by rest-assured.
the class ExtractTest method can_extract_rest_assureds_mock_mvc_response.
@Test
public void can_extract_rest_assureds_mock_mvc_response() {
MockMvcResponse response = RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).param("name", "Johan").when().get("/greeting").then().statusCode(200).body("id", equalTo(1)).extract().response();
assertThat(response.path("content")).isEqualTo("Hello, Johan!");
}
Aggregations