Polish MockMvcBuilders tests
This commit is contained in:
parent
32aafb21ff
commit
d8a01cb04a
|
@ -12,22 +12,12 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.test.web.servlet.setup;
|
package org.springframework.test.web.servlet.setup;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.web.MockServletContext;
|
import org.springframework.mock.web.MockServletContext;
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DefaultMockMvcBuilder}.
|
* Tests for {@link DefaultMockMvcBuilder}.
|
||||||
|
@ -37,33 +27,6 @@ import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
*/
|
*/
|
||||||
public class DefaultMockMvcBuilderTests {
|
public class DefaultMockMvcBuilderTests {
|
||||||
|
|
||||||
private StandaloneMockMvcBuilder builder;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
builder = MockMvcBuilders.standaloneSetup(new PersonController());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void addFiltersFiltersNull() {
|
|
||||||
builder.addFilters((Filter[]) null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void addFiltersFiltersContainsNull() {
|
|
||||||
builder.addFilters(new ContinueFilter(), (Filter) null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void addFilterPatternsNull() {
|
|
||||||
builder.addFilter(new ContinueFilter(), (String[]) null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void addFilterPatternContainsNull() {
|
|
||||||
builder.addFilter(new ContinueFilter(), (String) null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test // SPR-12553
|
@Test // SPR-12553
|
||||||
public void applicationContextAttribute() {
|
public void applicationContextAttribute() {
|
||||||
MockServletContext servletContext = new MockServletContext();
|
MockServletContext servletContext = new MockServletContext();
|
||||||
|
@ -73,21 +36,4 @@ public class DefaultMockMvcBuilderTests {
|
||||||
.getRequiredWebApplicationContext(servletContext));
|
.getRequiredWebApplicationContext(servletContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
private static class PersonController {
|
|
||||||
@RequestMapping(value="/forward")
|
|
||||||
public String forward() {
|
|
||||||
return "forward:/persons";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ContinueFilter extends OncePerRequestFilter {
|
|
||||||
@Override
|
|
||||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
|
|
||||||
FilterChain filterChain) throws ServletException, IOException {
|
|
||||||
filterChain.doFilter(request, response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.test.web.servlet.setup;
|
package org.springframework.test.web.servlet.setup;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||||
|
@ -23,6 +30,7 @@ import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.HandlerExecutionChain;
|
import org.springframework.web.servlet.HandlerExecutionChain;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||||
|
@ -30,14 +38,15 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rossen Stoyanchev
|
* Tests for {@link StandaloneMockMvcBuilder}
|
||||||
|
*
|
||||||
|
* @author Rossen
|
||||||
|
* @author Rob Winch
|
||||||
|
* @author Sebastien Deleuze
|
||||||
*/
|
*/
|
||||||
public class StandaloneMockMvcBuilderTests {
|
public class StandaloneMockMvcBuilderTests {
|
||||||
|
|
||||||
|
@Test // SPR-10825
|
||||||
// SPR-10825
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void placeHoldersInRequestMapping() throws Exception {
|
public void placeHoldersInRequestMapping() throws Exception {
|
||||||
|
|
||||||
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
|
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
|
||||||
|
@ -63,6 +72,30 @@ public class StandaloneMockMvcBuilderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void addFiltersFiltersNull() {
|
||||||
|
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
|
||||||
|
builder.addFilters((Filter[]) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void addFiltersFiltersContainsNull() {
|
||||||
|
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
|
||||||
|
builder.addFilters(new ContinueFilter(), (Filter) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void addFilterPatternsNull() {
|
||||||
|
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
|
||||||
|
builder.addFilter(new ContinueFilter(), (String[]) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void addFilterPatternContainsNull() {
|
||||||
|
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
|
||||||
|
builder.addFilter(new ContinueFilter(), (String) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
private static class PlaceholderController {
|
private static class PlaceholderController {
|
||||||
|
@ -86,4 +119,21 @@ public class StandaloneMockMvcBuilderTests {
|
||||||
return this.wac;
|
return this.wac;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
private static class PersonController {
|
||||||
|
@RequestMapping(value="/forward")
|
||||||
|
public String forward() {
|
||||||
|
return "forward:/persons";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ContinueFilter extends OncePerRequestFilter {
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
FilterChain filterChain) throws ServletException, IOException {
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue