Add @Override annotations to test sources
Issue: SPR-10129
This commit is contained in:
@@ -51,12 +51,14 @@ public class DerivedTestBean extends TestBean implements Serializable, BeanNameA
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanName(String beanName) {
|
||||
if (this.beanName == null || beanName == null) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
@@ -75,10 +77,12 @@ public class DerivedTestBean extends TestBean implements Serializable, BeanNameA
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasDestroyed() {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public class NestedTestBean implements INestedTestBean {
|
||||
this.company = (company != null ? company : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
@@ -31,22 +31,27 @@ public class SerializablePerson implements Person, Serializable {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object echo(Object o) throws Throwable {
|
||||
if (o instanceof Throwable) {
|
||||
throw (Throwable) o;
|
||||
|
||||
@@ -137,6 +137,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
@@ -145,6 +146,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
return beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
@@ -161,10 +163,12 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
return postProcessed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@@ -180,10 +184,12 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
@@ -196,14 +202,17 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
this.jedi = jedi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITestBean getSpouse() {
|
||||
return (spouses != null ? spouses[0] : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpouse(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITestBean[] getSpouses() {
|
||||
return spouses;
|
||||
}
|
||||
@@ -230,10 +239,12 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getStringArray() {
|
||||
return stringArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStringArray(String[] stringArray) {
|
||||
this.stringArray = stringArray;
|
||||
}
|
||||
@@ -302,6 +313,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INestedTestBean getDoctor() {
|
||||
return doctor;
|
||||
}
|
||||
@@ -310,6 +322,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
this.doctor = doctor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INestedTestBean getLawyer() {
|
||||
return lawyer;
|
||||
}
|
||||
@@ -342,6 +355,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
this.someBoolean = someBoolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexedTestBean getNestedIndexedBean() {
|
||||
return nestedIndexedBean;
|
||||
}
|
||||
@@ -370,18 +384,21 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
/**
|
||||
* @see org.springframework.beans.ITestBean#exceptional(Throwable)
|
||||
*/
|
||||
@Override
|
||||
public void exceptional(Throwable t) throws Throwable {
|
||||
if (t != null) {
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unreliableFileOperation() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
/**
|
||||
* @see org.springframework.beans.ITestBean#returnsThis()
|
||||
*/
|
||||
@Override
|
||||
public Object returnsThis() {
|
||||
return this;
|
||||
}
|
||||
@@ -389,9 +406,11 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
/**
|
||||
* @see org.springframework.beans.IOther#absquatulate()
|
||||
*/
|
||||
@Override
|
||||
public void absquatulate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int haveBirthday() {
|
||||
return age++;
|
||||
}
|
||||
@@ -421,6 +440,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
return this.age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object other) {
|
||||
if (this.name != null && other instanceof TestBean) {
|
||||
return this.name.compareTo(((TestBean) other).getName());
|
||||
|
||||
@@ -74,6 +74,7 @@ public class DummyFactory
|
||||
* Return if the bean managed by this factory is a singleton.
|
||||
* @see FactoryBean#isSingleton()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return this.singleton;
|
||||
}
|
||||
@@ -85,6 +86,7 @@ public class DummyFactory
|
||||
this.singleton = singleton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
@@ -93,6 +95,7 @@ public class DummyFactory
|
||||
return beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = (AutowireCapableBeanFactory) beanFactory;
|
||||
this.beanFactory.applyBeanPostProcessorsBeforeInitialization(this.testBean, this.beanName);
|
||||
@@ -119,6 +122,7 @@ public class DummyFactory
|
||||
return otherTestBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (initialized) {
|
||||
throw new RuntimeException("Cannot call afterPropertiesSet twice on the one bean");
|
||||
@@ -144,6 +148,7 @@ public class DummyFactory
|
||||
* and prototype mode.
|
||||
* @see FactoryBean#getObject()
|
||||
*/
|
||||
@Override
|
||||
public Object getObject() throws BeansException {
|
||||
if (isSingleton()) {
|
||||
return this.testBean;
|
||||
@@ -158,11 +163,13 @@ public class DummyFactory
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getObjectType() {
|
||||
return TestBean.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (this.testBean != null) {
|
||||
this.testBean.setName(null);
|
||||
|
||||
@@ -53,6 +53,7 @@ public class LifecycleBean implements BeanNameAware, BeanFactoryAware, Initializ
|
||||
return initMethodDeclared;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanName(String name) {
|
||||
this.beanName = name;
|
||||
}
|
||||
@@ -61,6 +62,7 @@ public class LifecycleBean implements BeanNameAware, BeanFactoryAware, Initializ
|
||||
return beanName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.owningFactory = beanFactory;
|
||||
}
|
||||
@@ -75,6 +77,7 @@ public class LifecycleBean implements BeanNameAware, BeanFactoryAware, Initializ
|
||||
this.postProcessedBeforeInit = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (this.owningFactory == null) {
|
||||
throw new RuntimeException("Factory didn't call setBeanFactory before afterPropertiesSet on lifecycle bean");
|
||||
@@ -126,6 +129,7 @@ public class LifecycleBean implements BeanNameAware, BeanFactoryAware, Initializ
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (this.destroyed) {
|
||||
throw new IllegalStateException("Already destroyed");
|
||||
@@ -140,6 +144,7 @@ public class LifecycleBean implements BeanNameAware, BeanFactoryAware, Initializ
|
||||
|
||||
public static class PostProcessor implements BeanPostProcessor {
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
|
||||
if (bean instanceof LifecycleBean) {
|
||||
((LifecycleBean) bean).postProcessBeforeInit();
|
||||
@@ -147,6 +152,7 @@ public class LifecycleBean implements BeanNameAware, BeanFactoryAware, Initializ
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
|
||||
if (bean instanceof LifecycleBean) {
|
||||
((LifecycleBean) bean).postProcessAfterInit();
|
||||
|
||||
@@ -30,6 +30,7 @@ public class MustBeInitialized implements InitializingBean {
|
||||
/**
|
||||
* @see InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.inited = true;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class ACATester implements ApplicationContextAware {
|
||||
|
||||
private ApplicationContext ac;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext ctx) throws ApplicationContextException {
|
||||
// check reinitialization
|
||||
if (this.ac != null) {
|
||||
|
||||
@@ -29,6 +29,7 @@ public class BeanThatBroadcasts implements ApplicationContextAware {
|
||||
public int receivedCount;
|
||||
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
if (applicationContext.getDisplayName().indexOf("listener") != -1) {
|
||||
|
||||
@@ -43,6 +43,7 @@ public class BeanThatListens implements ApplicationListener {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
eventCount++;
|
||||
if (beanThatBroadcasts != null) {
|
||||
|
||||
@@ -15,18 +15,21 @@ public class LifecycleContextBean extends LifecycleBean implements ApplicationCo
|
||||
|
||||
protected ApplicationContext owningContext;
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
super.setBeanFactory(beanFactory);
|
||||
if (this.owningContext != null)
|
||||
throw new RuntimeException("Factory called setBeanFactory after setApplicationContext");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
if (this.owningContext == null)
|
||||
throw new RuntimeException("Factory didn't call setAppliationContext before afterPropertiesSet on lifecycle bean");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if (this.owningFactory == null)
|
||||
throw new RuntimeException("Factory called setApplicationContext before setBeanFactory");
|
||||
|
||||
@@ -21,6 +21,7 @@ public class TestListener implements ApplicationListener {
|
||||
eventCount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent e) {
|
||||
++eventCount;
|
||||
}
|
||||
|
||||
@@ -45,10 +45,12 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
|
||||
|
||||
protected TestListener parentListener = new TestListener();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
this.applicationContext = createContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BeanFactory getBeanFactory() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@@ -325,6 +325,7 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
|
||||
|
||||
public static class TestBeanEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) {
|
||||
TestBean tb = new TestBean();
|
||||
StringTokenizer st = new StringTokenizer(text, "_");
|
||||
|
||||
@@ -105,6 +105,7 @@ public final class ContextLoaderTests {
|
||||
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
|
||||
"/org/springframework/web/context/WEB-INF/applicationContext.xml");
|
||||
final ServletContextListener listener = new ContextLoaderListener() {
|
||||
@Override
|
||||
protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
|
||||
assertNotNull("The ServletContext should not be null.", servletContext);
|
||||
assertEquals("Verifying that we received the expected ServletContext.", sc, servletContext);
|
||||
@@ -301,6 +302,7 @@ public final class ContextLoaderTests {
|
||||
"/org/springframework/web/context/WEB-INF/applicationContext.xml",
|
||||
"/org/springframework/web/context/WEB-INF/fail.xml" }) {
|
||||
|
||||
@Override
|
||||
public void refresh() throws BeansException {
|
||||
try {
|
||||
super.refresh();
|
||||
@@ -320,6 +322,7 @@ public final class ContextLoaderTests {
|
||||
}
|
||||
|
||||
private static class TestContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
ConfigurableEnvironment environment = applicationContext.getEnvironment();
|
||||
environment.getPropertySources().addFirst(new PropertySource<Object>("testPropertySource") {
|
||||
@@ -332,6 +335,7 @@ public final class ContextLoaderTests {
|
||||
}
|
||||
|
||||
private static class TestWebContextInitializer implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {
|
||||
@Override
|
||||
public void initialize(ConfigurableWebApplicationContext applicationContext) {
|
||||
ServletContext ctx = applicationContext.getServletContext(); // type-safe access to servlet-specific methods
|
||||
ctx.setAttribute("initialized", true);
|
||||
@@ -339,6 +343,7 @@ public final class ContextLoaderTests {
|
||||
}
|
||||
|
||||
private static class EnvApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {
|
||||
@Override
|
||||
public void initialize(ConfigurableWebApplicationContext applicationContext) {
|
||||
// test that ApplicationContextInitializers can access ServletContext properties
|
||||
// via the environment (SPR-8991)
|
||||
@@ -352,6 +357,7 @@ public final class ContextLoaderTests {
|
||||
}
|
||||
|
||||
private static class UnknownContextInitializer implements ApplicationContextInitializer<UnknownApplicationContext> {
|
||||
@Override
|
||||
public void initialize(UnknownApplicationContext applicationContext) {
|
||||
applicationContext.unheardOf();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public class ResourceBundleMessageSourceTests extends AbstractApplicationContext
|
||||
|
||||
private MessageSource themeMsgSource;
|
||||
|
||||
@Override
|
||||
protected ConfigurableApplicationContext createContext() throws Exception {
|
||||
root = new XmlWebApplicationContext();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
@@ -82,6 +83,7 @@ public class ResourceBundleMessageSourceTests extends AbstractApplicationContext
|
||||
return wac;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testCount() {
|
||||
assertTrue("should have 14 beans, not " +
|
||||
this.applicationContext.getBeanDefinitionCount(),
|
||||
@@ -92,6 +94,7 @@ public class ResourceBundleMessageSourceTests extends AbstractApplicationContext
|
||||
* Overridden as we can't trust superclass method.
|
||||
* @see org.springframework.context.AbstractApplicationContextTests#testEvents()
|
||||
*/
|
||||
@Override
|
||||
public void testEvents() throws Exception {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class ServletConfigAwareBean implements ServletConfigAware {
|
||||
|
||||
private ServletConfig servletConfig;
|
||||
|
||||
@Override
|
||||
public void setServletConfig(ServletConfig servletConfig) {
|
||||
this.servletConfig = servletConfig;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class ServletContextAwareBean implements ServletContextAware {
|
||||
|
||||
private ServletContext servletContext;
|
||||
|
||||
@Override
|
||||
public void setServletContext(ServletContext servletContext) {
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
|
||||
private ConfigurableWebApplicationContext root;
|
||||
|
||||
@Override
|
||||
protected ConfigurableApplicationContext createContext() throws Exception {
|
||||
InitAndIB.constructed = false;
|
||||
root = new XmlWebApplicationContext();
|
||||
@@ -53,8 +54,10 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
root.setServletContext(sc);
|
||||
root.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/applicationContext.xml"});
|
||||
root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
|
||||
beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
|
||||
if (bean instanceof TestBean) {
|
||||
@@ -62,6 +65,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
@@ -90,6 +94,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
* Overridden as we can't trust superclass method
|
||||
* @see org.springframework.context.AbstractApplicationContextTests#testEvents()
|
||||
*/
|
||||
@Override
|
||||
public void testEvents() throws Exception {
|
||||
TestListener listener = (TestListener) this.applicationContext.getBean("testListener");
|
||||
listener.zeroCounter();
|
||||
@@ -104,6 +109,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
assertTrue("1 parent events after publication", parentListener.getEventCount() == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testCount() {
|
||||
assertTrue("should have 14 beans, not "+ this.applicationContext.getBeanDefinitionCount(),
|
||||
this.applicationContext.getBeanDefinitionCount() == 14);
|
||||
@@ -169,6 +175,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
constructed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (this.initMethodInvoked)
|
||||
fail();
|
||||
@@ -182,6 +189,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
this.initMethodInvoked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (this.customDestroyed)
|
||||
fail();
|
||||
|
||||
@@ -48,6 +48,7 @@ public class HttpRequestHandlerTests {
|
||||
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
wac.getBeanFactory().registerSingleton("myHandler", new HttpRequestHandler() {
|
||||
@Override
|
||||
public void handleRequest(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
|
||||
assertSame(request, req);
|
||||
assertSame(response, res);
|
||||
|
||||
@@ -371,6 +371,7 @@ public class ServletContextSupportTests {
|
||||
paths.add("/WEB-INF/context2.xml");
|
||||
|
||||
MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context") {
|
||||
@Override
|
||||
public Set<String> getResourcePaths(String path) {
|
||||
if ("/WEB-INF/".equals(path)) {
|
||||
return paths;
|
||||
@@ -397,6 +398,7 @@ public class ServletContextSupportTests {
|
||||
dirs.add("/WEB-INF/mydir2/");
|
||||
|
||||
MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context") {
|
||||
@Override
|
||||
public Set<String> getResourcePaths(String path) {
|
||||
if ("/WEB-INF/".equals(path)) {
|
||||
return dirs;
|
||||
@@ -433,6 +435,7 @@ public class ServletContextSupportTests {
|
||||
paths.add("/WEB-INF/mydir2/mydir3/");
|
||||
|
||||
MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context") {
|
||||
@Override
|
||||
public Set<String> getResourcePaths(String path) {
|
||||
if ("/WEB-INF/".equals(path)) {
|
||||
return dirs;
|
||||
@@ -470,6 +473,7 @@ public class ServletContextSupportTests {
|
||||
paths.add("C:/webroot/someOtherDirThatDoesntContainPath");
|
||||
|
||||
MockServletContext sc = new MockServletContext("classpath:org/springframework/web/context") {
|
||||
@Override
|
||||
public Set<String> getResourcePaths(String path) {
|
||||
if ("/WEB-INF/".equals(path)) {
|
||||
return paths;
|
||||
|
||||
@@ -73,6 +73,7 @@ import org.springframework.web.servlet.view.ResourceBundleViewResolver;
|
||||
*/
|
||||
public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
@Override
|
||||
public void refresh() throws BeansException {
|
||||
registerSingleton(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, SessionLocaleResolver.class);
|
||||
registerSingleton(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, SessionThemeResolver.class);
|
||||
@@ -179,6 +180,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class HeadController implements Controller {
|
||||
|
||||
@Override
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
if ("HEAD".equals(request.getMethod())) {
|
||||
response.setContentLength(5);
|
||||
@@ -190,6 +192,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class BodyController implements Controller {
|
||||
|
||||
@Override
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
response.getOutputStream().write("body".getBytes());
|
||||
return null;
|
||||
@@ -199,6 +202,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class NoViewController implements Controller {
|
||||
|
||||
@Override
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
return new ModelAndView();
|
||||
}
|
||||
@@ -209,22 +213,27 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
private ServletConfig servletConfig;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig servletConfig) throws ServletException {
|
||||
this.servletConfig = servletConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletConfig getServletConfig() {
|
||||
return servletConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException {
|
||||
servletResponse.getOutputStream().write("body".getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServletInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.servletConfig = null;
|
||||
}
|
||||
@@ -241,20 +250,24 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class MyHandlerAdapter extends ApplicationObjectSupport implements HandlerAdapter, Ordered {
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 99;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Object handler) {
|
||||
return handler != null && MyHandler.class.isAssignableFrom(handler.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object delegate)
|
||||
throws ServletException, IllegalAccessException {
|
||||
((MyHandler) delegate).doSomething(request);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified(HttpServletRequest request, Object delegate) {
|
||||
return ((MyHandler) delegate).lastModified();
|
||||
}
|
||||
@@ -263,15 +276,18 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class MyDummyAdapter extends ApplicationObjectSupport implements HandlerAdapter {
|
||||
|
||||
@Override
|
||||
public boolean supports(Object handler) {
|
||||
return handler != null && MyHandler.class.isAssignableFrom(handler.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object delegate)
|
||||
throws IOException, ServletException {
|
||||
throw new ServletException("dummy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified(HttpServletRequest request, Object delegate) {
|
||||
return -1;
|
||||
}
|
||||
@@ -280,6 +296,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class MyHandlerInterceptor1 implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws ServletException {
|
||||
if (request.getAttribute("test2") != null) {
|
||||
@@ -291,6 +308,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
||||
throws ServletException {
|
||||
@@ -303,6 +321,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
request.removeAttribute("test1x");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws ServletException {
|
||||
@@ -316,6 +335,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class MyHandlerInterceptor2 implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws ServletException {
|
||||
if (request.getAttribute("test1x") == null) {
|
||||
@@ -330,6 +350,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
|
||||
throws ServletException {
|
||||
@@ -345,6 +366,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
request.removeAttribute("test2x");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||
throws Exception {
|
||||
@@ -358,14 +380,17 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class MyWebRequestInterceptor implements WebRequestInterceptor {
|
||||
|
||||
@Override
|
||||
public void preHandle(WebRequest request) throws Exception {
|
||||
request.setAttribute("test3", "test3", WebRequest.SCOPE_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(WebRequest request, ModelMap model) throws Exception {
|
||||
request.setAttribute("test3x", "test3x", WebRequest.SCOPE_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(WebRequest request, Exception ex) throws Exception {
|
||||
request.setAttribute("test3y", "test3y", WebRequest.SCOPE_REQUEST);
|
||||
}
|
||||
@@ -374,6 +399,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class ComplexLocaleChecker implements MyHandler {
|
||||
|
||||
@Override
|
||||
public void doSomething(HttpServletRequest request) throws ServletException, IllegalAccessException {
|
||||
WebApplicationContext wac = RequestContextUtils.getWebApplicationContext(request);
|
||||
if (!(wac instanceof ComplexWebApplicationContext)) {
|
||||
@@ -411,6 +437,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long lastModified() {
|
||||
return 99;
|
||||
}
|
||||
@@ -419,10 +446,12 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class MockMultipartResolver implements MultipartResolver {
|
||||
|
||||
@Override
|
||||
public boolean isMultipart(HttpServletRequest request) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {
|
||||
if (request.getAttribute("fail") != null) {
|
||||
throw new MaxUploadSizeExceededException(1000);
|
||||
@@ -435,15 +464,18 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
}
|
||||
request.setAttribute("resolved", Boolean.TRUE);
|
||||
return new AbstractMultipartHttpServletRequest(request) {
|
||||
@Override
|
||||
public HttpHeaders getMultipartHeaders(String paramOrFileName) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getMultipartContentType(String paramOrFileName) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupMultipart(MultipartHttpServletRequest request) {
|
||||
if (request.getAttribute("cleanedUp") != null) {
|
||||
throw new IllegalStateException("Already cleaned up");
|
||||
@@ -457,6 +489,7 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public int counter = 0;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof RequestHandledEvent) {
|
||||
this.counter++;
|
||||
|
||||
@@ -81,6 +81,7 @@ public class DispatcherServletTests extends TestCase {
|
||||
|
||||
private DispatcherServlet complexDispatcherServlet;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws ServletException {
|
||||
servletConfig = new MockServletConfig(new MockServletContext(), "simple");
|
||||
MockServletConfig complexConfig = new MockServletConfig(servletConfig.getServletContext(), "complex");
|
||||
@@ -869,6 +870,7 @@ public class DispatcherServletTests extends TestCase {
|
||||
|
||||
public static class ControllerFromParent implements Controller {
|
||||
|
||||
@Override
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
return new ModelAndView(ControllerFromParent.class.getName());
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
|
||||
*/
|
||||
public class SimpleWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
@Override
|
||||
public void refresh() throws BeansException {
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("commandClass", "org.springframework.beans.TestBean");
|
||||
@@ -75,6 +76,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
|
||||
|
||||
public static class LocaleChecker implements Controller, LastModified {
|
||||
|
||||
@Override
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
if (!(RequestContextUtils.getWebApplicationContext(request) instanceof SimpleWebApplicationContext)) {
|
||||
@@ -89,6 +91,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastModified(HttpServletRequest request) {
|
||||
return 98;
|
||||
}
|
||||
@@ -105,6 +108,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
|
||||
this.messageSource.addMessage("themetestArgs", Locale.ENGLISH, "theme test message {0}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Theme getTheme(String themeName) {
|
||||
if (AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME.equals(themeName)) {
|
||||
return new SimpleTheme(AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME, this.messageSource);
|
||||
|
||||
@@ -148,6 +148,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
|
||||
|
||||
class TestWebArgumentResolver implements WebArgumentResolver {
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
|
||||
return null;
|
||||
}
|
||||
@@ -156,10 +157,12 @@ class TestWebArgumentResolver implements WebArgumentResolver {
|
||||
|
||||
class TestHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
return null;
|
||||
@@ -168,10 +171,12 @@ class TestHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver
|
||||
|
||||
class TestHandlerMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
@@ -181,10 +186,12 @@ class TestHandlerMethodReturnValueHandler implements HandlerMethodReturnValueHan
|
||||
|
||||
class TestMessageCodesResolver implements MessageCodesResolver {
|
||||
|
||||
@Override
|
||||
public String[] resolveMessageCodes(String errorCode, String objectName) {
|
||||
return new String[] { "test.foo.bar" };
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class fieldType) {
|
||||
return new String[] { "test.foo.bar" };
|
||||
|
||||
@@ -516,10 +516,12 @@ public class MvcNamespaceTests {
|
||||
|
||||
boolean validatorInvoked;
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
this.validatorInvoked = true;
|
||||
}
|
||||
|
||||
@@ -161,13 +161,16 @@ public class InterceptorRegistryTests {
|
||||
|
||||
private boolean preHandleInvoked = false;
|
||||
|
||||
@Override
|
||||
public void preHandle(WebRequest request) throws Exception {
|
||||
preHandleInvoked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(WebRequest request, ModelMap model) throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(WebRequest request, Exception ex) throws Exception {
|
||||
}
|
||||
|
||||
|
||||
@@ -222,6 +222,7 @@ public class WebMvcConfigurationSupportExtensionTests {
|
||||
@Override
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
registry.addConverter(new Converter<TestBean, String>() {
|
||||
@Override
|
||||
public String convert(TestBean source) {
|
||||
return "converted";
|
||||
}
|
||||
@@ -236,9 +237,11 @@ public class WebMvcConfigurationSupportExtensionTests {
|
||||
@Override
|
||||
public Validator getValidator() {
|
||||
return new Validator() {
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
errors.reject("invalid");
|
||||
}
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public class BeanNameUrlHandlerMappingTests extends TestCase {
|
||||
|
||||
private ConfigurableWebApplicationContext wac;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
MockServletContext sc = new MockServletContext("");
|
||||
wac = new XmlWebApplicationContext();
|
||||
|
||||
@@ -183,6 +183,7 @@ public class CancellableFormControllerTests extends TestCase {
|
||||
final String reason = "Because I wanted to";
|
||||
|
||||
TestController ctl = new TestController() {
|
||||
@Override
|
||||
protected ModelAndView onCancel(HttpServletRequest request, HttpServletResponse response, Object command) {
|
||||
return new ModelAndView(getCancelView(), "reason", reason);
|
||||
}
|
||||
@@ -221,9 +222,11 @@ public class CancellableFormControllerTests extends TestCase {
|
||||
|
||||
private boolean invoked = false;
|
||||
|
||||
@Override
|
||||
public boolean supports(Class clazz) {
|
||||
return TestBean.class.isAssignableFrom(clazz);
|
||||
}
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
this.invoked = true;
|
||||
TestBean tb = (TestBean) target;
|
||||
|
||||
@@ -208,6 +208,7 @@ public class CommandControllerTests extends TestCase {
|
||||
|
||||
public void testCachingWithLastModified() throws Exception {
|
||||
class LastModifiedTestController extends TestController implements LastModified {
|
||||
@Override
|
||||
public long getLastModified(HttpServletRequest request) {
|
||||
return 0;
|
||||
}
|
||||
@@ -223,6 +224,7 @@ public class CommandControllerTests extends TestCase {
|
||||
|
||||
public void testCachingWithCustomCacheForSecondsCall() throws Exception {
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
|
||||
cacheForSeconds(response, 5);
|
||||
return super.handle(request, response, command, errors);
|
||||
@@ -237,6 +239,7 @@ public class CommandControllerTests extends TestCase {
|
||||
|
||||
public void testCachingWithCustomApplyCacheSecondsCall1() throws Exception {
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
|
||||
applyCacheSeconds(response, 5);
|
||||
return super.handle(request, response, command, errors);
|
||||
@@ -251,6 +254,7 @@ public class CommandControllerTests extends TestCase {
|
||||
|
||||
public void testCachingWithCustomApplyCacheSecondsCall2() throws Exception {
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
|
||||
applyCacheSeconds(response, 0);
|
||||
return super.handle(request, response, command, errors);
|
||||
@@ -267,6 +271,7 @@ public class CommandControllerTests extends TestCase {
|
||||
|
||||
public void testCachingWithCustomApplyCacheSecondsCall3() throws Exception {
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
|
||||
applyCacheSeconds(response, -1);
|
||||
return super.handle(request, response, command, errors);
|
||||
@@ -282,6 +287,7 @@ public class CommandControllerTests extends TestCase {
|
||||
public void testCustomDateEditorWithAllowEmpty() throws Exception {
|
||||
final DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN);
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
|
||||
}
|
||||
@@ -311,6 +317,7 @@ public class CommandControllerTests extends TestCase {
|
||||
public void testCustomDateEditorWithoutAllowEmpty() throws Exception {
|
||||
final DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN);
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(df, false));
|
||||
}
|
||||
@@ -341,6 +348,7 @@ public class CommandControllerTests extends TestCase {
|
||||
final NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
|
||||
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
|
||||
binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
|
||||
}
|
||||
@@ -371,6 +379,7 @@ public class CommandControllerTests extends TestCase {
|
||||
final NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
|
||||
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
|
||||
binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, false));
|
||||
}
|
||||
@@ -463,9 +472,11 @@ public class CommandControllerTests extends TestCase {
|
||||
|
||||
public void testResetEmptyFieldsTurnedOff() throws Exception {
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected Object getCommand(HttpServletRequest request) throws Exception {
|
||||
return new TestBean("original", 99);
|
||||
}
|
||||
@Override
|
||||
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {
|
||||
binder.setFieldMarkerPrefix(null);
|
||||
}
|
||||
@@ -497,6 +508,7 @@ public class CommandControllerTests extends TestCase {
|
||||
super(TestBean.class, "person");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
|
||||
Map m = new HashMap();
|
||||
assertTrue("Command not null", command != null);
|
||||
|
||||
@@ -178,23 +178,28 @@ public class ControllerTests extends TestCase {
|
||||
destroyed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig servletConfig) {
|
||||
config = servletConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServletConfig getServletConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void service(ServletRequest servletRequest, ServletResponse servletResponse) {
|
||||
request = servletRequest;
|
||||
response = servletResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServletInfo() {
|
||||
return "TestServlet";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
destroyed = true;
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ public class FormControllerTests extends TestCase {
|
||||
final Integer someNumber = new Integer(12);
|
||||
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected void onBindOnNewForm(HttpServletRequest request, Object command) throws Exception {
|
||||
TestBean testBean = (TestBean)command;
|
||||
testBean.setSomeNumber(new Integer(12));
|
||||
@@ -370,6 +371,7 @@ public class FormControllerTests extends TestCase {
|
||||
String successView = "s";
|
||||
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected ModelAndView handleInvalidSubmit(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
throw new ServletException("invalid submit");
|
||||
@@ -438,10 +440,12 @@ public class FormControllerTests extends TestCase {
|
||||
final Float myFloat = new Float("123.45");
|
||||
|
||||
TestController mc = new TestController() {
|
||||
@Override
|
||||
protected boolean isFormChangeRequest(HttpServletRequest request) {
|
||||
return (request.getParameter("formChange") != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFormChange(HttpServletRequest request, HttpServletResponse response, Object command) {
|
||||
assertNotNull("Command should not be null", command);
|
||||
assertEquals("Incorrect command class", TestBean.class, command.getClass());
|
||||
@@ -513,8 +517,10 @@ public class FormControllerTests extends TestCase {
|
||||
|
||||
public static String TOOSHORT = "tooshort";
|
||||
|
||||
@Override
|
||||
public boolean supports(Class clazz) { return true; }
|
||||
|
||||
@Override
|
||||
public void validate(Object obj, Errors errors) {
|
||||
TestBean tb = (TestBean) obj;
|
||||
if (tb.getName() == null || "".equals(tb.getName()))
|
||||
@@ -529,8 +535,10 @@ public class FormControllerTests extends TestCase {
|
||||
|
||||
public static String TOOSHORT = "tooshort";
|
||||
|
||||
@Override
|
||||
public boolean supports(Class clazz) { return true; }
|
||||
|
||||
@Override
|
||||
public void validate(Object obj, Errors errors) {
|
||||
errors.reject("test", "testmessage");
|
||||
}
|
||||
@@ -548,12 +556,14 @@ public class FormControllerTests extends TestCase {
|
||||
setCommandName(BEAN_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object formBackingObject(HttpServletRequest request) throws ServletException {
|
||||
TestBean person = new TestBean();
|
||||
person.setAge(DEFAULT_AGE);
|
||||
return person;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFormChangeRequest(HttpServletRequest request) {
|
||||
return (request.getParameter("formChange") != null);
|
||||
}
|
||||
@@ -562,6 +572,7 @@ public class FormControllerTests extends TestCase {
|
||||
|
||||
private static class TestControllerWithCustomOnSubmit extends TestController {
|
||||
|
||||
@Override
|
||||
protected ModelAndView onSubmit(Object command) throws Exception {
|
||||
return new ModelAndView("mySuccess");
|
||||
}
|
||||
@@ -580,6 +591,7 @@ public class FormControllerTests extends TestCase {
|
||||
setCommandClass(TestBean.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map referenceData(HttpServletRequest request) {
|
||||
++refDataCount;
|
||||
Map m = new HashMap();
|
||||
@@ -595,6 +607,7 @@ public class FormControllerTests extends TestCase {
|
||||
|
||||
public static class BooleanBindingFormController extends AbstractFormController {
|
||||
|
||||
@Override
|
||||
protected ModelAndView processFormSubmission
|
||||
(HttpServletRequest req, HttpServletResponse resp, Object command, BindException errors) throws Exception {
|
||||
ModelAndView mav = new ModelAndView();
|
||||
@@ -602,6 +615,7 @@ public class FormControllerTests extends TestCase {
|
||||
return mav;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelAndView showForm(
|
||||
HttpServletRequest req, HttpServletResponse resp, BindException err) throws Exception {
|
||||
return null;
|
||||
|
||||
@@ -105,9 +105,11 @@ public class WizardFormControllerTests extends TestCase {
|
||||
|
||||
public void testCustomSessionAttributes() throws Exception {
|
||||
AbstractWizardFormController wizard = new TestWizardController() {
|
||||
@Override
|
||||
protected String getFormSessionAttributeName() {
|
||||
return "myFormAttr";
|
||||
}
|
||||
@Override
|
||||
protected String getPageSessionAttributeName() {
|
||||
return "myPageAttr";
|
||||
}
|
||||
@@ -140,9 +142,11 @@ public class WizardFormControllerTests extends TestCase {
|
||||
|
||||
public void testCustomRequestDependentSessionAttributes() throws Exception {
|
||||
AbstractWizardFormController wizard = new TestWizardController() {
|
||||
@Override
|
||||
protected String getFormSessionAttributeName(HttpServletRequest request) {
|
||||
return "myFormAttr" + request.getParameter("formAttr");
|
||||
}
|
||||
@Override
|
||||
protected String getPageSessionAttributeName(HttpServletRequest request) {
|
||||
return "myPageAttr" + request.getParameter("pageAttr");
|
||||
}
|
||||
@@ -383,15 +387,18 @@ public class WizardFormControllerTests extends TestCase {
|
||||
setPages(new String[] {"page0", "page1"});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map referenceData(HttpServletRequest request, int page) throws Exception {
|
||||
assertEquals(new Integer(page), request.getAttribute("target"));
|
||||
return super.referenceData(request, page);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean suppressValidation(HttpServletRequest request, Object command) {
|
||||
return (request.getParameter("formChange") != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validatePage(Object command, Errors errors, int page) {
|
||||
TestBean tb = (TestBean) command;
|
||||
switch (page) {
|
||||
@@ -410,6 +417,7 @@ public class WizardFormControllerTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelAndView processFinish(
|
||||
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
|
||||
throws ServletException, IOException {
|
||||
@@ -417,6 +425,7 @@ public class WizardFormControllerTests extends TestCase {
|
||||
return new ModelAndView("success", getCommandName(), command);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ModelAndView processCancel(
|
||||
HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
|
||||
throws ServletException, IOException {
|
||||
|
||||
@@ -41,6 +41,7 @@ public class ControllerClassNameHandlerMappingTests extends TestCase {
|
||||
|
||||
private HandlerMapping hm4;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
MockServletContext sc = new MockServletContext("");
|
||||
this.wac = new XmlWebApplicationContext();
|
||||
|
||||
@@ -110,6 +110,7 @@ public class JdkProxyServletAnnotationTests {
|
||||
|
||||
public static class TypeLevelImpl implements TypeLevel {
|
||||
|
||||
@Override
|
||||
public void doIt(Writer writer) throws IOException {
|
||||
writer.write("doIt");
|
||||
}
|
||||
@@ -126,6 +127,7 @@ public class JdkProxyServletAnnotationTests {
|
||||
|
||||
public static class MethodLevelImpl implements MethodLevel {
|
||||
|
||||
@Override
|
||||
public void doIt(Writer writer) throws IOException {
|
||||
writer.write("doIt");
|
||||
}
|
||||
@@ -142,6 +144,7 @@ public class JdkProxyServletAnnotationTests {
|
||||
|
||||
public static class TypeAndMethodLevelImpl implements TypeAndMethodLevel {
|
||||
|
||||
@Override
|
||||
public void doIt(Writer writer) throws IOException {
|
||||
writer.write("doIt");
|
||||
}
|
||||
|
||||
@@ -124,6 +124,7 @@ public class RequestSpecificMappingInfoComparatorTests {
|
||||
|
||||
private static class MockComparator implements Comparator<String> {
|
||||
|
||||
@Override
|
||||
public int compare(String s1, String s2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1964,6 +1964,7 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
public static class ListEditorRegistrar implements PropertyEditorRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerCustomEditors(PropertyEditorRegistry registry) {
|
||||
registry.registerCustomEditor(Set.class, new ListEditor());
|
||||
}
|
||||
@@ -2190,12 +2191,14 @@ public class ServletAnnotationControllerTests {
|
||||
@Controller
|
||||
public static class MySessionAttributesControllerImpl implements MySessionAttributesControllerIfc {
|
||||
|
||||
@Override
|
||||
public String get(Model model) {
|
||||
model.addAttribute("object1", new Object());
|
||||
model.addAttribute("object2", new Object());
|
||||
return "page1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String post(@ModelAttribute("object1") Object object1) {
|
||||
//do something with object1
|
||||
return "page2";
|
||||
@@ -2222,6 +2225,7 @@ public class ServletAnnotationControllerTests {
|
||||
@Controller
|
||||
public static class MyParameterizedControllerImpl implements MyEditableParameterizedControllerIfc<TestBean> {
|
||||
|
||||
@Override
|
||||
public List<TestBean> getTestBeans() {
|
||||
List<TestBean> list = new LinkedList<TestBean>();
|
||||
list.add(new TestBean("tb1"));
|
||||
@@ -2229,12 +2233,14 @@ public class ServletAnnotationControllerTests {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Model model) {
|
||||
model.addAttribute("object1", new TestBean());
|
||||
model.addAttribute("object2", new TestBean());
|
||||
return "page1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String post(TestBean object) {
|
||||
//do something with object1
|
||||
return "page2";
|
||||
@@ -2244,6 +2250,7 @@ public class ServletAnnotationControllerTests {
|
||||
@Controller
|
||||
public static class MyParameterizedControllerImplWithOverriddenMappings implements MyEditableParameterizedControllerIfc<TestBean> {
|
||||
|
||||
@Override
|
||||
@ModelAttribute("testBeanList")
|
||||
public List<TestBean> getTestBeans() {
|
||||
List<TestBean> list = new LinkedList<TestBean>();
|
||||
@@ -2252,6 +2259,7 @@ public class ServletAnnotationControllerTests {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public String get(Model model) {
|
||||
model.addAttribute("object1", new TestBean());
|
||||
@@ -2259,6 +2267,7 @@ public class ServletAnnotationControllerTests {
|
||||
return "page1";
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public String post(@ModelAttribute("object1") TestBean object1) {
|
||||
//do something with object1
|
||||
@@ -2428,6 +2437,7 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
private static class MyWebBindingInitializer implements WebBindingInitializer {
|
||||
|
||||
@Override
|
||||
public void initBinder(WebDataBinder binder, WebRequest request) {
|
||||
LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
|
||||
vf.afterPropertiesSet();
|
||||
@@ -2441,6 +2451,7 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
private static class MySpecialArgumentResolver implements WebArgumentResolver {
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) {
|
||||
if (methodParameter.getParameterType().equals(MySpecialArg.class)) {
|
||||
return new MySpecialArg("myValue");
|
||||
@@ -2599,6 +2610,7 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
private static class TestPrincipal implements Principal {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "test";
|
||||
}
|
||||
@@ -2606,6 +2618,7 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
private static class OtherPrincipal implements Principal {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "other";
|
||||
}
|
||||
@@ -2613,12 +2626,15 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
private static class TestViewResolver implements ViewResolver {
|
||||
|
||||
@Override
|
||||
public View resolveViewName(final String viewName, Locale locale) throws Exception {
|
||||
return new View() {
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "deprecation"})
|
||||
public void render(Map model, HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
@@ -2657,11 +2673,14 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
public static class ModelExposingViewResolver implements ViewResolver {
|
||||
|
||||
@Override
|
||||
public View resolveViewName(final String viewName, Locale locale) throws Exception {
|
||||
return new View() {
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
request.setAttribute("viewName", viewName);
|
||||
request.getSession().setAttribute("model", model);
|
||||
@@ -2758,6 +2777,7 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
public static class TestBeanConverter implements Converter<String, ITestBean> {
|
||||
|
||||
@Override
|
||||
public ITestBean convert(String source) {
|
||||
return new TestBean(source);
|
||||
}
|
||||
@@ -2849,23 +2869,28 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
public static class NotReadableMessageConverter implements HttpMessageConverter {
|
||||
|
||||
@Override
|
||||
public boolean canRead(Class clazz, MediaType mediaType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Class clazz, MediaType mediaType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getSupportedMediaTypes() {
|
||||
return Collections.singletonList(new MediaType("application", "pdf"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(Class clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
throw new HttpMessageNotReadableException("Could not read");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
@@ -2880,23 +2905,28 @@ public class ServletAnnotationControllerTests {
|
||||
this.supportedMediaTypes = Arrays.asList(supportedMediaTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(Class clazz, MediaType mediaType) {
|
||||
return supportedMediaTypes.contains(mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Class clazz, MediaType mediaType) {
|
||||
return supportedMediaTypes.contains(mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getSupportedMediaTypes() {
|
||||
return supportedMediaTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(Class clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
outputMessage.getHeaders().setContentType(contentType);
|
||||
@@ -2968,6 +2998,7 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
public static class MyModelAndViewResolver implements ModelAndViewResolver {
|
||||
|
||||
@Override
|
||||
public ModelAndView resolveModelAndView(Method handlerMethod,
|
||||
Class handlerType,
|
||||
Object returnValue,
|
||||
@@ -2975,10 +3006,12 @@ public class ServletAnnotationControllerTests {
|
||||
NativeWebRequest webRequest) {
|
||||
if (returnValue instanceof MySpecialArg) {
|
||||
return new ModelAndView(new View() {
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "text/html";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
response.getWriter().write("myValue");
|
||||
@@ -3036,6 +3069,7 @@ public class ServletAnnotationControllerTests {
|
||||
@Controller
|
||||
public static class TestControllerImpl implements TestController<MyEntity> {
|
||||
|
||||
@Override
|
||||
@RequestMapping("/method")
|
||||
public ModelAndView method(MyEntity object) {
|
||||
return new ModelAndView("/something");
|
||||
@@ -3131,6 +3165,7 @@ public class ServletAnnotationControllerTests {
|
||||
@Controller
|
||||
public static class IMyControllerImpl implements IMyController {
|
||||
|
||||
@Override
|
||||
public void handle(Writer writer, @RequestParam(value="p", required=false) String param) throws IOException {
|
||||
writer.write("handle " + param);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public class Spr7766Tests {
|
||||
}
|
||||
|
||||
public class ColorConverter implements Converter<String, Color> {
|
||||
@Override
|
||||
public Color convert(String source) { if (!source.startsWith("#")) source = "#" + source; return Color.decode(source); }
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ public class Spr7839Tests {
|
||||
ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
|
||||
GenericConversionService service = new DefaultConversionService();
|
||||
service.addConverter(new Converter<String, NestedBean>() {
|
||||
@Override
|
||||
public NestedBean convert(String source) {
|
||||
return new NestedBean(source);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
*/
|
||||
public class Controller implements org.springframework.web.servlet.mvc.Controller {
|
||||
|
||||
@Override
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
|
||||
return new ModelAndView("indexView");
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public class ControllerBeanNameHandlerMappingTests extends TestCase {
|
||||
|
||||
private HandlerMapping hm;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
MockServletContext sc = new MockServletContext("");
|
||||
this.wac = new XmlWebApplicationContext();
|
||||
|
||||
@@ -42,6 +42,7 @@ public class ControllerClassNameHandlerMappingTests extends TestCase {
|
||||
|
||||
private HandlerMapping hm4;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
MockServletContext sc = new MockServletContext("");
|
||||
this.wac = new XmlWebApplicationContext();
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.web.servlet.mvc.Controller;
|
||||
*/
|
||||
public class WelcomeController implements Controller {
|
||||
|
||||
@Override
|
||||
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
|
||||
return new ModelAndView("welcomeView");
|
||||
}
|
||||
|
||||
@@ -195,6 +195,7 @@ public class RequestMappingInfoTests {
|
||||
new ParamsRequestCondition("foo"), null, null, null, null);
|
||||
|
||||
Comparator<RequestMappingInfo> comparator = new Comparator<RequestMappingInfo>() {
|
||||
@Override
|
||||
public int compare(RequestMappingInfo info, RequestMappingInfo otherInfo) {
|
||||
return info.compareTo(otherInfo, new MockHttpServletRequest());
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ public class HandlerMethodAnnotationDetectionTests {
|
||||
}
|
||||
|
||||
class TestPointcut extends StaticMethodMatcherPointcut {
|
||||
@Override
|
||||
public boolean matches(Method method, Class<?> clazz) {
|
||||
return method.getName().equals("hashCode");
|
||||
}
|
||||
@@ -202,19 +203,23 @@ public class HandlerMethodAnnotationDetectionTests {
|
||||
*/
|
||||
static class AbstractClassController extends MappingAbstractClass {
|
||||
|
||||
@Override
|
||||
public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String pattern) {
|
||||
CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(pattern), false);
|
||||
dataBinder.registerCustomEditor(Date.class, dateEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initModel(@RequestHeader("header1") Date date, Model model) {
|
||||
model.addAttribute("attr1", date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date handle(@RequestHeader("header2") Date date, Model model) throws Exception {
|
||||
return date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handleException(Exception exception) {
|
||||
return exception.getMessage();
|
||||
}
|
||||
@@ -251,19 +256,23 @@ public class HandlerMethodAnnotationDetectionTests {
|
||||
*/
|
||||
static class InterfaceController implements MappingInterface {
|
||||
|
||||
@Override
|
||||
public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) {
|
||||
CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false);
|
||||
dataBinder.registerCustomEditor(Date.class, dateEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initModel(@RequestHeader("header1") Date date, Model model) {
|
||||
model.addAttribute("attr1", date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date handle(@RequestHeader("header2") Date date, Model model) throws Exception {
|
||||
return date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handleException(Exception exception) {
|
||||
return exception.getMessage();
|
||||
}
|
||||
@@ -295,19 +304,23 @@ public class HandlerMethodAnnotationDetectionTests {
|
||||
*/
|
||||
static class ParameterizedAbstractClassController extends MappingParameterizedAbstractClass<String, Date, Date> {
|
||||
|
||||
@Override
|
||||
public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) {
|
||||
CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false);
|
||||
dataBinder.registerCustomEditor(Date.class, dateEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initModel(@RequestHeader("header1") Date date, Model model) {
|
||||
model.addAttribute("attr1", date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date handle(@RequestHeader("header2") Date date, Model model) throws Exception {
|
||||
return date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String handleException(Exception exception) {
|
||||
return exception.getMessage();
|
||||
}
|
||||
@@ -340,23 +353,27 @@ public class HandlerMethodAnnotationDetectionTests {
|
||||
*/
|
||||
static class ParameterizedInterfaceController implements MappingParameterizedInterface<String, Date, Date> {
|
||||
|
||||
@Override
|
||||
@InitBinder
|
||||
public void initBinder(WebDataBinder dataBinder, @RequestParam("datePattern") String thePattern) {
|
||||
CustomDateEditor dateEditor = new CustomDateEditor(new SimpleDateFormat(thePattern), false);
|
||||
dataBinder.registerCustomEditor(Date.class, dateEditor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ModelAttribute
|
||||
public void initModel(@RequestHeader("header1") Date date, Model model) {
|
||||
model.addAttribute("attr1", date);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequestMapping(value="/path1/path2", method=RequestMethod.POST)
|
||||
@ModelAttribute("attr2")
|
||||
public Date handle(@RequestHeader("header2") Date date, Model model) throws Exception {
|
||||
return date;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public String handleException(Exception exception) {
|
||||
@@ -412,6 +429,7 @@ public class HandlerMethodAnnotationDetectionTests {
|
||||
|
||||
private static StaticMethodMatcherPointcut getControllerPointcut() {
|
||||
return new StaticMethodMatcherPointcut() {
|
||||
@Override
|
||||
public boolean matches(Method method, Class<?> targetClass) {
|
||||
return ((AnnotationUtils.findAnnotation(targetClass, Controller.class) != null) ||
|
||||
(AnnotationUtils.findAnnotation(targetClass, RequestMapping.class) != null));
|
||||
|
||||
@@ -159,10 +159,12 @@ public class HttpEntityMethodProcessorTests {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -177,6 +179,7 @@ public class HttpEntityMethodProcessorTests {
|
||||
}
|
||||
|
||||
private final class ValidatingBinderFactory implements WebDataBinderFactory {
|
||||
@Override
|
||||
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
|
||||
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
|
||||
validator.afterPropertiesSet();
|
||||
|
||||
@@ -124,6 +124,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests {
|
||||
this.returnValueType = returnValueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public ModelAndView resolveModelAndView(Method method, Class handlerType, Object returnValue,
|
||||
ExtendedModelMap model, NativeWebRequest request) {
|
||||
|
||||
@@ -394,28 +394,33 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||
}
|
||||
|
||||
private static class StubValidator implements Validator {
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object target, Errors errors) {
|
||||
errors.reject("error");
|
||||
}
|
||||
}
|
||||
|
||||
private static class ColorArgumentResolver implements WebArgumentResolver {
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
|
||||
return new Color(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static class User implements Principal {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "user";
|
||||
}
|
||||
}
|
||||
|
||||
private static class OtherUser implements Principal {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "other user";
|
||||
}
|
||||
|
||||
@@ -275,6 +275,7 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
}
|
||||
|
||||
private final class ValidatingBinderFactory implements WebDataBinderFactory {
|
||||
@Override
|
||||
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
|
||||
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
|
||||
validator.afterPropertiesSet();
|
||||
|
||||
@@ -323,6 +323,7 @@ public class RequestResponseBodyMethodProcessorMockTests {
|
||||
}
|
||||
|
||||
private final class ValidatingBinderFactory implements WebDataBinderFactory {
|
||||
@Override
|
||||
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
|
||||
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
|
||||
validator.afterPropertiesSet();
|
||||
|
||||
@@ -259,10 +259,12 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -277,6 +279,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
}
|
||||
|
||||
private final class ValidatingBinderFactory implements WebDataBinderFactory {
|
||||
@Override
|
||||
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
|
||||
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
|
||||
validator.afterPropertiesSet();
|
||||
|
||||
@@ -243,6 +243,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void defaultExpressionParameters() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
|
||||
ppc.getPropertyValues().add("properties", "myKey=foo");
|
||||
@@ -266,6 +267,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void typeNestedSetBinding() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
|
||||
csDef.getPropertyValues().add("converters", new TestBeanConverter());
|
||||
@@ -308,6 +310,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void emptyParameterListHandleMethod() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
RootBeanDefinition vrDef = new RootBeanDefinition(InternalResourceViewResolver.class);
|
||||
vrDef.getPropertyValues().add("suffix", ".jsp");
|
||||
@@ -328,6 +331,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void sessionAttributeExposure() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
context.registerBeanDefinition("viewResolver", new RootBeanDefinition(ModelExposingViewResolver.class));
|
||||
}
|
||||
@@ -358,6 +362,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void sessionAttributeExposureWithInterface() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
context.registerBeanDefinition("viewResolver", new RootBeanDefinition(ModelExposingViewResolver.class));
|
||||
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
@@ -392,6 +397,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void parameterizedAnnotatedInterface() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
context.registerBeanDefinition("viewResolver", new RootBeanDefinition(ModelExposingViewResolver.class));
|
||||
}
|
||||
@@ -424,6 +430,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void parameterizedAnnotatedInterfaceWithOverriddenMappingsInImpl() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
context.registerBeanDefinition("viewResolver", new RootBeanDefinition(ModelExposingViewResolver.class));
|
||||
}
|
||||
@@ -508,6 +515,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void formController() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
|
||||
}
|
||||
@@ -524,6 +532,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void modelFormController() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
|
||||
}
|
||||
@@ -540,6 +549,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void proxiedFormController() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
|
||||
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
@@ -561,6 +571,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void commandProvidingFormControllerWithCustomEditor() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
@@ -581,6 +592,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void typedCommandProvidingFormController() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
@@ -620,6 +632,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void binderInitializingCommandProvidingFormController() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
|
||||
}
|
||||
@@ -637,6 +650,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void specificBinderInitializingCommandProvidingFormController() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
|
||||
}
|
||||
@@ -658,6 +672,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
WebApplicationContext webAppContext =
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
wac.setServletContext(servletContext);
|
||||
AnnotationConfigUtils.registerAnnotationConfigProcessors(wac);
|
||||
@@ -831,6 +846,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void responseBodyNoAcceptableMediaType() throws ServletException, IOException {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
StringHttpMessageConverter converter = new StringHttpMessageConverter();
|
||||
@@ -866,6 +882,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void unsupportedRequestBody() throws ServletException, IOException {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
adapterDef.getPropertyValues().add("messageConverters", new ByteArrayHttpMessageConverter());
|
||||
@@ -900,6 +917,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void badRequestRequestBody() throws ServletException, IOException {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
adapterDef.getPropertyValues().add("messageConverters", new NotReadableMessageConverter());
|
||||
@@ -946,6 +964,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void overlappingMessageConvertersRequestBody() throws ServletException, IOException {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
|
||||
@@ -980,6 +999,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void responseBodyArgMismatch() throws ServletException, IOException {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
|
||||
marshaller.setClassesToBeBound(A.class, B.class);
|
||||
@@ -1155,6 +1175,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void mavResolver() throws ServletException, IOException {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
ModelAndViewResolver[] mavResolvers = new ModelAndViewResolver[] {new MyModelAndViewResolver()};
|
||||
@@ -1283,6 +1304,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void requestMappingInterfaceWithProxy() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
|
||||
@@ -1420,6 +1442,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void parameterCsvAsStringArray() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
|
||||
RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
|
||||
@@ -1525,6 +1548,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Test
|
||||
public void prototypeController() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
RootBeanDefinition beanDef = new RootBeanDefinition(PrototypeController.class);
|
||||
beanDef.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||
@@ -1727,12 +1751,14 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
public static class MySessionAttributesControllerImpl implements MySessionAttributesControllerIfc {
|
||||
|
||||
@Override
|
||||
public String get(Model model) {
|
||||
model.addAttribute("object1", new Object());
|
||||
model.addAttribute("object2", new Object());
|
||||
return "page1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String post(@ModelAttribute("object1") Object object1) {
|
||||
//do something with object1
|
||||
return "page2";
|
||||
@@ -1759,6 +1785,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Controller
|
||||
public static class MyParameterizedControllerImpl implements MyEditableParameterizedControllerIfc<TestBean> {
|
||||
|
||||
@Override
|
||||
public List<TestBean> getTestBeans() {
|
||||
List<TestBean> list = new LinkedList<TestBean>();
|
||||
list.add(new TestBean("tb1"));
|
||||
@@ -1766,12 +1793,14 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Model model) {
|
||||
model.addAttribute("object1", new TestBean());
|
||||
model.addAttribute("object2", new TestBean());
|
||||
return "page1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String post(TestBean object) {
|
||||
//do something with object1
|
||||
return "page2";
|
||||
@@ -1781,6 +1810,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Controller
|
||||
public static class MyParameterizedControllerImplWithOverriddenMappings implements MyEditableParameterizedControllerIfc<TestBean> {
|
||||
|
||||
@Override
|
||||
@ModelAttribute("testBeanList")
|
||||
public List<TestBean> getTestBeans() {
|
||||
List<TestBean> list = new LinkedList<TestBean>();
|
||||
@@ -1789,6 +1819,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public String get(Model model) {
|
||||
model.addAttribute("object1", new TestBean());
|
||||
@@ -1796,6 +1827,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
return "page1";
|
||||
}
|
||||
|
||||
@Override
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public String post(@ModelAttribute("object1") TestBean object1) {
|
||||
//do something with object1
|
||||
@@ -1966,6 +1998,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
static class MyWebBindingInitializer implements WebBindingInitializer {
|
||||
|
||||
@Override
|
||||
public void initBinder(WebDataBinder binder, WebRequest request) {
|
||||
LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
|
||||
vf.afterPropertiesSet();
|
||||
@@ -1979,6 +2012,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
static class MySpecialArgumentResolver implements WebArgumentResolver {
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) {
|
||||
if (methodParameter.getParameterType().equals(MySpecialArg.class)) {
|
||||
return new MySpecialArg("myValue");
|
||||
@@ -2132,6 +2166,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
static class TestPrincipal implements Principal {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "test";
|
||||
}
|
||||
@@ -2139,6 +2174,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
static class OtherPrincipal implements Principal {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "other";
|
||||
}
|
||||
@@ -2146,12 +2182,15 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
static class TestViewResolver implements ViewResolver {
|
||||
|
||||
@Override
|
||||
public View resolveViewName(final String viewName, Locale locale) throws Exception {
|
||||
return new View() {
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "deprecation", "rawtypes"})
|
||||
public void render(Map model, HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
@@ -2190,11 +2229,14 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
public static class ModelExposingViewResolver implements ViewResolver {
|
||||
|
||||
@Override
|
||||
public View resolveViewName(final String viewName, Locale locale) throws Exception {
|
||||
return new View() {
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
request.setAttribute("viewName", viewName);
|
||||
request.getSession().setAttribute("model", model);
|
||||
@@ -2291,6 +2333,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
public static class TestBeanConverter implements Converter<String, ITestBean> {
|
||||
|
||||
@Override
|
||||
public ITestBean convert(String source) {
|
||||
return new TestBean(source);
|
||||
}
|
||||
@@ -2398,23 +2441,28 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
public static class NotReadableMessageConverter implements HttpMessageConverter<Object> {
|
||||
|
||||
@Override
|
||||
public boolean canRead(Class<?> clazz, MediaType mediaType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MediaType> getSupportedMediaTypes() {
|
||||
return Collections.singletonList(new MediaType("application", "pdf"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(Class<?> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
throw new HttpMessageNotReadableException("Could not read");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
@@ -2429,23 +2477,28 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
this.supportedMediaTypes = Arrays.asList(supportedMediaTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(Class<?> clazz, MediaType mediaType) {
|
||||
return supportedMediaTypes.contains(mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
|
||||
return supportedMediaTypes.contains(mediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MediaType> getSupportedMediaTypes() {
|
||||
return supportedMediaTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(Class<?> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMessageNotWritableException {
|
||||
outputMessage.getHeaders().setContentType(contentType);
|
||||
@@ -2545,6 +2598,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
|
||||
public static class MyModelAndViewResolver implements ModelAndViewResolver {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public ModelAndView resolveModelAndView(Method handlerMethod,
|
||||
Class handlerType,
|
||||
@@ -2553,10 +2607,12 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
NativeWebRequest webRequest) {
|
||||
if (returnValue instanceof MySpecialArg) {
|
||||
return new ModelAndView(new View() {
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return "text/html";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
response.getWriter().write("myValue");
|
||||
@@ -2628,6 +2684,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Controller
|
||||
public static class TestControllerImpl implements TestController<MyEntity> {
|
||||
|
||||
@Override
|
||||
@RequestMapping("/method")
|
||||
public ModelAndView method(MyEntity object) {
|
||||
return new ModelAndView("/something");
|
||||
@@ -2723,6 +2780,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
@Controller
|
||||
public static class IMyControllerImpl implements IMyController {
|
||||
|
||||
@Override
|
||||
public void handle(Writer writer, @RequestParam(value="p", required=false) String param) throws IOException {
|
||||
writer.write("handle " + param);
|
||||
}
|
||||
|
||||
@@ -185,10 +185,12 @@ public class ServletInvocableHandlerMethodTests {
|
||||
|
||||
private static class ExceptionRaisingReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
|
||||
throw new HttpMessageNotWritableException("oops, can't write");
|
||||
|
||||
@@ -95,6 +95,7 @@ public class ServletRequestMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void principal() throws Exception {
|
||||
Principal principal = new Principal() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Foo";
|
||||
}
|
||||
|
||||
@@ -107,6 +107,7 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab
|
||||
|
||||
WebApplicationContext wac =
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext context) {
|
||||
RootBeanDefinition beanDef = new RootBeanDefinition(ModelValidatingViewResolver.class);
|
||||
beanDef.getConstructorArgumentValues().addGenericArgumentValue(pathVars);
|
||||
@@ -671,8 +672,10 @@ public class UriTemplateServletAnnotationControllerHandlerMethodTests extends Ab
|
||||
this.attrsToValidate = attrsToValidate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View resolveViewName(final String viewName, Locale locale) throws Exception {
|
||||
return new AbstractView () {
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ public class RedirectAttributesModelMapTests {
|
||||
|
||||
public static class TestBeanConverter implements Converter<TestBean, String> {
|
||||
|
||||
@Override
|
||||
public String convert(TestBean source) {
|
||||
return "[" + source.getName() + "]";
|
||||
}
|
||||
|
||||
@@ -39,10 +39,12 @@ class MockFilterRegistration implements Dynamic {
|
||||
return this.asyncSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsyncSupported(boolean isAsyncSupported) {
|
||||
this.asyncSupported = isAsyncSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes,
|
||||
boolean isMatchAfter, String... servletNames) {
|
||||
|
||||
@@ -53,38 +55,47 @@ class MockFilterRegistration implements Dynamic {
|
||||
|
||||
// Not implemented
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getServletNameMappings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes,
|
||||
boolean isMatchAfter, String... urlPatterns) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getUrlPatternMappings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setInitParameter(String name, String value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> setInitParameters(Map<String, String> initParameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getInitParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -40,27 +40,33 @@ class MockServletRegistration implements ServletRegistration.Dynamic {
|
||||
return loadOnStartup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoadOnStartup(int loadOnStartup) {
|
||||
this.loadOnStartup = loadOnStartup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRunAsRole(String roleName) {
|
||||
this.roleName = roleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> addMapping(String... urlPatterns) {
|
||||
mappings.addAll(Arrays.asList(urlPatterns));
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getMappings() {
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRunAsRole() {
|
||||
return roleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsyncSupported(boolean isAsyncSupported) {
|
||||
this.asyncSupported = isAsyncSupported;
|
||||
}
|
||||
@@ -71,33 +77,41 @@ class MockServletRegistration implements ServletRegistration.Dynamic {
|
||||
|
||||
// not implemented
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMultipartConfig(MultipartConfigElement multipartConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> setServletSecurity(ServletSecurityElement constraint) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setInitParameter(String name, String value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> setInitParameters(Map<String, String> initParameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getInitParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,18 +30,22 @@ public class RequestDataValueProcessorWrapper implements RequestDataValueProcess
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processUrl(HttpServletRequest request, String url) {
|
||||
return (this.processor != null) ? this.processor.processUrl(request, url) : url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processFormFieldValue(HttpServletRequest request, String name, String value, String type) {
|
||||
return (this.processor != null) ? this.processor.processFormFieldValue(request, name, value, type) : value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processAction(HttpServletRequest request, String action) {
|
||||
return (this.processor != null) ? this.processor.processAction(request, action) : action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getExtraHiddenFields(HttpServletRequest request) {
|
||||
return (this.processor != null) ? this.processor.getExtraHiddenFields(request) : null;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.springframework.web.servlet.tags;
|
||||
*/
|
||||
public class BindTagOutsideDispatcherServletTests extends BindTagTests {
|
||||
|
||||
@Override
|
||||
protected boolean inDispatcherServlet() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -509,6 +509,7 @@ public class BindTagTests extends AbstractTagTests {
|
||||
IndexedTestBean tb = new IndexedTestBean();
|
||||
DataBinder binder = new ServletRequestDataBinder(tb, "tb");
|
||||
binder.registerCustomEditor(TestBean.class, null, new PropertyEditorSupport() {
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return "something";
|
||||
}
|
||||
@@ -987,6 +988,7 @@ public class BindTagTests extends AbstractTagTests {
|
||||
pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", binder.getBindingResult());
|
||||
|
||||
FormTag formTag = new FormTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(new StringWriter());
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class EvalTagTests extends AbstractTagTests {
|
||||
|
||||
private MockPageContext context;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
context = createPageContext();
|
||||
FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean();
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.springframework.web.servlet.tags;
|
||||
*/
|
||||
public class HtmlEscapeTagOutsideDispatcherServletTests extends HtmlEscapeTagTests {
|
||||
|
||||
@Override
|
||||
protected boolean inDispatcherServlet() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
|
||||
tag.setPageContext(pc);
|
||||
tag.doStartTag();
|
||||
HtmlEscapingAwareTag testTag = new HtmlEscapingAwareTag() {
|
||||
@Override
|
||||
public int doStartTagInternal() throws Exception {
|
||||
return EVAL_BODY_INCLUDE;
|
||||
}
|
||||
@@ -113,9 +114,11 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer result = new StringBuffer();
|
||||
EscapeBodyTag tag = new EscapeBodyTag() {
|
||||
@Override
|
||||
protected String readBodyContent() {
|
||||
return "test text";
|
||||
}
|
||||
@Override
|
||||
protected void writeBodyContent(String content) {
|
||||
result.append(content);
|
||||
}
|
||||
@@ -131,9 +134,11 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer result = new StringBuffer();
|
||||
EscapeBodyTag tag = new EscapeBodyTag() {
|
||||
@Override
|
||||
protected String readBodyContent() {
|
||||
return "test & text";
|
||||
}
|
||||
@Override
|
||||
protected void writeBodyContent(String content) {
|
||||
result.append(content);
|
||||
}
|
||||
@@ -150,9 +155,11 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer result = new StringBuffer();
|
||||
EscapeBodyTag tag = new EscapeBodyTag() {
|
||||
@Override
|
||||
protected String readBodyContent() {
|
||||
return "' test & text \\";
|
||||
}
|
||||
@Override
|
||||
protected void writeBodyContent(String content) {
|
||||
result.append(content);
|
||||
}
|
||||
@@ -169,9 +176,11 @@ public class HtmlEscapeTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer result = new StringBuffer();
|
||||
EscapeBodyTag tag = new EscapeBodyTag() {
|
||||
@Override
|
||||
protected String readBodyContent() {
|
||||
return "' test & text \\";
|
||||
}
|
||||
@Override
|
||||
protected void writeBodyContent(String content) {
|
||||
result.append(content);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.springframework.web.servlet.tags;
|
||||
*/
|
||||
public class MessageTagOutsideDispatcherServletTests extends MessageTagTests {
|
||||
|
||||
@Override
|
||||
protected boolean inDispatcherServlet() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -58,6 +59,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -74,6 +76,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -91,6 +94,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
request.addPreferredLocale(Locale.CANADA);
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -108,6 +112,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -123,6 +128,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -139,6 +145,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -155,6 +162,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -172,6 +180,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -188,6 +197,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -204,6 +214,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -221,6 +232,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -239,6 +251,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -256,6 +269,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -274,6 +288,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -290,6 +305,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -307,6 +323,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -323,6 +340,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -341,6 +359,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
@@ -357,6 +376,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
MessageTag tag = new MessageTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ public class ParamTagTests extends AbstractTagTests {
|
||||
|
||||
private Param param;
|
||||
|
||||
@Override
|
||||
public void addParam(Param param) {
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class ThemeTagTests extends AbstractTagTests {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
ThemeTag tag = new ThemeTag() {
|
||||
@Override
|
||||
protected void writeMessage(String msg) {
|
||||
message.append(msg);
|
||||
}
|
||||
|
||||
@@ -31,12 +31,14 @@ public abstract class AbstractFormTagTests extends AbstractHtmlElementTagTests {
|
||||
private FormTag formTag = new FormTag();
|
||||
|
||||
|
||||
@Override
|
||||
protected void extendRequest(MockHttpServletRequest request) {
|
||||
request.setAttribute(COMMAND_NAME, createTestBean());
|
||||
}
|
||||
|
||||
protected abstract TestBean createTestBean();
|
||||
|
||||
@Override
|
||||
protected void extendPageContext(MockPageContext pageContext) throws JspException {
|
||||
this.formTag.setCommandName(COMMAND_NAME);
|
||||
this.formTag.setAction("myAction");
|
||||
|
||||
@@ -53,6 +53,7 @@ public abstract class AbstractHtmlElementTagTests extends AbstractTagTests {
|
||||
private MockPageContext pageContext;
|
||||
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
// set up a writer for the tag content to be written to
|
||||
this.writer = new StringWriter();
|
||||
|
||||
@@ -29,6 +29,7 @@ public class ButtonTagTests extends AbstractFormTagTests {
|
||||
|
||||
private ButtonTag tag;
|
||||
|
||||
@Override
|
||||
protected void onSetUp() {
|
||||
this.tag = createTag(getWriter());
|
||||
this.tag.setParent(getFormTag());
|
||||
@@ -82,6 +83,7 @@ public class ButtonTagTests extends AbstractFormTagTests {
|
||||
@SuppressWarnings("serial")
|
||||
protected ButtonTag createTag(final Writer writer) {
|
||||
return new ButtonTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(writer);
|
||||
}
|
||||
|
||||
@@ -50,9 +50,11 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
|
||||
private TestBean bean;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new CheckboxTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -636,6 +638,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
List colours = new ArrayList();
|
||||
colours.add(Colour.BLUE);
|
||||
@@ -678,6 +681,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) {
|
||||
this.count++;
|
||||
super.setAsText(text);
|
||||
@@ -689,6 +693,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
|
||||
public int count = 0;
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) {
|
||||
this.count++;
|
||||
setValue(new Integer(text.trim()));
|
||||
|
||||
@@ -59,9 +59,11 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
|
||||
private TestBean bean;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new CheckboxesTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -426,9 +428,11 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
|
||||
FormattingConversionService cs = new FormattingConversionService();
|
||||
cs.addFormatterForFieldType(String.class, new Formatter<String>() {
|
||||
@Override
|
||||
public String print(String object, Locale locale) {
|
||||
return object;
|
||||
}
|
||||
@Override
|
||||
public String parse(String text, Locale locale) throws ParseException {
|
||||
return text.trim();
|
||||
}
|
||||
@@ -728,6 +732,7 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
List colours = new ArrayList();
|
||||
colours.add(Colour.BLUE);
|
||||
@@ -770,6 +775,7 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) {
|
||||
super.setAsText(text);
|
||||
this.allProcessedValues.add(getValue());
|
||||
@@ -779,10 +785,12 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
|
||||
private static class MyLowerCaseEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(text.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ObjectUtils.nullSafeToString(getValue()).toUpperCase();
|
||||
}
|
||||
|
||||
@@ -48,9 +48,11 @@ public class ErrorsTagTests extends AbstractFormTagTests {
|
||||
private ErrorsTag tag;
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new ErrorsTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -60,6 +62,7 @@ public class ErrorsTagTests extends AbstractFormTagTests {
|
||||
this.tag.setPageContext(getPageContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
return new TestBean();
|
||||
}
|
||||
@@ -434,6 +437,7 @@ public class ErrorsTagTests extends AbstractFormTagTests {
|
||||
assertTrue(output.contains("field error"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void exposeBindingResult(Errors errors) {
|
||||
// wrap errors in a Model
|
||||
Map model = new HashMap();
|
||||
|
||||
@@ -47,9 +47,11 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new FormTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
|
||||
@@ -31,9 +31,11 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||
|
||||
private TestBean bean;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new HiddenInputTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -120,6 +122,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||
assertTrue(output.startsWith("<input "));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
this.bean = new TestBean();
|
||||
bean.setName("Sally Greenwood");
|
||||
|
||||
@@ -39,12 +39,14 @@ public class InputTagTests extends AbstractFormTagTests {
|
||||
private TestBean rob;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSetUp() {
|
||||
this.tag = createTag(getWriter());
|
||||
this.tag.setParent(getFormTag());
|
||||
this.tag.setPageContext(getPageContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
// set up test data
|
||||
this.rob = new TestBean();
|
||||
@@ -388,6 +390,7 @@ public class InputTagTests extends AbstractFormTagTests {
|
||||
@SuppressWarnings("serial")
|
||||
protected InputTag createTag(final Writer writer) {
|
||||
return new InputTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(writer);
|
||||
}
|
||||
|
||||
@@ -59,10 +59,12 @@ public class ItemPet {
|
||||
|
||||
public static class CustomEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(new ItemPet(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ((ItemPet) getValue()).getName();
|
||||
}
|
||||
|
||||
@@ -34,9 +34,11 @@ public class LabelTagTests extends AbstractFormTagTests {
|
||||
private LabelTag tag;
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new LabelTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -44,6 +46,7 @@ public class LabelTagTests extends AbstractFormTagTests {
|
||||
this.tag.setPageContext(getPageContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extendPageContext(MockPageContext pageContext) throws JspException {
|
||||
super.extendPageContext(pageContext);
|
||||
|
||||
@@ -139,6 +142,7 @@ public class LabelTagTests extends AbstractFormTagTests {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
TestBean bean = new TestBean();
|
||||
bean.setSpouse(new TestBean("Hoopy"));
|
||||
|
||||
@@ -32,14 +32,17 @@ public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
private SelectTag parentTag;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new OptionTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
};
|
||||
this.parentTag = new SelectTag() {
|
||||
@Override
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
|
||||
@@ -51,14 +51,17 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
private SelectTag parentTag;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new OptionTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
};
|
||||
this.parentTag = new SelectTag() {
|
||||
@Override
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
@@ -239,6 +242,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
public void testWithPropertyEditor() throws Exception {
|
||||
String selectName = "testBean.stringArray";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
@Override
|
||||
public PropertyEditor getEditor() {
|
||||
return new StringArrayPropertyEditor();
|
||||
}
|
||||
@@ -268,6 +272,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
testBeanEditor.setValue(new TestBean("Sally"));
|
||||
String selectName = "testBean.spouse";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
@Override
|
||||
public PropertyEditor getEditor() {
|
||||
return testBeanEditor;
|
||||
}
|
||||
@@ -332,6 +337,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
floatEditor.setValue(new Float("12.34"));
|
||||
String selectName = "testBean.someNumber";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
@Override
|
||||
public PropertyEditor getEditor() {
|
||||
return floatEditor;
|
||||
}
|
||||
@@ -357,6 +363,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
final PropertyEditor floatEditor = new SimpleFloatEditor();
|
||||
String selectName = "testBean.someNumber";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
@Override
|
||||
public PropertyEditor getEditor() {
|
||||
return floatEditor;
|
||||
}
|
||||
@@ -443,6 +450,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
public void testAsBodyTagWithEditor() throws Exception {
|
||||
String selectName = "testBean.stringArray";
|
||||
BindStatus bindStatus = new BindStatus(getRequestContext(), selectName, false) {
|
||||
@Override
|
||||
public PropertyEditor getEditor() {
|
||||
return new RulesVariantEditor();
|
||||
}
|
||||
@@ -499,6 +507,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
assertTrue(output.endsWith("</option>"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extendRequest(MockHttpServletRequest request) {
|
||||
TestBean bean = new TestBean();
|
||||
bean.setName("foo");
|
||||
@@ -520,10 +529,12 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
private static class TestBeanPropertyEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(new TestBean(text + "k", 123));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ((TestBean) getValue()).getName();
|
||||
}
|
||||
@@ -589,10 +600,12 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
public class RulesVariantEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(RulesVariant.fromId(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
RulesVariant rulesVariant = (RulesVariant) getValue();
|
||||
return rulesVariant.toId();
|
||||
@@ -602,11 +615,13 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
private static class FriendEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(new TestBean(text));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ((TestBean) getValue()).getName();
|
||||
}
|
||||
|
||||
@@ -54,17 +54,21 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
private SelectTag selectTag;
|
||||
private OptionsTag tag;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new OptionsTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
};
|
||||
selectTag = new SelectTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
@@ -276,6 +280,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
assertEquals(value2, rootElement.selectSingleNode("option[@selected]"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extendRequest(MockHttpServletRequest request) {
|
||||
TestBean bean = new TestBean();
|
||||
bean.setName("foo");
|
||||
@@ -295,6 +300,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
request.setAttribute("floats", floats);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void exposeBindingResult(Errors errors) {
|
||||
// wrap errors in a Model
|
||||
Map model = new HashMap();
|
||||
|
||||
@@ -78,6 +78,7 @@ public class PasswordInputTagTests extends InputTagTests {
|
||||
assertValueAttribute(output, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.getTag().setDynamicAttribute(null, "type", "email");
|
||||
@@ -88,6 +89,7 @@ public class PasswordInputTagTests extends InputTagTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertValueAttribute(String output, String expectedValue) {
|
||||
if (this.getPasswordTag().isShowPassword()) {
|
||||
super.assertValueAttribute(output, expectedValue);
|
||||
@@ -96,13 +98,16 @@ public class PasswordInputTagTests extends InputTagTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getType() {
|
||||
return "password";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected InputTag createTag(final Writer writer) {
|
||||
return new PasswordInputTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(writer);
|
||||
}
|
||||
|
||||
@@ -43,9 +43,11 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
|
||||
|
||||
private TestBean bean;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new RadioButtonTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -251,6 +253,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
|
||||
return new Float("12.99");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
this.bean = new TestBean();
|
||||
bean.setSex("M");
|
||||
@@ -262,10 +265,12 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
|
||||
|
||||
private static class MyFloatEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(text.substring(1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return "F" + getValue();
|
||||
}
|
||||
|
||||
@@ -53,9 +53,11 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
|
||||
private TestBean bean;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new RadioButtonsTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -582,6 +584,7 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
List colours = new ArrayList();
|
||||
colours.add(Colour.BLUE);
|
||||
@@ -619,6 +622,7 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) {
|
||||
super.setAsText(text);
|
||||
this.allProcessedValues.add(getValue());
|
||||
|
||||
@@ -64,9 +64,11 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
private TestBeanWithRealCountry bean;
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new SelectTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -175,9 +177,11 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
this.tag.setItems("${countries}");
|
||||
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), "testBean");
|
||||
bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(Country.getCountryWithIsoCode(text));
|
||||
}
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ((Country) getValue()).getName();
|
||||
}
|
||||
@@ -203,9 +207,11 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
this.tag.setItemLabel("name");
|
||||
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), "testBean");
|
||||
bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(Country.getCountryWithIsoCode(text));
|
||||
}
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ((Country) getValue()).getName();
|
||||
}
|
||||
@@ -230,6 +236,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
testBean.setBean(withCountry);
|
||||
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(testBean , "testBean");
|
||||
bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
if (text==null || text.length()==0) {
|
||||
setValue(null);
|
||||
@@ -237,6 +244,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
}
|
||||
setValue(Country.getCountryWithIsoCode(text));
|
||||
}
|
||||
@Override
|
||||
public String getAsText() {
|
||||
Country value = (Country) getValue();
|
||||
if (value==null) {
|
||||
@@ -263,9 +271,11 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
testBean.setBean(getTestBean());
|
||||
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(testBean , "testBean");
|
||||
bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(Country.getCountryWithIsoCode(text));
|
||||
}
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ((Country) getValue()).getName();
|
||||
}
|
||||
@@ -287,9 +297,11 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
testBean.setRealCountry(null);
|
||||
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(testBean, "testBean");
|
||||
bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(Country.getCountryWithIsoCode(text));
|
||||
}
|
||||
@Override
|
||||
public String getAsText() {
|
||||
Country value = (Country) getValue();
|
||||
if (value==null) {
|
||||
@@ -470,9 +482,11 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
|
||||
FormattingConversionService cs = new FormattingConversionService();
|
||||
cs.addFormatterForFieldType(Country.class, new Formatter<Country>() {
|
||||
@Override
|
||||
public String print(Country object, Locale locale) {
|
||||
return object.getName();
|
||||
}
|
||||
@Override
|
||||
public Country parse(String text, Locale locale) throws ParseException {
|
||||
return new Country(text, text);
|
||||
}
|
||||
@@ -515,9 +529,11 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
|
||||
FormattingConversionService cs = new FormattingConversionService();
|
||||
cs.addFormatterForFieldType(Country.class, new Formatter<Country>() {
|
||||
@Override
|
||||
public String print(Country object, Locale locale) {
|
||||
return object.getName();
|
||||
}
|
||||
@Override
|
||||
public Country parse(String text, Locale locale) throws ParseException {
|
||||
return new Country(text, text);
|
||||
}
|
||||
@@ -563,6 +579,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
|
||||
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(this.bean, COMMAND_NAME);
|
||||
errors.getPropertyAccessor().registerCustomEditor(List.class, new CustomCollectionEditor(LinkedList.class) {
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return getValue().toString();
|
||||
}
|
||||
@@ -671,10 +688,12 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(getTestBean(), COMMAND_NAME);
|
||||
bindingResult.getPropertyAccessor().registerCustomEditor(Country.class, new PropertyEditorSupport() {
|
||||
|
||||
@Override
|
||||
public void setAsText(final String text) throws IllegalArgumentException {
|
||||
setValue(Country.getCountryWithIsoCode(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ((Country) getValue()).getIsoCode();
|
||||
}
|
||||
@@ -772,6 +791,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
|
||||
private Map getCountryToLocaleMap() {
|
||||
Map map = new TreeMap(new Comparator() {
|
||||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
return ((Country)o1).getName().compareTo(((Country)o2).getName());
|
||||
}
|
||||
@@ -793,6 +813,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
return sexes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void extendRequest(MockHttpServletRequest request) {
|
||||
super.extendRequest(request);
|
||||
request.setAttribute("countries", Country.getCountries());
|
||||
@@ -834,6 +855,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
this.bean = new TestBeanWithRealCountry();
|
||||
this.bean.setName("Rob");
|
||||
|
||||
@@ -24,10 +24,12 @@ import java.beans.PropertyEditorSupport;
|
||||
*/
|
||||
class SimpleFloatEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(new Float(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return getValue() + "f";
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ public class TagWriterTests extends TestCase {
|
||||
private StringWriter data;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
this.data = new StringWriter();
|
||||
this.writer = new TagWriter(this.data);
|
||||
|
||||
@@ -33,9 +33,11 @@ public class TextareaTagTests extends AbstractFormTagTests {
|
||||
|
||||
private TestBean rob;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("serial")
|
||||
protected void onSetUp() {
|
||||
this.tag = new TextareaTag() {
|
||||
@Override
|
||||
protected TagWriter createTagWriter() {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
@@ -110,6 +112,7 @@ public class TextareaTagTests extends AbstractFormTagTests {
|
||||
assertBlockTagContains(output, "12.34f");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
// set up test data
|
||||
this.rob = new TestBean();
|
||||
|
||||
@@ -309,6 +309,7 @@ public class BaseViewTests extends TestCase {
|
||||
*/
|
||||
private class ConcreteView extends AbstractView {
|
||||
// Do-nothing concrete subclass
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -330,6 +331,7 @@ public class BaseViewTests extends TestCase {
|
||||
this.wac = wac;
|
||||
|
||||
}
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
// do nothing
|
||||
@@ -338,6 +340,7 @@ public class BaseViewTests extends TestCase {
|
||||
/**
|
||||
* @see org.springframework.context.support.ApplicationObjectSupport#initApplicationContext()
|
||||
*/
|
||||
@Override
|
||||
protected void initApplicationContext() throws ApplicationContextException {
|
||||
if (inited)
|
||||
throw new RuntimeException("Already initialized");
|
||||
|
||||
@@ -73,6 +73,7 @@ public class InternalResourceViewTests extends TestCase {
|
||||
InternalResourceView view = new InternalResourceView();
|
||||
view.setUrl(url);
|
||||
view.setServletContext(new MockServletContext() {
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
return 4;
|
||||
}
|
||||
@@ -118,6 +119,7 @@ public class InternalResourceViewTests extends TestCase {
|
||||
InternalResourceView view = new InternalResourceView();
|
||||
view.setUrl(url);
|
||||
view.setServletContext(new MockServletContext() {
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.springframework.web.servlet.view;
|
||||
*/
|
||||
public class ResourceBundleViewResolverNoCacheTests extends ResourceBundleViewResolverTests {
|
||||
|
||||
@Override
|
||||
protected boolean getCache() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public class ResourceBundleViewResolverTests extends TestCase {
|
||||
private StaticWebApplicationContext wac;
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
rb = new ResourceBundleViewResolver();
|
||||
rb.setBasename(PROPS_FILE);
|
||||
@@ -170,9 +171,11 @@ public class ResourceBundleViewResolverTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initApplicationContext() {
|
||||
++initCount;
|
||||
}
|
||||
|
||||
@@ -249,8 +249,10 @@ public class ViewResolverTests {
|
||||
vr.setApplicationContext(wac);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(sc) {
|
||||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String path) {
|
||||
return new MockRequestDispatcher(path) {
|
||||
@Override
|
||||
public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
|
||||
assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
|
||||
assertEquals("value1", forwardRequest.getAttribute("key1"));
|
||||
@@ -287,8 +289,10 @@ public class ViewResolverTests {
|
||||
vr.setApplicationContext(wac);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(sc) {
|
||||
@Override
|
||||
public RequestDispatcher getRequestDispatcher(String path) {
|
||||
return new MockRequestDispatcher(path) {
|
||||
@Override
|
||||
public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
|
||||
assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
|
||||
assertEquals("value1", forwardRequest.getAttribute("key1"));
|
||||
@@ -432,6 +436,7 @@ public class ViewResolverTests {
|
||||
@Test
|
||||
public void testXmlViewResolverDefaultLocation() {
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext() {
|
||||
@Override
|
||||
protected Resource getResourceByPath(String path) {
|
||||
assertTrue("Correct default location", XmlViewResolver.DEFAULT_LOCATION.equals(path));
|
||||
return super.getResourceByPath(path);
|
||||
@@ -453,6 +458,7 @@ public class ViewResolverTests {
|
||||
@Test
|
||||
public void testXmlViewResolverWithoutCache() throws Exception {
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext() {
|
||||
@Override
|
||||
protected Resource getResourceByPath(String path) {
|
||||
assertTrue("Correct default location", XmlViewResolver.DEFAULT_LOCATION.equals(path));
|
||||
return super.getResourceByPath(path);
|
||||
|
||||
@@ -57,6 +57,7 @@ public class ExcelViewTests extends TestCase {
|
||||
private MockHttpServletResponse response;
|
||||
private StaticWebApplicationContext webAppCtx;
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
servletCtx = new MockServletContext("org/springframework/web/servlet/view/document");
|
||||
request = new MockHttpServletRequest(servletCtx);
|
||||
@@ -67,6 +68,7 @@ public class ExcelViewTests extends TestCase {
|
||||
|
||||
public void testExcel() throws Exception {
|
||||
AbstractExcelView excelView = new AbstractExcelView() {
|
||||
@Override
|
||||
protected void buildExcelDocument(Map model, HSSFWorkbook wb,
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
@@ -101,6 +103,7 @@ public class ExcelViewTests extends TestCase {
|
||||
newDummyLocaleResolver("nl", "nl"));
|
||||
|
||||
AbstractExcelView excelView = new AbstractExcelView() {
|
||||
@Override
|
||||
protected void buildExcelDocument(Map model, HSSFWorkbook wb,
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
@@ -135,6 +138,7 @@ public class ExcelViewTests extends TestCase {
|
||||
newDummyLocaleResolver("en", "US"));
|
||||
|
||||
AbstractExcelView excelView = new AbstractExcelView() {
|
||||
@Override
|
||||
protected void buildExcelDocument(Map model, HSSFWorkbook wb,
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
@@ -169,6 +173,7 @@ public class ExcelViewTests extends TestCase {
|
||||
newDummyLocaleResolver("de", ""));
|
||||
|
||||
AbstractExcelView excelView = new AbstractExcelView() {
|
||||
@Override
|
||||
protected void buildExcelDocument(Map model, HSSFWorkbook wb,
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
@@ -200,6 +205,7 @@ public class ExcelViewTests extends TestCase {
|
||||
|
||||
public void testJExcel() throws Exception {
|
||||
AbstractJExcelView excelView = new AbstractJExcelView() {
|
||||
@Override
|
||||
protected void buildExcelDocument(Map model,
|
||||
WritableWorkbook wb,
|
||||
HttpServletRequest request,
|
||||
@@ -229,6 +235,7 @@ public class ExcelViewTests extends TestCase {
|
||||
newDummyLocaleResolver("nl", "nl"));
|
||||
|
||||
AbstractJExcelView excelView = new AbstractJExcelView() {
|
||||
@Override
|
||||
protected void buildExcelDocument(Map model,
|
||||
WritableWorkbook wb,
|
||||
HttpServletRequest request,
|
||||
@@ -259,6 +266,7 @@ public class ExcelViewTests extends TestCase {
|
||||
newDummyLocaleResolver("en", "US"));
|
||||
|
||||
AbstractJExcelView excelView = new AbstractJExcelView() {
|
||||
@Override
|
||||
protected void buildExcelDocument(Map model,
|
||||
WritableWorkbook wb,
|
||||
HttpServletRequest request,
|
||||
@@ -289,6 +297,7 @@ public class ExcelViewTests extends TestCase {
|
||||
newDummyLocaleResolver("de", ""));
|
||||
|
||||
AbstractJExcelView excelView = new AbstractJExcelView() {
|
||||
@Override
|
||||
protected void buildExcelDocument(Map model,
|
||||
WritableWorkbook wb,
|
||||
HttpServletRequest request,
|
||||
@@ -316,10 +325,12 @@ public class ExcelViewTests extends TestCase {
|
||||
|
||||
private LocaleResolver newDummyLocaleResolver(final String lang, final String country) {
|
||||
return new LocaleResolver() {
|
||||
@Override
|
||||
public Locale resolveLocale(HttpServletRequest request) {
|
||||
return new Locale(lang, country);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocale(HttpServletRequest request,
|
||||
HttpServletResponse response, Locale locale) {
|
||||
// not supported!
|
||||
|
||||
@@ -44,6 +44,7 @@ public class PdfViewTests extends TestCase {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
AbstractPdfView pdfView = new AbstractPdfView() {
|
||||
@Override
|
||||
protected void buildPdfDocument(Map model, Document document, PdfWriter writer,
|
||||
HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
document.add(new Paragraph(text));
|
||||
|
||||
@@ -85,12 +85,14 @@ public class FreeMarkerConfigurerTests extends TestCase {
|
||||
settings.setProperty("localized_lookup", "false");
|
||||
fcfb.setFreemarkerSettings(settings);
|
||||
fcfb.setResourceLoader(new ResourceLoader() {
|
||||
@Override
|
||||
public Resource getResource(String location) {
|
||||
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
|
||||
throw new IllegalArgumentException(location);
|
||||
}
|
||||
return new ByteArrayResource("test".getBytes(), "test");
|
||||
}
|
||||
@Override
|
||||
public ClassLoader getClassLoader() {
|
||||
return getClass().getClassLoader();
|
||||
}
|
||||
|
||||
@@ -202,9 +202,11 @@ public class FreeMarkerViewTests {
|
||||
|
||||
private class TestConfiguration extends Configuration {
|
||||
|
||||
@Override
|
||||
public Template getTemplate(String name, final Locale locale) throws IOException {
|
||||
if (name.equals("templateName") || name.equals("prefix_test_suffix")) {
|
||||
return new Template(name, new StringReader("test")) {
|
||||
@Override
|
||||
public void process(Object model, Writer writer) throws TemplateException, IOException {
|
||||
assertEquals(Locale.US, locale);
|
||||
assertTrue(model instanceof AllHttpScopesHashModel);
|
||||
|
||||
@@ -54,6 +54,7 @@ public abstract class AbstractJasperReportsTests extends TestCase {
|
||||
protected MockHttpServletResponse response;
|
||||
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user