use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder 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.MockMvcRequestSpecBuilder 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.MockMvcRequestSpecBuilder 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.MockMvcRequestSpecBuilder 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.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcStaticRequestAndResponseSpecTest method request_and_response_spec_can_be_defined_statically.
@Test
public void request_and_response_spec_can_be_defined_statically() {
RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().addQueryParam("name", "Johan").build();
RestAssuredMockMvc.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).expectBody("content", equalTo("Hello, Johan!")).build();
try {
// When
RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).when().get("/greeting").then().body("id", equalTo(1));
} finally {
RestAssuredMockMvc.reset();
}
}
Aggregations