use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method base_path_is_not_overwritten_when_not_defined_in_specification.
@Test
public void base_path_is_not_overwritten_when_not_defined_in_specification() {
// Given
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().body("body1").spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getBasePath()).isEqualTo(RestAssuredMockMvc.basePath);
Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class SecuredControllerTest method statically_defined_auth_has_precedence_over_statically_defined_request_spec.
@Test
public void statically_defined_auth_has_precedence_over_statically_defined_request_spec() {
RestAssuredMockMvc.authentication = RestAssuredMockMvc.principal(new User("authorized_user", "password", Collections.<GrantedAuthority>emptyList()));
RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().setAuth(RestAssuredMockMvc.authentication(new TestingAuthenticationToken("name", "pw"))).build();
try {
RestAssuredMockMvc.given().standaloneSetup(new SecuredController()).param("name", "Johan").when().get("/springSecurityGreeting").then().statusCode(200).body("content", equalTo("Hello, Johan!"));
} finally {
RestAssuredMockMvc.reset();
}
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class LoggingIfValidationFailsTest method logging_of_both_request_and_response_validation_works_when_test_fails_when_using_static_response_and_request_specs_declared_before_enable_logging.
@Test
public void logging_of_both_request_and_response_validation_works_when_test_fails_when_using_static_response_and_request_specs_declared_before_enable_logging() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssuredMockMvc.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).build();
RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().setConfig(config().logConfig(new LogConfig(captor, true))).addHeader("Api-Key", "1234").build();
RestAssuredMockMvc.enableLoggingOfRequestAndResponseIfValidationFails(HEADERS);
try {
given().standaloneSetup(new PostController()).param("name", "Johan").when().post("/greetingPost").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan2!"));
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), equalTo("Headers:\t\tApi-Key=1234\n\t\t\t\tContent-Type=application/x-www-form-urlencoded;charset=" + RestAssuredMockMvcConfig.config().getEncoderConfig().defaultContentCharset() + "\n\nContent-Type: application/json;charset=UTF-8\n"));
}
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method content_type_is_overwritten_when_defined_in_specification.
@Test
public void content_type_is_overwritten_when_defined_in_specification() {
// Given
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setContentType(ContentType.JSON).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().contentType(ContentType.XML).spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getRequestContentType()).isEqualTo(ContentType.JSON.toString());
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method authentication_is_overwritten_when_using_dsl_and_defined_in_specification.
@Test
public void authentication_is_overwritten_when_using_dsl_and_defined_in_specification() {
// Given
MockMvcAuthenticationScheme otherAuth = RestAssuredMockMvc.principal("other");
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setAuth(otherAuth).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().auth().principal("this").and().spec(specToMerge);
// Then
assertThat(((TestingAuthenticationToken) implOf(spec).getAuthentication()).getPrincipal()).isEqualTo("other");
}
Aggregations