Search in sources :

Example 1 with MockMvcRequestSpecification

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"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 2 with MockMvcRequestSpecification

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"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 3 with MockMvcRequestSpecification

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"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 4 with MockMvcRequestSpecification

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"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) MockMvcAuthenticationScheme(io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 5 with MockMvcRequestSpecification

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);
}
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)31 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)31 Test (org.junit.Test)31 GreetingController (io.restassured.module.mockmvc.http.GreetingController)4 RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)3 MockMvcAuthenticationScheme (io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme)3 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)3 Cookie (io.restassured.http.Cookie)2 Header (io.restassured.http.Header)2 MockHttpServletRequestBuilderInterceptor (io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor)2 PrintStream (java.io.PrintStream)2 StringWriter (java.io.StringWriter)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 PostController (io.restassured.module.mockmvc.http.PostController)1