Search in sources :

Example 36 with MockMvcRequestSpecBuilder

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_after_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_after_web_app_context_setup() {
    MockMvcRequestSpecification specification = new MockMvcRequestSpecBuilder().setPostProcessors(httpBasic("username", "password")).build();
    RestAssuredMockMvc.given().webAppContextSetup(context).spec(specification).param("name", "Johan").when().get("/secured/greeting").then().statusCode(200).body("content", equalTo("Hello, Johan!")).expect(authenticated().withUsername("username"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Aggregations

MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)36 Test (org.junit.Test)36 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)31 GreetingController (io.restassured.module.mockmvc.http.GreetingController)7 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)4 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)4 RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)3 MockMvcAuthenticationScheme (io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme)3 PrintStream (java.io.PrintStream)3 StringWriter (java.io.StringWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 Cookie (io.restassured.http.Cookie)2 Header (io.restassured.http.Header)2 PostController (io.restassured.module.mockmvc.http.PostController)2 MockHttpServletRequestBuilderInterceptor (io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 LogConfig (io.restassured.config.LogConfig)1 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 SecuredController (io.restassured.module.mockmvc.http.SecuredController)1