use of org.springframework.test.web.servlet.ResultMatcher in project tutorials by eugenp.
the class RequestMapingShortcutsIntegrationTest method giventUrl_whenPostRequest_thenFindPostResponse.
@Test
public void giventUrl_whenPostRequest_thenFindPostResponse() throws Exception {
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.post("/post");
ResultMatcher contentMatcher = MockMvcResultMatchers.content().string("POST Response");
this.mockMvc.perform(builder).andExpect(contentMatcher).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.test.web.servlet.ResultMatcher in project tutorials by eugenp.
the class RequestMapingShortcutsIntegrationTest method giventUrl_whenDeleteRequest_thenFindDeleteResponse.
@Test
public void giventUrl_whenDeleteRequest_thenFindDeleteResponse() throws Exception {
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.delete("/delete");
ResultMatcher contentMatcher = MockMvcResultMatchers.content().string("DELETE Response");
this.mockMvc.perform(builder).andExpect(contentMatcher).andExpect(MockMvcResultMatchers.status().isOk());
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-security by spring-projects.
the class HeadersConfigurerTests method getWhenContentSecurityPolicyConfiguredThenContentSecurityPolicyHeaderInResponse.
@Test
public void getWhenContentSecurityPolicyConfiguredThenContentSecurityPolicyHeaderInResponse() throws Exception {
this.spring.register(ContentSecurityPolicyDefaultConfig.class).autowire();
ResultMatcher csp = header().string(HttpHeaders.CONTENT_SECURITY_POLICY, "default-src 'self'");
// @formatter:off
MvcResult mvcResult = this.mvc.perform(get("/").secure(true)).andExpect(csp).andReturn();
// @formatter:on
assertThat(mvcResult.getResponse().getHeaderNames()).containsExactly(HttpHeaders.CONTENT_SECURITY_POLICY);
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-security by spring-projects.
the class HeadersConfigurerTests method configureWhenContentSecurityPolicyNoPolicyDirectivesInLambdaThenDefaultHeaderValue.
@Test
public void configureWhenContentSecurityPolicyNoPolicyDirectivesInLambdaThenDefaultHeaderValue() throws Exception {
this.spring.register(ContentSecurityPolicyNoDirectivesInLambdaConfig.class).autowire();
ResultMatcher csp = header().string(HttpHeaders.CONTENT_SECURITY_POLICY, "default-src 'self'");
// @formatter:off
MvcResult mvcResult = this.mvc.perform(get("/").secure(true)).andExpect(csp).andReturn();
// @formatter:on
assertThat(mvcResult.getResponse().getHeaderNames()).containsExactly(HttpHeaders.CONTENT_SECURITY_POLICY);
}
use of org.springframework.test.web.servlet.ResultMatcher in project spring-security by spring-projects.
the class HeadersConfigurerTests method getWhenReferrerPolicyConfiguredWithCustomValueInLambdaThenCustomValueInResponse.
@Test
public void getWhenReferrerPolicyConfiguredWithCustomValueInLambdaThenCustomValueInResponse() throws Exception {
this.spring.register(ReferrerPolicyCustomInLambdaConfig.class).autowire();
ResultMatcher referrerPolicy = header().string("Referrer-Policy", ReferrerPolicy.SAME_ORIGIN.getPolicy());
// @formatter:off
MvcResult mvcResult = this.mvc.perform(get("/").secure(true)).andExpect(referrerPolicy).andReturn();
// @formatter:on
assertThat(mvcResult.getResponse().getHeaderNames()).containsExactly("Referrer-Policy");
}
Aggregations