removed dependency on Servlet API mocks
This commit is contained in:
parent
ac8f37439b
commit
f0dbfeb791
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2008 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,7 +19,6 @@ package org.springframework.web.portlet;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.portlet.PortletContext;
|
import javax.portlet.PortletContext;
|
||||||
import javax.portlet.PortletException;
|
import javax.portlet.PortletException;
|
||||||
import javax.portlet.PortletMode;
|
import javax.portlet.PortletMode;
|
||||||
|
|
@ -34,8 +33,6 @@ import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.i18n.LocaleContext;
|
import org.springframework.context.i18n.LocaleContext;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
|
||||||
import org.springframework.mock.web.MockServletContext;
|
|
||||||
import org.springframework.mock.web.portlet.MockActionRequest;
|
import org.springframework.mock.web.portlet.MockActionRequest;
|
||||||
import org.springframework.mock.web.portlet.MockActionResponse;
|
import org.springframework.mock.web.portlet.MockActionResponse;
|
||||||
import org.springframework.mock.web.portlet.MockPortletConfig;
|
import org.springframework.mock.web.portlet.MockPortletConfig;
|
||||||
|
|
@ -46,12 +43,12 @@ import org.springframework.mock.web.portlet.MockRenderResponse;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.context.request.RequestAttributes;
|
import org.springframework.web.context.request.RequestAttributes;
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||||
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||||
import org.springframework.web.portlet.context.PortletApplicationContextUtils;
|
import org.springframework.web.portlet.context.PortletApplicationContextUtils;
|
||||||
import org.springframework.web.portlet.context.PortletConfigAwareBean;
|
import org.springframework.web.portlet.context.PortletConfigAwareBean;
|
||||||
import org.springframework.web.portlet.context.PortletContextAwareBean;
|
import org.springframework.web.portlet.context.PortletContextAwareBean;
|
||||||
|
import org.springframework.web.portlet.context.PortletRequestAttributes;
|
||||||
import org.springframework.web.portlet.handler.PortletSessionRequiredException;
|
import org.springframework.web.portlet.handler.PortletSessionRequiredException;
|
||||||
import org.springframework.web.portlet.multipart.MultipartActionRequest;
|
import org.springframework.web.portlet.multipart.MultipartActionRequest;
|
||||||
import org.springframework.web.portlet.multipart.PortletMultipartResolver;
|
import org.springframework.web.portlet.multipart.PortletMultipartResolver;
|
||||||
|
|
@ -810,22 +807,20 @@ public class DispatcherPortletTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testValidActionRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
|
public void testValidActionRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
|
||||||
MockServletContext servletContext = new MockServletContext();
|
MockActionRequest request = new MockActionRequest();
|
||||||
MockHttpServletRequest httpRequest = new MockHttpServletRequest(servletContext);
|
MockActionResponse response = new MockActionResponse();
|
||||||
httpRequest.addPreferredLocale(Locale.GERMAN);
|
request.addPreferredLocale(Locale.GERMAN);
|
||||||
|
request.setParameter("action", "form");
|
||||||
|
request.setParameter("age", "29");
|
||||||
|
|
||||||
// see RequestContextListener.requestInitialized()
|
// see RequestContextListener.requestInitialized()
|
||||||
try {
|
try {
|
||||||
LocaleContextHolder.setLocale(httpRequest.getLocale());
|
LocaleContextHolder.setLocale(request.getLocale());
|
||||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpRequest));
|
RequestContextHolder.setRequestAttributes(new PortletRequestAttributes(request));
|
||||||
|
|
||||||
LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
|
LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
|
||||||
RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();
|
RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();
|
||||||
|
|
||||||
MockActionRequest request = new MockActionRequest();
|
|
||||||
MockActionResponse response = new MockActionResponse();
|
|
||||||
request.setParameter("action", "form");
|
|
||||||
request.setParameter("age", "29");
|
|
||||||
simpleDispatcherPortlet.processAction(request, response);
|
simpleDispatcherPortlet.processAction(request, response);
|
||||||
|
|
||||||
assertSame(servletLocaleContext, LocaleContextHolder.getLocaleContext());
|
assertSame(servletLocaleContext, LocaleContextHolder.getLocaleContext());
|
||||||
|
|
@ -838,20 +833,18 @@ public class DispatcherPortletTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testValidRenderRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
|
public void testValidRenderRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
|
||||||
MockServletContext servletContext = new MockServletContext();
|
MockRenderRequest request = new MockRenderRequest();
|
||||||
MockHttpServletRequest httpRequest = new MockHttpServletRequest(servletContext);
|
MockRenderResponse response = new MockRenderResponse();
|
||||||
httpRequest.addPreferredLocale(Locale.GERMAN);
|
request.addPreferredLocale(Locale.GERMAN);
|
||||||
|
|
||||||
// see RequestContextListener.requestInitialized()
|
// see RequestContextListener.requestInitialized()
|
||||||
try {
|
try {
|
||||||
LocaleContextHolder.setLocale(httpRequest.getLocale());
|
LocaleContextHolder.setLocale(request.getLocale());
|
||||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpRequest));
|
RequestContextHolder.setRequestAttributes(new PortletRequestAttributes(request));
|
||||||
|
|
||||||
LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
|
LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
|
||||||
RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();
|
RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();
|
||||||
|
|
||||||
MockRenderRequest request = new MockRenderRequest();
|
|
||||||
MockRenderResponse response = new MockRenderResponse();
|
|
||||||
request.setParameter("action", "form");
|
request.setParameter("action", "form");
|
||||||
request.setParameter("age", "29");
|
request.setParameter("age", "29");
|
||||||
simpleDispatcherPortlet.doDispatch(request, response);
|
simpleDispatcherPortlet.doDispatch(request, response);
|
||||||
|
|
@ -866,20 +859,18 @@ public class DispatcherPortletTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInvalidActionRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
|
public void testInvalidActionRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
|
||||||
MockServletContext servletContext = new MockServletContext();
|
MockActionRequest request = new MockActionRequest();
|
||||||
MockHttpServletRequest httpRequest = new MockHttpServletRequest(servletContext);
|
MockActionResponse response = new MockActionResponse();
|
||||||
httpRequest.addPreferredLocale(Locale.GERMAN);
|
request.addPreferredLocale(Locale.GERMAN);
|
||||||
|
|
||||||
// see RequestContextListener.requestInitialized()
|
// see RequestContextListener.requestInitialized()
|
||||||
try {
|
try {
|
||||||
LocaleContextHolder.setLocale(httpRequest.getLocale());
|
LocaleContextHolder.setLocale(request.getLocale());
|
||||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpRequest));
|
RequestContextHolder.setRequestAttributes(new PortletRequestAttributes(request));
|
||||||
|
|
||||||
LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
|
LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
|
||||||
RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();
|
RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();
|
||||||
|
|
||||||
MockActionRequest request = new MockActionRequest();
|
|
||||||
MockActionResponse response = new MockActionResponse();
|
|
||||||
request.setParameter("action", "invalid");
|
request.setParameter("action", "invalid");
|
||||||
simpleDispatcherPortlet.processAction(request, response);
|
simpleDispatcherPortlet.processAction(request, response);
|
||||||
String exceptionParam = response.getRenderParameter(DispatcherPortlet.ACTION_EXCEPTION_RENDER_PARAMETER);
|
String exceptionParam = response.getRenderParameter(DispatcherPortlet.ACTION_EXCEPTION_RENDER_PARAMETER);
|
||||||
|
|
@ -895,20 +886,18 @@ public class DispatcherPortletTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInvalidRenderRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
|
public void testInvalidRenderRequestWithExistingThreadLocalRequestContext() throws IOException, PortletException {
|
||||||
MockServletContext servletContext = new MockServletContext();
|
MockRenderRequest request = new MockRenderRequest();
|
||||||
MockHttpServletRequest httpRequest = new MockHttpServletRequest(servletContext);
|
MockRenderResponse response = new MockRenderResponse();
|
||||||
httpRequest.addPreferredLocale(Locale.GERMAN);
|
request.addPreferredLocale(Locale.GERMAN);
|
||||||
|
|
||||||
// see RequestContextListener.requestInitialized()
|
// see RequestContextListener.requestInitialized()
|
||||||
try {
|
try {
|
||||||
LocaleContextHolder.setLocale(httpRequest.getLocale());
|
LocaleContextHolder.setLocale(request.getLocale());
|
||||||
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpRequest));
|
RequestContextHolder.setRequestAttributes(new PortletRequestAttributes(request));
|
||||||
|
|
||||||
LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
|
LocaleContext servletLocaleContext = LocaleContextHolder.getLocaleContext();
|
||||||
RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();
|
RequestAttributes servletRequestAttrs = RequestContextHolder.getRequestAttributes();
|
||||||
|
|
||||||
MockRenderRequest request = new MockRenderRequest();
|
|
||||||
MockRenderResponse response = new MockRenderResponse();
|
|
||||||
try {
|
try {
|
||||||
simpleDispatcherPortlet.doDispatch(request, response);
|
simpleDispatcherPortlet.doDispatch(request, response);
|
||||||
fail("should have failed to find a handler and raised an UnavailableException");
|
fail("should have failed to find a handler and raised an UnavailableException");
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 the original author or authors.
|
* Copyright 2002-2008 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
|
@ -17,21 +17,15 @@
|
||||||
package org.springframework.web.portlet.context;
|
package org.springframework.web.portlet.context;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
||||||
import org.springframework.context.AbstractApplicationContextTests;
|
import org.springframework.context.AbstractApplicationContextTests;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.NoSuchMessageException;
|
import org.springframework.context.NoSuchMessageException;
|
||||||
import org.springframework.context.TestListener;
|
import org.springframework.context.TestListener;
|
||||||
import org.springframework.mock.web.MockServletContext;
|
|
||||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||||
import org.springframework.web.context.support.XmlWebApplicationContext;
|
import org.springframework.web.context.support.XmlWebApplicationContext;
|
||||||
|
|
||||||
|
|
@ -48,36 +42,6 @@ public abstract class AbstractXmlWebApplicationContextTests extends AbstractAppl
|
||||||
|
|
||||||
private ConfigurableWebApplicationContext root;
|
private ConfigurableWebApplicationContext root;
|
||||||
|
|
||||||
protected ConfigurableApplicationContext createContext() throws Exception {
|
|
||||||
InitAndIB.constructed = false;
|
|
||||||
root = new XmlWebApplicationContext();
|
|
||||||
MockServletContext sc = new MockServletContext("");
|
|
||||||
root.setServletContext(sc);
|
|
||||||
root.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/applicationContext.xml"});
|
|
||||||
root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
|
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
|
|
||||||
beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
|
|
||||||
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
|
|
||||||
if (bean instanceof TestBean) {
|
|
||||||
((TestBean) bean).getFriends().add("myFriend");
|
|
||||||
}
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
root.refresh();
|
|
||||||
XmlWebApplicationContext wac = new XmlWebApplicationContext();
|
|
||||||
wac.setParent(root);
|
|
||||||
wac.setServletContext(sc);
|
|
||||||
wac.setNamespace("test-servlet");
|
|
||||||
wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
|
|
||||||
wac.refresh();
|
|
||||||
return wac;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overridden as we can't trust superclass method
|
* Overridden as we can't trust superclass method
|
||||||
|
|
@ -102,25 +66,6 @@ public abstract class AbstractXmlWebApplicationContextTests extends AbstractAppl
|
||||||
this.applicationContext.getBeanDefinitionCount() == 14);
|
this.applicationContext.getBeanDefinitionCount() == 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithoutMessageSource() throws Exception {
|
|
||||||
MockServletContext sc = new MockServletContext("");
|
|
||||||
XmlWebApplicationContext wac = new XmlWebApplicationContext();
|
|
||||||
wac.setParent(root);
|
|
||||||
wac.setServletContext(sc);
|
|
||||||
wac.setNamespace("testNamespace");
|
|
||||||
wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
|
|
||||||
wac.refresh();
|
|
||||||
try {
|
|
||||||
wac.getMessage("someMessage", null, Locale.getDefault());
|
|
||||||
fail("Should have thrown NoSuchMessageException");
|
|
||||||
}
|
|
||||||
catch (NoSuchMessageException ex) {
|
|
||||||
// expected;
|
|
||||||
}
|
|
||||||
String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
|
|
||||||
assertTrue("Default message returned", "default".equals(msg));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testContextNesting() {
|
public void testContextNesting() {
|
||||||
TestBean father = (TestBean) this.applicationContext.getBean("father");
|
TestBean father = (TestBean) this.applicationContext.getBean("father");
|
||||||
assertTrue("Bean from root context", father != null);
|
assertTrue("Bean from root context", father != null);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue