use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification in project rest-assured by rest-assured.
the class AutoSpringSecurityConfigurerITest method spring_security_configurer_is_automatically_applied_when_spring_security_test_is_in_classpath_when_using_a_specifications_applied_before_web_app_context_setup.
@Test
public void spring_security_configurer_is_automatically_applied_when_spring_security_test_is_in_classpath_when_using_a_specifications_applied_before_web_app_context_setup() {
MockMvcRequestSpecification specification = new MockMvcRequestSpecBuilder().setPostProcessors(httpBasic("username", "password")).build();
RestAssuredMockMvc.given().spec(specification).webAppContextSetup(context).param("name", "Johan").when().get("/secured/greeting").then().statusCode(200).body("content", equalTo("Hello, Johan!")).expect(authenticated().withUsername("username"));
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification in project rest-assured by rest-assured.
the class MockMvcSecurityITest method can_authenticate_using_post_processors_in_spec.
@Test
public void can_authenticate_using_post_processors_in_spec() throws Exception {
MockMvcRequestSpecification specification = new MockMvcRequestSpecBuilder().setPostProcessors(httpBasic("username", "password")).build();
RestAssuredMockMvc.given().mockMvc(mvc).spec(specification).param("name", "Johan").when().get("/secured/greeting").then().statusCode(200).body("content", equalTo("Hello, Johan!")).expect(authenticated().withUsername("username"));
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification in project rest-assured by rest-assured.
the class MockMvcSecurityITest method can_specify_authentication_request_post_processor_using_spec_builder.
@Test
public void can_specify_authentication_request_post_processor_using_spec_builder() throws Exception {
MockMvcRequestSpecification specification = new MockMvcRequestSpecBuilder().setAuth(RestAssuredMockMvc.with(httpBasic("username", "password"))).build();
RestAssuredMockMvc.given().mockMvc(mvc).spec(specification).param("name", "Johan").when().get("/secured/greeting").then().statusCode(200).body("content", equalTo("Hello, Johan!")).expect(authenticated().withUsername("username"));
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method authentication_is_not_overwritten_when_not_defined_in_specification.
@Test
public void authentication_is_not_overwritten_when_not_defined_in_specification() {
// Given
MockMvcAuthenticationScheme thisAuth = RestAssuredMockMvc.principal("this");
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().spec(new MockMvcRequestSpecBuilder().setAuth(thisAuth).build()).spec(specToMerge);
// Then
assertThat(((TestingAuthenticationToken) implOf(spec).getAuthentication()).getPrincipal()).isEqualTo("this");
Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method multi_parts_are_merged.
@Test
public void multi_parts_are_merged() {
// Given
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addMultiPart("param1", "value1").build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().multiPart("param2", "value2").spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getMultiParts()).hasSize(2);
}
Aggregations