Java Code Examples for org.springframework.mock.web.test.MockHttpServletResponse#getHeader()
The following examples show how to use
org.springframework.mock.web.test.MockHttpServletResponse#getHeader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void methodNotAllowed() throws Exception { initServletWithControllers(MethodNotAllowedController.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do"); MockHttpServletResponse response = new MockHttpServletResponse(); getServlet().service(request, response); assertEquals("Invalid response status", HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus()); String allowHeader = response.getHeader("Allow"); assertNotNull("No Allow header", allowHeader); Set<String> allowedMethods = new HashSet<>(); allowedMethods.addAll(Arrays.asList(StringUtils.delimitedListToStringArray(allowHeader, ", "))); assertEquals("Invalid amount of supported methods", 6, allowedMethods.size()); assertTrue("PUT not allowed", allowedMethods.contains("PUT")); assertTrue("DELETE not allowed", allowedMethods.contains("DELETE")); assertTrue("HEAD not allowed", allowedMethods.contains("HEAD")); assertTrue("TRACE not allowed", allowedMethods.contains("TRACE")); assertTrue("OPTIONS not allowed", allowedMethods.contains("OPTIONS")); assertTrue("POST not allowed", allowedMethods.contains("POST")); }
Example 2
Source File: ServletAnnotationControllerHandlerMethodTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void methodNotAllowed() throws Exception { initServletWithControllers(MethodNotAllowedController.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do"); MockHttpServletResponse response = new MockHttpServletResponse(); getServlet().service(request, response); assertEquals("Invalid response status", HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus()); String allowHeader = response.getHeader("Allow"); assertNotNull("No Allow header", allowHeader); Set<String> allowedMethods = new HashSet<>(); allowedMethods.addAll(Arrays.asList(StringUtils.delimitedListToStringArray(allowHeader, ", "))); assertEquals("Invalid amount of supported methods", 6, allowedMethods.size()); assertTrue("PUT not allowed", allowedMethods.contains("PUT")); assertTrue("DELETE not allowed", allowedMethods.contains("DELETE")); assertTrue("HEAD not allowed", allowedMethods.contains("HEAD")); assertTrue("TRACE not allowed", allowedMethods.contains("TRACE")); assertTrue("OPTIONS not allowed", allowedMethods.contains("OPTIONS")); assertTrue("POST not allowed", allowedMethods.contains("POST")); }
Example 3
Source File: ServletAnnotationControllerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void methodNotAllowed() throws Exception { initServlet(MethodNotAllowedController.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do"); MockHttpServletResponse response = new MockHttpServletResponse(); servlet.service(request, response); assertEquals("Invalid response status", HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus()); String allowHeader = response.getHeader("Allow"); assertNotNull("No Allow header", allowHeader); Set<String> allowedMethods = new HashSet<String>(); allowedMethods.addAll(Arrays.asList(StringUtils.delimitedListToStringArray(allowHeader, ", "))); assertEquals("Invalid amount of supported methods", 6, allowedMethods.size()); assertTrue("PUT not allowed", allowedMethods.contains("PUT")); assertTrue("DELETE not allowed", allowedMethods.contains("DELETE")); assertTrue("HEAD not allowed", allowedMethods.contains("HEAD")); assertTrue("TRACE not allowed", allowedMethods.contains("TRACE")); assertTrue("OPTIONS not allowed", allowedMethods.contains("OPTIONS")); assertTrue("POST not allowed", allowedMethods.contains("POST")); }
Example 4
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void methodNotAllowed() throws Exception { initServletWithControllers(MethodNotAllowedController.class); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do"); MockHttpServletResponse response = new MockHttpServletResponse(); getServlet().service(request, response); assertEquals("Invalid response status", HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus()); String allowHeader = response.getHeader("Allow"); assertNotNull("No Allow header", allowHeader); Set<String> allowedMethods = new HashSet<String>(); allowedMethods.addAll(Arrays.asList(StringUtils.delimitedListToStringArray(allowHeader, ", "))); assertEquals("Invalid amount of supported methods", 6, allowedMethods.size()); assertTrue("PUT not allowed", allowedMethods.contains("PUT")); assertTrue("DELETE not allowed", allowedMethods.contains("DELETE")); assertTrue("HEAD not allowed", allowedMethods.contains("HEAD")); assertTrue("TRACE not allowed", allowedMethods.contains("TRACE")); assertTrue("OPTIONS not allowed", allowedMethods.contains("OPTIONS")); assertTrue("POST not allowed", allowedMethods.contains("POST")); }