Remove trailing whitespace in source files
find . -type f -name "*.java" -or -name "*.aj" | \
xargs perl -p -i -e "s/[ \t]*$//g" {} \;
Issue: SPR-10127
This commit is contained in:
committed by
Chris Beams
parent
44a474a014
commit
1762157ad1
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Scrap bean for use in tests.
|
||||
*
|
||||
*
|
||||
* @author Colin Sampaleanu
|
||||
*/
|
||||
public class TestBean {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -24,7 +24,7 @@ import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.NoSuchMessageException;
|
||||
|
||||
public class ACATester implements ApplicationContextAware {
|
||||
|
||||
|
||||
private ApplicationContext ac;
|
||||
|
||||
public void setApplicationContext(ApplicationContext ctx) throws ApplicationContextException {
|
||||
|
||||
@@ -7,12 +7,12 @@ import org.springframework.beans.factory.LifecycleBean;
|
||||
|
||||
/**
|
||||
* Simple bean to test ApplicationContext lifecycle methods for beans
|
||||
*
|
||||
*
|
||||
* @author Colin Sampaleanu
|
||||
* @since 03.07.2004
|
||||
*/
|
||||
public class LifecycleContextBean extends LifecycleBean implements ApplicationContextAware {
|
||||
|
||||
|
||||
protected ApplicationContext owningContext;
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
@@ -20,18 +20,18 @@ public class LifecycleContextBean extends LifecycleBean implements ApplicationCo
|
||||
if (this.owningContext != null)
|
||||
throw new RuntimeException("Factory called setBeanFactory after setApplicationContext");
|
||||
}
|
||||
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
if (this.owningContext == null)
|
||||
throw new RuntimeException("Factory didn't call setAppliationContext before afterPropertiesSet on lifecycle bean");
|
||||
}
|
||||
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if (this.owningFactory == null)
|
||||
throw new RuntimeException("Factory called setApplicationContext before setBeanFactory");
|
||||
|
||||
|
||||
this.owningContext = applicationContext;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -95,7 +95,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||
listener.zeroCounter();
|
||||
TestListener parentListener = (TestListener) this.applicationContext.getParent().getBean("parentListener");
|
||||
parentListener.zeroCounter();
|
||||
|
||||
|
||||
parentListener.zeroCounter();
|
||||
assertTrue("0 events before publication", listener.getEventCount() == 0);
|
||||
assertTrue("0 parent events before publication", parentListener.getEventCount() == 0);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link FlashMap} tests.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class FlashMapTests {
|
||||
@@ -78,7 +78,7 @@ public class FlashMapTests {
|
||||
flashMap.addTargetRequestParam("text", "abc");
|
||||
flashMap.addTargetRequestParam("empty", " ");
|
||||
flashMap.addTargetRequestParam("null", null);
|
||||
|
||||
|
||||
assertEquals(1, flashMap.getTargetRequestParams().size());
|
||||
assertEquals("abc", flashMap.getTargetRequestParams().getFirst("text"));
|
||||
}
|
||||
@@ -89,10 +89,10 @@ public class FlashMapTests {
|
||||
params.add("key", "abc");
|
||||
params.add("key", " ");
|
||||
params.add("key", null);
|
||||
|
||||
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.addTargetRequestParams(params);
|
||||
|
||||
|
||||
assertEquals(1, flashMap.getTargetRequestParams().size());
|
||||
assertEquals(1, flashMap.getTargetRequestParams().get("key").size());
|
||||
assertEquals("abc", flashMap.getTargetRequestParams().getFirst("key"));
|
||||
@@ -103,7 +103,7 @@ public class FlashMapTests {
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.addTargetRequestParam(" ", "abc");
|
||||
flashMap.addTargetRequestParam(null, "abc");
|
||||
|
||||
|
||||
assertTrue(flashMap.getTargetRequestParams().isEmpty());
|
||||
}
|
||||
|
||||
@@ -112,11 +112,11 @@ public class FlashMapTests {
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
||||
params.add(" ", "abc");
|
||||
params.add(null, " ");
|
||||
|
||||
|
||||
FlashMap flashMap = new FlashMap();
|
||||
flashMap.addTargetRequestParams(params);
|
||||
|
||||
|
||||
assertTrue(flashMap.getTargetRequestParams().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -143,7 +143,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
|
||||
assertTrue(converters.get(0) instanceof StringHttpMessageConverter);
|
||||
assertTrue(converters.get(1) instanceof ResourceHttpMessageConverter);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class TestWebArgumentResolver implements WebArgumentResolver {
|
||||
@@ -176,7 +176,7 @@ class TestHandlerMethodReturnValueHandler implements HandlerMethodReturnValueHan
|
||||
MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class TestMessageCodesResolver implements MessageCodesResolver {
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
|
||||
public class ResourceHandlerRegistryTests {
|
||||
|
||||
private ResourceHandlerRegistry registry;
|
||||
|
||||
|
||||
private ResourceHandlerRegistration registration;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ViewControllerRegistryTests {
|
||||
assertNotNull(controller);
|
||||
assertEquals("viewName", controller.getViewName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void order() {
|
||||
registry.addViewController("/path");
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.web.servlet.HandlerMapping;
|
||||
public class BeanNameUrlHandlerMappingTests extends TestCase {
|
||||
|
||||
public static final String CONF = "/org/springframework/web/servlet/handler/map1.xml";
|
||||
|
||||
|
||||
private ConfigurableWebApplicationContext wac;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
@@ -82,7 +82,7 @@ public class BeanNameUrlHandlerMappingTests extends TestCase {
|
||||
req.setContextPath("/myapp");
|
||||
hec = hm.getHandler(req);
|
||||
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
|
||||
|
||||
|
||||
req = new MockHttpServletRequest("GET", "/myapp/mypath/welcome.html");
|
||||
req.setContextPath("/myapp");
|
||||
req.setServletPath("/mypath/welcome.html");
|
||||
@@ -109,7 +109,7 @@ public class BeanNameUrlHandlerMappingTests extends TestCase {
|
||||
hec = hm.getHandler(req);
|
||||
assertTrue("Handler is correct bean", hec != null && hec.getHandler() == bean);
|
||||
}
|
||||
|
||||
|
||||
public void testRequestsWithFullPaths() throws Exception {
|
||||
BeanNameUrlHandlerMapping hm = new BeanNameUrlHandlerMapping();
|
||||
hm.setAlwaysUseFullPath(true);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -78,7 +78,7 @@ public class CommandControllerTests extends TestCase {
|
||||
assertTrue("command name bound ok", person.getName().equals(name));
|
||||
assertTrue("command age bound ok", person.getAge() == age);
|
||||
}
|
||||
|
||||
|
||||
public void test2Args1Mismatch() throws Exception {
|
||||
TestController mc = new TestController();
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/ok.html");
|
||||
@@ -492,11 +492,11 @@ public class CommandControllerTests extends TestCase {
|
||||
|
||||
|
||||
private static class TestController extends AbstractCommandController {
|
||||
|
||||
|
||||
private TestController() {
|
||||
super(TestBean.class, "person");
|
||||
}
|
||||
|
||||
|
||||
protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {
|
||||
Map m = new HashMap();
|
||||
assertTrue("Command not null", command != null);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ParameterizableViewControllerTests {
|
||||
private ParameterizableViewController controller;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.controller = new ParameterizableViewController();
|
||||
@@ -54,7 +54,7 @@ public class ParameterizableViewControllerTests {
|
||||
assertEquals(viewName, mav.getViewName());
|
||||
assertTrue(mav.getModel().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void handleRequestWithoutViewName() throws Exception {
|
||||
ModelAndView mav = this.controller.handleRequest(this.request, new MockHttpServletResponse());
|
||||
|
||||
@@ -76,7 +76,7 @@ public class WebContentInterceptorTests {
|
||||
WebContentInterceptor interceptor = new WebContentInterceptor();
|
||||
interceptor.setCacheSeconds(10);
|
||||
interceptor.setCacheMappings(mappings);
|
||||
|
||||
|
||||
request.setRequestURI("http://localhost:7070/example/adminhandle.vm");
|
||||
interceptor.preHandle(request, response, null);
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ public class ServletAnnotationControllerTests {
|
||||
}
|
||||
};
|
||||
servlet.init(new MockServletConfig());
|
||||
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myPath.do");
|
||||
request.setContextPath("/myApp");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
@@ -1705,7 +1705,7 @@ public class ServletAnnotationControllerTests {
|
||||
assertEquals("handle", response.getContentAsString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void trailingSlash() throws Exception {
|
||||
initServlet(TrailingSlashController.class);
|
||||
@@ -2824,7 +2824,7 @@ public class ServletAnnotationControllerTests {
|
||||
|
||||
@XmlRootElement
|
||||
public static class A {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@@ -3144,7 +3144,7 @@ public class ServletAnnotationControllerTests {
|
||||
public void root(Writer writer) throws IOException {
|
||||
writer.write("root");
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/{templatePath}/", method = RequestMethod.GET)
|
||||
public void templatePath(Writer writer) throws IOException {
|
||||
writer.write("templatePath");
|
||||
@@ -3256,10 +3256,10 @@ public class ServletAnnotationControllerTests {
|
||||
writer.write("handle2");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Controller
|
||||
static class HeadersConditionController {
|
||||
|
||||
|
||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||
public String home() {
|
||||
return "home";
|
||||
@@ -3279,5 +3279,5 @@ public class ServletAnnotationControllerTests {
|
||||
public void handle(RedirectAttributes redirectAttrs) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ServletAnnotationMappingUtilsTests {
|
||||
boolean result = ServletAnnotationMappingUtils.checkParameters(params, request);
|
||||
assertTrue("Invalid request method result", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void checkParametersKeyValueNoMatch() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
|
||||
@@ -77,7 +77,7 @@ public class ServletAnnotationMappingUtilsTests {
|
||||
boolean result = ServletAnnotationMappingUtils.checkParameters(params, request);
|
||||
assertFalse("Invalid request method result", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void checkParametersNegatedValueMatch() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
|
||||
@@ -86,7 +86,7 @@ public class ServletAnnotationMappingUtilsTests {
|
||||
boolean result = ServletAnnotationMappingUtils.checkParameters(params, request);
|
||||
assertTrue("Invalid request method result", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void checkParametersNegatedValueNoMatch() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
|
||||
@@ -143,8 +143,8 @@ public class ServletAnnotationMappingUtilsTests {
|
||||
assertFalse("Invalid request method result", result);
|
||||
}
|
||||
|
||||
// SPR-8862
|
||||
|
||||
// SPR-8862
|
||||
|
||||
@Test
|
||||
public void checkHeadersKeyValueNoMatchWithNegation() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Spr7766Tests {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
adapter.handle(request, response, controller);
|
||||
}
|
||||
|
||||
|
||||
public class ColorConverter implements Converter<String, Color> {
|
||||
public Color convert(String source) { if (!source.startsWith("#")) source = "#" + source; return Color.decode(source); }
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Spr7839Tests {
|
||||
request.addParameter("nested.list", "Nested1,Nested2");
|
||||
adapter.handle(request, response, controller);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void listElement() throws Exception {
|
||||
request.setRequestURI("/nested/listElement");
|
||||
@@ -124,14 +124,14 @@ public class Spr7839Tests {
|
||||
|
||||
@Test
|
||||
public void map() throws Exception {
|
||||
request.setRequestURI("/nested/map");
|
||||
request.setRequestURI("/nested/map");
|
||||
request.addParameter("nested.map['apple'].foo", "bar");
|
||||
adapter.handle(request, response, controller);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapOfLists() throws Exception {
|
||||
request.setRequestURI("/nested/mapOfLists");
|
||||
request.setRequestURI("/nested/mapOfLists");
|
||||
request.addParameter("nested.mapOfLists['apples'][0]", "1");
|
||||
adapter.handle(request, response, controller);
|
||||
}
|
||||
@@ -173,14 +173,14 @@ public class Spr7839Tests {
|
||||
public void handlerMap(JavaBean bean) {
|
||||
assertEquals("bar", bean.nested.map.get("apple").foo);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/nested/mapOfLists")
|
||||
public void handlerMapOfLists(JavaBean bean) {
|
||||
assertEquals(new Integer(1), bean.nested.mapOfLists.get("apples").get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class JavaBean {
|
||||
|
||||
private NestedBean nested;
|
||||
@@ -193,7 +193,7 @@ public class Spr7839Tests {
|
||||
this.nested = nested;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class NestedBean {
|
||||
@@ -209,15 +209,15 @@ public class Spr7839Tests {
|
||||
private Map<String, NestedBean> map;
|
||||
|
||||
private Map<String, List<Integer>> mapOfLists;
|
||||
|
||||
|
||||
public NestedBean() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public NestedBean(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
|
||||
public String getFoo() {
|
||||
return foo;
|
||||
}
|
||||
@@ -265,7 +265,7 @@ public class Spr7839Tests {
|
||||
public void setMapOfLists(Map<String, List<Integer>> mapOfLists) {
|
||||
this.mapOfLists = mapOfLists;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class HeadersRequestConditionTests {
|
||||
assertTrue("Invalid comparison result: " + result, result > 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void combine() {
|
||||
HeadersRequestCondition condition1 = new HeadersRequestCondition("foo=bar");
|
||||
|
||||
@@ -48,7 +48,7 @@ public class RequestMappingInfoTests {
|
||||
@Test
|
||||
public void createEmpty() {
|
||||
RequestMappingInfo info = new RequestMappingInfo(null, null, null, null, null, null, null);
|
||||
|
||||
|
||||
assertEquals(0, info.getPatternsCondition().getPatterns().size());
|
||||
assertEquals(0, info.getMethodsCondition().getMethods().size());
|
||||
assertEquals(true, info.getConsumesCondition().isEmpty());
|
||||
@@ -57,7 +57,7 @@ public class RequestMappingInfoTests {
|
||||
assertNotNull(info.getHeadersCondition());
|
||||
assertNull(info.getCustomCondition());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void matchPatternsCondition() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
@@ -66,14 +66,14 @@ public class RequestMappingInfoTests {
|
||||
new PatternsRequestCondition("/foo*", "/bar"), null, null, null, null, null, null);
|
||||
RequestMappingInfo expected = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo*"), null, null, null, null, null, null);
|
||||
|
||||
|
||||
assertEquals(expected, info.getMatchingCondition(request));
|
||||
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/**", "/foo*", "/foo"), null, null, null, null, null, null);
|
||||
expected = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo", "/foo*", "/**"), null, null, null, null, null, null);
|
||||
|
||||
|
||||
assertEquals(expected, info.getMatchingCondition(request));
|
||||
}
|
||||
|
||||
@@ -84,14 +84,14 @@ public class RequestMappingInfoTests {
|
||||
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new ParamsRequestCondition("foo=bar"), null, null, null, null);
|
||||
RequestMappingInfo match = info.getMatchingCondition(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new ParamsRequestCondition("foo!=bar"), null, null, null, null);
|
||||
match = info.getMatchingCondition(request);
|
||||
|
||||
@@ -105,14 +105,14 @@ public class RequestMappingInfoTests {
|
||||
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null,
|
||||
new PatternsRequestCondition("/foo"), null, null,
|
||||
new HeadersRequestCondition("foo=bar"), null, null, null);
|
||||
RequestMappingInfo match = info.getMatchingCondition(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null,
|
||||
new PatternsRequestCondition("/foo"), null, null,
|
||||
new HeadersRequestCondition("foo!=bar"), null, null, null);
|
||||
match = info.getMatchingCondition(request);
|
||||
|
||||
@@ -124,7 +124,7 @@ public class RequestMappingInfoTests {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.setContentType("text/plain");
|
||||
|
||||
RequestMappingInfo info =
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null, null,
|
||||
new ConsumesRequestCondition("text/plain"), null, null);
|
||||
@@ -145,9 +145,9 @@ public class RequestMappingInfoTests {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
|
||||
request.addHeader("Accept", "text/plain");
|
||||
|
||||
RequestMappingInfo info =
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null, null, null,
|
||||
new PatternsRequestCondition("/foo"), null, null, null, null,
|
||||
new ProducesRequestCondition("text/plain"), null);
|
||||
RequestMappingInfo match = info.getMatchingCondition(request);
|
||||
|
||||
@@ -168,38 +168,38 @@ public class RequestMappingInfoTests {
|
||||
|
||||
RequestMappingInfo info =
|
||||
new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null, null, null, null, null,
|
||||
new PatternsRequestCondition("/foo"), null, null, null, null, null,
|
||||
new ParamsRequestCondition("foo=bar"));
|
||||
RequestMappingInfo match = info.getMatchingCondition(request);
|
||||
|
||||
assertNotNull(match);
|
||||
|
||||
info = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new ParamsRequestCondition("foo!=bar"), null, null, null,
|
||||
new PatternsRequestCondition("/foo"), null,
|
||||
new ParamsRequestCondition("foo!=bar"), null, null, null,
|
||||
new ParamsRequestCondition("foo!=bar"));
|
||||
match = info.getMatchingCondition(request);
|
||||
|
||||
assertNull(match);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareTwoHttpMethodsOneParam() {
|
||||
RequestMappingInfo none = new RequestMappingInfo(null, null, null, null, null, null, null);
|
||||
RequestMappingInfo oneMethod =
|
||||
new RequestMappingInfo(null,
|
||||
RequestMappingInfo oneMethod =
|
||||
new RequestMappingInfo(null,
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET), null, null, null, null, null);
|
||||
RequestMappingInfo oneMethodOneParam =
|
||||
new RequestMappingInfo(null,
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new RequestMappingInfo(null,
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo"), null, null, null, null);
|
||||
|
||||
|
||||
Comparator<RequestMappingInfo> comparator = new Comparator<RequestMappingInfo>() {
|
||||
public int compare(RequestMappingInfo info, RequestMappingInfo otherInfo) {
|
||||
return info.compareTo(otherInfo, new MockHttpServletRequest());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
|
||||
Collections.shuffle(list);
|
||||
Collections.sort(list, comparator);
|
||||
@@ -211,22 +211,22 @@ public class RequestMappingInfoTests {
|
||||
|
||||
@Test
|
||||
public void equals() {
|
||||
|
||||
|
||||
RequestMappingInfo info1 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
RequestMappingInfo info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
@@ -234,86 +234,86 @@ public class RequestMappingInfoTests {
|
||||
assertEquals(info1.hashCode(), info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo", "/NOOOOOO"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new PatternsRequestCondition("/foo", "/NOOOOOO"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("/NOOOOOO"),
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("/NOOOOOO"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("/NOOOOOO"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/NOOOOOO"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ConsumesRequestCondition("text/NOOOOOO"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/NOOOOOO"),
|
||||
new ParamsRequestCondition("customFoo=customBar"));
|
||||
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
|
||||
info2 = new RequestMappingInfo(
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new PatternsRequestCondition("/foo"),
|
||||
new RequestMethodsRequestCondition(RequestMethod.GET),
|
||||
new ParamsRequestCondition("foo=bar"),
|
||||
new HeadersRequestCondition("foo=bar"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ConsumesRequestCondition("text/plain"),
|
||||
new ProducesRequestCondition("text/plain"),
|
||||
new ParamsRequestCondition("customFoo=NOOOOOO"));
|
||||
|
||||
|
||||
assertFalse(info1.equals(info2));
|
||||
assertTrue(info1.hashCode() != info2.hashCode());
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ModelAndViewResolve
|
||||
|
||||
/**
|
||||
* Test fixture with {@link ModelAndViewResolverMethodReturnValueHandler}.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ModelAndViewResolverMethodReturnValueHandlerTests {
|
||||
@@ -69,7 +69,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests {
|
||||
TestBean testBean = new TestBean("name");
|
||||
|
||||
handler.handleReturnValue(testBean, returnType, mavContainer, request);
|
||||
|
||||
|
||||
assertEquals("viewName", mavContainer.getViewName());
|
||||
assertSame(testBean, mavContainer.getModel().get("modelAttrName"));
|
||||
assertFalse(mavContainer.isRequestHandled());
|
||||
@@ -86,12 +86,12 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests {
|
||||
public void handleNull() throws Exception {
|
||||
MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("testBeanReturnValue"), -1);
|
||||
handler.handleReturnValue(null, returnType, mavContainer, request);
|
||||
|
||||
|
||||
assertNull(mavContainer.getView());
|
||||
assertNull(mavContainer.getViewName());
|
||||
assertTrue(mavContainer.getModel().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void handleSimpleType() throws Exception {
|
||||
MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("intReturnValue"), -1);
|
||||
@@ -102,7 +102,7 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests {
|
||||
public void handleNonSimpleType() throws Exception{
|
||||
MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("testBeanReturnValue"), -1);
|
||||
handler.handleReturnValue(new TestBean(), returnType, mavContainer, request);
|
||||
|
||||
|
||||
assertTrue(mavContainer.containsAttribute("testBean"));
|
||||
}
|
||||
|
||||
@@ -115,11 +115,11 @@ public class ModelAndViewResolverMethodReturnValueHandlerTests {
|
||||
private TestBean testBeanReturnValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static class TestModelAndViewResolver implements ModelAndViewResolver {
|
||||
|
||||
|
||||
private Class<?> returnValueType;
|
||||
|
||||
|
||||
public TestModelAndViewResolver(Class<?> returnValueType) {
|
||||
this.returnValueType = returnValueType;
|
||||
}
|
||||
|
||||
@@ -41,21 +41,21 @@ import org.springframework.web.servlet.mvc.method.annotation.PathVariableMethodA
|
||||
|
||||
/**
|
||||
* Test fixture with {@link PathVariableMethodArgumentResolver}.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class PathVariableMethodArgumentResolverTests {
|
||||
|
||||
private PathVariableMethodArgumentResolver resolver;
|
||||
|
||||
|
||||
private MethodParameter paramNamedString;
|
||||
|
||||
private MethodParameter paramString;
|
||||
|
||||
private ModelAndViewContainer mavContainer;
|
||||
|
||||
|
||||
private ServletWebRequest webRequest;
|
||||
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
@Before
|
||||
@@ -70,7 +70,7 @@ public class PathVariableMethodArgumentResolverTests {
|
||||
request = new MockHttpServletRequest();
|
||||
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() {
|
||||
assertTrue("Parameter with @PathVariable annotation", resolver.supportsParameter(paramNamedString));
|
||||
@@ -85,14 +85,14 @@ public class PathVariableMethodArgumentResolverTests {
|
||||
|
||||
String result = (String) resolver.resolveArgument(paramNamedString, mavContainer, webRequest, null);
|
||||
assertEquals("PathVariable not resolved correctly", "value", result);
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> pathVars = (Map<String, Object>) request.getAttribute(View.PATH_VARIABLES);
|
||||
assertNotNull(pathVars);
|
||||
assertEquals(1, pathVars.size());
|
||||
assertEquals("value", pathVars.get("name"));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void resolveArgumentWithExistingPathVars() throws Exception {
|
||||
@@ -106,20 +106,20 @@ public class PathVariableMethodArgumentResolverTests {
|
||||
|
||||
String result = (String) resolver.resolveArgument(paramNamedString, mavContainer, webRequest, null);
|
||||
assertEquals("PathVariable not resolved correctly", "value", result);
|
||||
|
||||
|
||||
pathVars = (Map<String, Object>) request.getAttribute(View.PATH_VARIABLES);
|
||||
assertNotNull(pathVars);
|
||||
assertEquals(2, pathVars.size());
|
||||
assertEquals("value", pathVars.get("name"));
|
||||
assertEquals("oldValue", pathVars.get("oldName"));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = ServletRequestBindingException.class)
|
||||
public void handleMissingValue() throws Exception {
|
||||
resolver.resolveArgument(paramNamedString, mavContainer, webRequest, null);
|
||||
fail("Unresolved path variable should lead to exception.");
|
||||
}
|
||||
|
||||
|
||||
public void handle(@PathVariable(value = "name") String param1, String param2) {
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodAr
|
||||
|
||||
/**
|
||||
* Test fixture with {@link RequestPartMethodArgumentResolver} and mock {@link HttpMessageConverter}.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class RequestPartMethodArgumentResolverTests {
|
||||
@@ -76,7 +76,7 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
private RequestPartMethodArgumentResolver resolver;
|
||||
|
||||
private HttpMessageConverter<SimpleBean> messageConverter;
|
||||
|
||||
|
||||
private MultipartFile multipartFile1;
|
||||
private MultipartFile multipartFile2;
|
||||
|
||||
@@ -99,10 +99,10 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
|
||||
Method method = getClass().getMethod("handle", SimpleBean.class, SimpleBean.class, SimpleBean.class,
|
||||
MultipartFile.class, List.class, Integer.TYPE, MultipartFile.class, Part.class, MultipartFile.class);
|
||||
|
||||
|
||||
paramRequestPart = new MethodParameter(method, 0);
|
||||
paramRequestPart.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
|
||||
paramNamedRequestPart = new MethodParameter(method, 1);
|
||||
@@ -122,7 +122,7 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
|
||||
resolver = new RequestPartMethodArgumentResolver(Collections.<HttpMessageConverter<?>>singletonList(messageConverter));
|
||||
reset(messageConverter);
|
||||
|
||||
|
||||
multipartFile1 = new MockMultipartFile("requestPart", "", "text/plain", (byte[]) null);
|
||||
multipartFile2 = new MockMultipartFile("requestPart", "", "text/plain", (byte[]) null);
|
||||
multipartRequest = new MockMultipartHttpServletRequest();
|
||||
@@ -139,16 +139,16 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
assertTrue("Part parameter not supported", resolver.supportsParameter(paramServlet30Part));
|
||||
assertFalse("non-RequestPart parameter supported", resolver.supportsParameter(paramInt));
|
||||
assertFalse("@RequestParam args not supported", resolver.supportsParameter(paramRequestParamAnnot));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void resolveMultipartFile() throws Exception {
|
||||
Object actual = resolver.resolveArgument(paramMultipartFile, null, webRequest, null);
|
||||
assertNotNull(actual);
|
||||
assertSame(multipartFile1, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void resolveMultipartFileList() throws Exception {
|
||||
Object actual = resolver.resolveArgument(paramMultipartFileList, null, webRequest, null);
|
||||
assertNotNull(actual);
|
||||
@@ -193,7 +193,7 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
public void resolveNamedRequestPart() throws Exception {
|
||||
testResolveArgument(new SimpleBean("foo"), paramNamedRequestPart);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveRequestPartNotValid() throws Exception {
|
||||
try {
|
||||
@@ -205,12 +205,12 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
assertNotNull(e.getBindingResult().getFieldError("name"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveRequestPartValid() throws Exception {
|
||||
testResolveArgument(new SimpleBean("foo"), paramNamedRequestPart);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveRequestPartRequired() throws Exception {
|
||||
try {
|
||||
@@ -225,7 +225,7 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
public void resolveRequestPartNotRequired() throws Exception {
|
||||
testResolveArgument(new SimpleBean("foo"), paramValidRequestPart);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=MultipartException.class)
|
||||
public void isMultipartRequest() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -255,9 +255,9 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
|
||||
assertEquals("Invalid argument value", argValue, actualValue);
|
||||
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
|
||||
|
||||
|
||||
verify(messageConverter);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SimpleBean {
|
||||
|
||||
@@ -273,7 +273,7 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final class ValidatingBinderFactory implements WebDataBinderFactory {
|
||||
public WebDataBinder createBinder(NativeWebRequest webRequest, Object target, String objectName) throws Exception {
|
||||
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
|
||||
@@ -284,9 +284,9 @@ public class RequestPartMethodArgumentResolverTests {
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(@RequestPart SimpleBean requestPart,
|
||||
@RequestPart(value="requestPart", required=false) SimpleBean namedRequestPart,
|
||||
@Valid @RequestPart("requestPart") SimpleBean validRequestPart,
|
||||
public void handle(@RequestPart SimpleBean requestPart,
|
||||
@RequestPart(value="requestPart", required=false) SimpleBean namedRequestPart,
|
||||
@Valid @RequestPart("requestPart") SimpleBean validRequestPart,
|
||||
@RequestPart("requestPart") MultipartFile multipartFile,
|
||||
@RequestPart("requestPart") List<MultipartFile> multipartFileList,
|
||||
int i,
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.web.servlet.HandlerMapping;
|
||||
/**
|
||||
* Test fixture for {@link ServletModelAttributeMethodProcessor} specific tests.
|
||||
* Also see org.springframework.web.method.annotation.support.ModelAttributeMethodProcessorTests
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class SerlvetModelAttributeMethodProcessorTests {
|
||||
@@ -48,7 +48,7 @@ public class SerlvetModelAttributeMethodProcessorTests {
|
||||
private ServletModelAttributeMethodProcessor processor;
|
||||
|
||||
private MethodParameter testBeanModelAttr;
|
||||
|
||||
|
||||
private MethodParameter testBeanWithoutStringConstructorModelAttr;
|
||||
|
||||
private ModelAndViewContainer mavContainer;
|
||||
@@ -63,18 +63,18 @@ public class SerlvetModelAttributeMethodProcessorTests {
|
||||
public void setUp() throws Exception {
|
||||
this.processor = new ServletModelAttributeMethodProcessor(false);
|
||||
|
||||
Method method = getClass().getDeclaredMethod("modelAttribute",
|
||||
Method method = getClass().getDeclaredMethod("modelAttribute",
|
||||
TestBean.class, TestBeanWithoutStringConstructor.class);
|
||||
|
||||
|
||||
this.testBeanModelAttr = new MethodParameter(method, 0);
|
||||
this.testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1);
|
||||
|
||||
|
||||
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
|
||||
initializer.setConversionService(new DefaultConversionService());
|
||||
|
||||
|
||||
this.binderFactory = new ServletRequestDataBinderFactory(null, initializer );
|
||||
this.mavContainer = new ModelAndViewContainer();
|
||||
|
||||
|
||||
this.request = new MockHttpServletRequest();
|
||||
this.webRequest = new ServletWebRequest(request);
|
||||
}
|
||||
@@ -87,10 +87,10 @@ public class SerlvetModelAttributeMethodProcessorTests {
|
||||
|
||||
// Type conversion from "Patty" to TestBean via TestBean(String) constructor
|
||||
|
||||
TestBean testBean =
|
||||
TestBean testBean =
|
||||
(TestBean) this.processor.resolveArgument(
|
||||
this.testBeanModelAttr, this.mavContainer, this.webRequest, this.binderFactory);
|
||||
|
||||
|
||||
assertEquals("Patty", testBean.getName());
|
||||
}
|
||||
|
||||
@@ -100,10 +100,10 @@ public class SerlvetModelAttributeMethodProcessorTests {
|
||||
uriTemplateVars.put("testBean2", "Patty");
|
||||
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
|
||||
|
||||
TestBeanWithoutStringConstructor testBean =
|
||||
TestBeanWithoutStringConstructor testBean =
|
||||
(TestBeanWithoutStringConstructor) this.processor.resolveArgument(
|
||||
this.testBeanWithoutStringConstructorModelAttr, this.mavContainer, this.webRequest, this.binderFactory);
|
||||
|
||||
|
||||
assertNotNull(testBean);
|
||||
}
|
||||
|
||||
@@ -113,10 +113,10 @@ public class SerlvetModelAttributeMethodProcessorTests {
|
||||
|
||||
// Type conversion from "Patty" to TestBean via TestBean(String) constructor
|
||||
|
||||
TestBean testBean =
|
||||
TestBean testBean =
|
||||
(TestBean) this.processor.resolveArgument(
|
||||
this.testBeanModelAttr, this.mavContainer, this.webRequest, this.binderFactory);
|
||||
|
||||
|
||||
assertEquals("Patty", testBean.getName());
|
||||
}
|
||||
|
||||
@@ -124,17 +124,17 @@ public class SerlvetModelAttributeMethodProcessorTests {
|
||||
public void createAttributeRequestParameterCannotConvert() throws Exception {
|
||||
this.request.addParameter("testBean1", "Patty");
|
||||
|
||||
TestBeanWithoutStringConstructor testBean =
|
||||
TestBeanWithoutStringConstructor testBean =
|
||||
(TestBeanWithoutStringConstructor) this.processor.resolveArgument(
|
||||
this.testBeanWithoutStringConstructorModelAttr, this.mavContainer, this.webRequest, this.binderFactory);
|
||||
|
||||
|
||||
assertNotNull(testBean);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void modelAttribute(@ModelAttribute("testBean1") TestBean testBean1,
|
||||
@ModelAttribute("testBean2") TestBeanWithoutStringConstructor testBean2) {
|
||||
private void modelAttribute(@ModelAttribute("testBean1") TestBean testBean1,
|
||||
@ModelAttribute("testBean2") TestBeanWithoutStringConstructor testBean2) {
|
||||
}
|
||||
|
||||
|
||||
@@ -143,10 +143,10 @@ public class SerlvetModelAttributeMethodProcessorTests {
|
||||
|
||||
public TestBeanWithoutStringConstructor() {
|
||||
}
|
||||
|
||||
|
||||
public TestBeanWithoutStringConstructor(int i) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ServletCookieValueM
|
||||
|
||||
/**
|
||||
* Test fixture with {@link ServletCookieValueMethodArgumentResolver}.
|
||||
*
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@@ -52,7 +52,7 @@ public class ServletCookieValueMethodArgumentResolverTests {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resolver = new ServletCookieValueMethodArgumentResolver(null);
|
||||
|
||||
|
||||
Method method = getClass().getMethod("params", Cookie.class, String.class);
|
||||
cookieParameter = new MethodParameter(method, 0);
|
||||
cookieStringParameter = new MethodParameter(method, 1);
|
||||
|
||||
@@ -41,7 +41,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link ServletRequestMethodArgumentResolver}.
|
||||
*
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@@ -52,7 +52,7 @@ public class ServletRequestMethodArgumentResolverTests {
|
||||
private Method method;
|
||||
|
||||
private ModelAndViewContainer mavContainer;
|
||||
|
||||
|
||||
private ServletWebRequest webRequest;
|
||||
|
||||
private MockHttpServletRequest servletRequest;
|
||||
@@ -69,10 +69,10 @@ public class ServletRequestMethodArgumentResolverTests {
|
||||
@Test
|
||||
public void servletRequest() throws Exception {
|
||||
MethodParameter servletRequestParameter = new MethodParameter(method, 0);
|
||||
|
||||
|
||||
boolean isSupported = resolver.supportsParameter(servletRequestParameter);
|
||||
Object result = resolver.resolveArgument(servletRequestParameter, mavContainer, webRequest, null);
|
||||
|
||||
|
||||
assertTrue("ServletRequest not supported", isSupported);
|
||||
assertSame("Invalid result", servletRequest, result);
|
||||
assertFalse("The requestHandled flag shouldn't change", mavContainer.isRequestHandled());
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link org.springframework.web.servlet.mvc.method.annotation.ServletRequestMethodArgumentResolver}.
|
||||
*
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class ServletResponseMethodArgumentResolverTests {
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link UriComponentsBuilderMethodArgumentResolver}.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class UriComponentsBuilderMethodArgumentResolverTests {
|
||||
@@ -45,7 +45,7 @@ public class UriComponentsBuilderMethodArgumentResolverTests {
|
||||
private MethodParameter builderParam;
|
||||
|
||||
private MethodParameter servletBuilderParam;
|
||||
|
||||
|
||||
private MethodParameter intParam;
|
||||
|
||||
private ServletWebRequest webRequest;
|
||||
@@ -62,22 +62,22 @@ public class UriComponentsBuilderMethodArgumentResolverTests {
|
||||
this.servletRequest = new MockHttpServletRequest();
|
||||
this.webRequest = new ServletWebRequest(this.servletRequest);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsParameter() throws Exception {
|
||||
assertTrue(this.resolver.supportsParameter(this.builderParam));
|
||||
assertTrue(this.resolver.supportsParameter(this.servletBuilderParam));
|
||||
assertFalse(this.resolver.supportsParameter(this.intParam));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void resolveArgument() throws Exception {
|
||||
this.servletRequest.setContextPath("/myapp");
|
||||
this.servletRequest.setServletPath("/main");
|
||||
this.servletRequest.setPathInfo("/accounts");
|
||||
|
||||
|
||||
Object actual = this.resolver.resolveArgument(this.builderParam, new ModelAndViewContainer(), this.webRequest, null);
|
||||
|
||||
|
||||
assertNotNull(actual);
|
||||
assertEquals(ServletUriComponentsBuilder.class, actual.getClass());
|
||||
assertEquals("http://localhost/myapp/main", ((ServletUriComponentsBuilder) actual).build().toUriString());
|
||||
@@ -86,5 +86,5 @@ public class UriComponentsBuilderMethodArgumentResolverTests {
|
||||
|
||||
void handle(UriComponentsBuilder builder, ServletUriComponentsBuilder servletBuilder, int value) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ import org.springframework.web.servlet.view.RedirectView;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link ViewMethodReturnValueHandler}.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ViewMethodReturnValueHandlerTests {
|
||||
@@ -53,7 +53,7 @@ public class ViewMethodReturnValueHandlerTests {
|
||||
this.mavContainer = new ModelAndViewContainer();
|
||||
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsReturnType() throws Exception {
|
||||
assertTrue(this.handler.supportsReturnType(createReturnValueParam("view")));
|
||||
@@ -63,7 +63,7 @@ public class ViewMethodReturnValueHandlerTests {
|
||||
public void returnView() throws Exception {
|
||||
InternalResourceView view = new InternalResourceView("testView");
|
||||
this.handler.handleReturnValue(view, createReturnValueParam("view"), this.mavContainer, this.webRequest);
|
||||
|
||||
|
||||
assertSame(view, this.mavContainer.getView());
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ViewMethodReturnValueHandlerTests {
|
||||
this.mavContainer.setRedirectModel(redirectModel);
|
||||
MethodParameter param = createReturnValueParam("view");
|
||||
this.handler.handleReturnValue(redirectView, param, this.mavContainer, this.webRequest);
|
||||
|
||||
|
||||
assertSame(redirectView, this.mavContainer.getView());
|
||||
assertSame("Should have switched to the RedirectModel", redirectModel, this.mavContainer.getModel());
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class ViewMethodReturnValueHandlerTests {
|
||||
Method method = getClass().getDeclaredMethod(methodName);
|
||||
return new MethodParameter(method, -1);
|
||||
}
|
||||
|
||||
|
||||
View view() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link ViewNameMethodReturnValueHandler}.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ViewNameMethodReturnValueHandlerTests {
|
||||
@@ -51,17 +51,17 @@ public class ViewNameMethodReturnValueHandlerTests {
|
||||
this.mavContainer = new ModelAndViewContainer();
|
||||
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsReturnType() throws Exception {
|
||||
assertTrue(this.handler.supportsReturnType(createReturnValueParam("viewName")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void returnViewName() throws Exception {
|
||||
MethodParameter param = createReturnValueParam("viewName");
|
||||
this.handler.handleReturnValue("testView", param, this.mavContainer, this.webRequest);
|
||||
|
||||
|
||||
assertEquals("testView", this.mavContainer.getViewName());
|
||||
}
|
||||
|
||||
@@ -80,9 +80,9 @@ public class ViewNameMethodReturnValueHandlerTests {
|
||||
Method method = getClass().getDeclaredMethod(methodName);
|
||||
return new MethodParameter(method, -1);
|
||||
}
|
||||
|
||||
|
||||
String viewName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import org.springframework.format.support.FormattingConversionService;
|
||||
import org.springframework.validation.DataBinder;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Test fixture for {@link RedirectAttributesModelMap} tests.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -40,7 +40,7 @@ import org.springframework.validation.DataBinder;
|
||||
public class RedirectAttributesModelMapTests {
|
||||
|
||||
private RedirectAttributesModelMap redirectAttributes;
|
||||
|
||||
|
||||
private FormattingConversionService conversionService;
|
||||
|
||||
@Before
|
||||
@@ -48,10 +48,10 @@ public class RedirectAttributesModelMapTests {
|
||||
this.conversionService = new DefaultFormattingConversionService();
|
||||
DataBinder dataBinder = new DataBinder(null);
|
||||
dataBinder.setConversionService(conversionService);
|
||||
|
||||
|
||||
this.redirectAttributes = new RedirectAttributesModelMap(dataBinder);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void addAttributePrimitiveType() {
|
||||
this.redirectAttributes.addAttribute("speed", 65);
|
||||
@@ -62,12 +62,12 @@ public class RedirectAttributesModelMapTests {
|
||||
public void addAttributeCustomType() {
|
||||
String attrName = "person";
|
||||
this.redirectAttributes.addAttribute(attrName, new TestBean("Fred"));
|
||||
|
||||
|
||||
assertEquals("ConversionService should have invoked toString()", "Fred", this.redirectAttributes.get(attrName));
|
||||
|
||||
this.conversionService.addConverter(new TestBeanConverter());
|
||||
this.redirectAttributes.addAttribute(attrName, new TestBean("Fred"));
|
||||
|
||||
|
||||
assertEquals("Type converter should have been used", "[Fred]", this.redirectAttributes.get(attrName));
|
||||
}
|
||||
|
||||
@@ -83,14 +83,14 @@ public class RedirectAttributesModelMapTests {
|
||||
@Test
|
||||
public void addAttributeValue() {
|
||||
this.redirectAttributes.addAttribute(new TestBean("Fred"));
|
||||
|
||||
|
||||
assertEquals("Fred", this.redirectAttributes.get("testBean"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addAllAttributesList() {
|
||||
this.redirectAttributes.addAllAttributes(Arrays.asList(new TestBean("Fred"), new Integer(5)));
|
||||
|
||||
|
||||
assertEquals("Fred", this.redirectAttributes.get("testBean"));
|
||||
assertEquals("5", this.redirectAttributes.get("integer"));
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class RedirectAttributesModelMapTests {
|
||||
map.put("person", new TestBean("Fred"));
|
||||
map.put("age", 33);
|
||||
this.redirectAttributes.addAllAttributes(map);
|
||||
|
||||
|
||||
assertEquals("Fred", this.redirectAttributes.get("person"));
|
||||
assertEquals("33", this.redirectAttributes.get("age"));
|
||||
}
|
||||
@@ -111,18 +111,18 @@ public class RedirectAttributesModelMapTests {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("person", new TestBean("Fred"));
|
||||
map.put("age", 33);
|
||||
|
||||
|
||||
this.redirectAttributes.addAttribute("person", new TestBean("Ralph"));
|
||||
this.redirectAttributes.mergeAttributes(map);
|
||||
|
||||
|
||||
assertEquals("Ralph", this.redirectAttributes.get("person"));
|
||||
assertEquals("33", this.redirectAttributes.get("age"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void put() {
|
||||
this.redirectAttributes.put("testBean", new TestBean("Fred"));
|
||||
|
||||
|
||||
assertEquals("Fred", this.redirectAttributes.get("testBean"));
|
||||
}
|
||||
|
||||
@@ -132,16 +132,16 @@ public class RedirectAttributesModelMapTests {
|
||||
map.put("person", new TestBean("Fred"));
|
||||
map.put("age", 33);
|
||||
this.redirectAttributes.putAll(map);
|
||||
|
||||
|
||||
assertEquals("Fred", this.redirectAttributes.get("person"));
|
||||
assertEquals("33", this.redirectAttributes.get("age"));
|
||||
}
|
||||
|
||||
|
||||
public static class TestBeanConverter implements Converter<TestBean, String> {
|
||||
|
||||
|
||||
public String convert(TestBean source) {
|
||||
return "[" + source.getName() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class RequestContextTests {
|
||||
map.put("spam", "bucket");
|
||||
assertEquals("foo/bar?spam=bucket", context.getContextUrl("{foo}?spam={spam}", map));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetContextUrlWithMapEscaping() throws Exception {
|
||||
request.setContextPath("foo/");
|
||||
@@ -83,12 +83,12 @@ public class RequestContextTests {
|
||||
request.setContextPath("/app");
|
||||
request.setServletPath("/servlet");
|
||||
RequestContext context = new RequestContext(request, response, servletContext, model);
|
||||
|
||||
|
||||
assertEquals("/app/servlet", context.getPathToServlet());
|
||||
|
||||
request.setAttribute(WebUtils.FORWARD_CONTEXT_PATH_ATTRIBUTE, "/origApp");
|
||||
request.setAttribute(WebUtils.FORWARD_SERVLET_PATH_ATTRIBUTE, "/origServlet");
|
||||
|
||||
|
||||
assertEquals("/origApp/origServlet", context.getPathToServlet());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||
public class RequestDataValueProcessorWrapper implements RequestDataValueProcessor {
|
||||
|
||||
private RequestDataValueProcessor processor;
|
||||
|
||||
|
||||
public void setRequestDataValueProcessor(RequestDataValueProcessor processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ServletUriComponentsBuilderTests {
|
||||
this.request.setServerPort(80);
|
||||
this.request.setContextPath("/mvc-showcase");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void fromRequest() {
|
||||
request.setRequestURI("/mvc-showcase/data/param");
|
||||
@@ -61,16 +61,16 @@ public class ServletUriComponentsBuilderTests {
|
||||
public void fromRequestAtypicalHttpPort() {
|
||||
request.setServerPort(8080);
|
||||
String result = ServletUriComponentsBuilder.fromRequest(request).build().toUriString();
|
||||
|
||||
|
||||
assertEquals("http://localhost:8080", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void fromRequestAtypicalHttpsPort() {
|
||||
request.setScheme("https");
|
||||
request.setServerPort(9043);
|
||||
String result = ServletUriComponentsBuilder.fromRequest(request).build().toUriString();
|
||||
|
||||
|
||||
assertEquals("https://localhost:9043", result);
|
||||
}
|
||||
|
||||
@@ -88,9 +88,9 @@ public class ServletUriComponentsBuilderTests {
|
||||
request.setRequestURI("/mvc-showcase/data/param");
|
||||
request.setQueryString("foo=123");
|
||||
String result = ServletUriComponentsBuilder.fromContextPath(request).build().toUriString();
|
||||
|
||||
|
||||
assertEquals("http://localhost/mvc-showcase", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromServletMapping() {
|
||||
@@ -98,9 +98,9 @@ public class ServletUriComponentsBuilderTests {
|
||||
request.setServletPath("/app");
|
||||
request.setQueryString("foo=123");
|
||||
String result = ServletUriComponentsBuilder.fromServletMapping(request).build().toUriString();
|
||||
|
||||
|
||||
assertEquals("http://localhost/mvc-showcase/app", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromCurrentRequest() {
|
||||
@@ -116,5 +116,5 @@ public class ServletUriComponentsBuilderTests {
|
||||
RequestContextHolder.resetRequestAttributes();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -159,16 +159,16 @@ public class EvalTagTests extends AbstractTagTests {
|
||||
|
||||
|
||||
public static class Bean {
|
||||
|
||||
|
||||
public String method() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
|
||||
@NumberFormat(style=Style.PERCENT)
|
||||
public BigDecimal getFormattable() {
|
||||
return new BigDecimal(".25");
|
||||
}
|
||||
|
||||
|
||||
public String html() {
|
||||
return "<p>";
|
||||
}
|
||||
@@ -176,7 +176,7 @@ public class EvalTagTests extends AbstractTagTests {
|
||||
public String getBean() {
|
||||
return "not the bean object";
|
||||
}
|
||||
|
||||
|
||||
public Object getNull() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -300,7 +300,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
|
||||
assertEquals("Correct message", "test & text", message.toString());
|
||||
}
|
||||
|
||||
|
||||
public void testMessageTagWithTextAndExpressionArgumentFormat() throws JspException {
|
||||
PageContext pc = createPageContext();
|
||||
final StringBuffer message = new StringBuffer();
|
||||
@@ -354,12 +354,12 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
MessageTag tag = new MessageTag();
|
||||
tag.setPageContext(pc);
|
||||
tag.setText("text & text");
|
||||
tag.setVar("testvar");
|
||||
tag.setVar("testvar");
|
||||
tag.setScope("page");
|
||||
tag.doStartTag();
|
||||
assertEquals("text & text", pc.getAttribute("testvar"));
|
||||
tag.release();
|
||||
|
||||
|
||||
tag = new MessageTag();
|
||||
tag.setPageContext(pc);
|
||||
tag.setCode("test");
|
||||
@@ -374,7 +374,7 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
MessageTag tag = new MessageTag();
|
||||
tag.setPageContext(pc);
|
||||
tag.setText("text & text");
|
||||
tag.setVar("testvar");
|
||||
tag.setVar("testvar");
|
||||
tag.doStartTag();
|
||||
assertEquals("text & text", pc.getAttribute("testvar"));
|
||||
tag.release();
|
||||
@@ -383,11 +383,11 @@ public class MessageTagTests extends AbstractTagTests {
|
||||
tag.setPageContext(pc);
|
||||
tag.setCode("test");
|
||||
tag.setVar("testvar");
|
||||
|
||||
|
||||
tag.doStartTag();
|
||||
assertEquals("Correct message", "test message", pc.getAttribute("testvar"));
|
||||
}
|
||||
|
||||
|
||||
public void testNullMessageSource() throws JspException {
|
||||
PageContext pc = createPageContext();
|
||||
ConfigurableWebApplicationContext ctx = (ConfigurableWebApplicationContext)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -26,7 +26,7 @@ import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
|
||||
/**
|
||||
* Unit tests for ParamTag
|
||||
*
|
||||
*
|
||||
* @author Scott Andrews
|
||||
*/
|
||||
public class ParamTagTests extends AbstractTagTests {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -20,7 +20,7 @@ import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for Param
|
||||
*
|
||||
*
|
||||
* @author Scott Andrews
|
||||
*/
|
||||
public class ParamTests extends TestCase {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -34,7 +34,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for UrlTag
|
||||
*
|
||||
*
|
||||
* @author Scott Andrews
|
||||
*/
|
||||
public class UrlTagTests extends AbstractTagTests {
|
||||
|
||||
@@ -104,7 +104,7 @@ public abstract class AbstractHtmlElementTagTests extends AbstractTagTests {
|
||||
RequestDataValueProcessor mockProcessor = createMock(RequestDataValueProcessor.class);
|
||||
ServletRequest request = getPageContext().getRequest();
|
||||
StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.getWebApplicationContext(request);
|
||||
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
|
||||
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
|
||||
return mockProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@ public class ButtonTagTests extends AbstractFormTagTests {
|
||||
this.tag.setName("My Name");
|
||||
this.tag.setValue("My Button");
|
||||
}
|
||||
|
||||
|
||||
public void testButtonTag() throws Exception {
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, this.tag.doStartTag());
|
||||
assertEquals(Tag.EVAL_PAGE, this.tag.doEndTag());
|
||||
|
||||
|
||||
String output = getOutput();
|
||||
assertTagOpened(output);
|
||||
assertTagClosed(output);
|
||||
@@ -52,10 +52,10 @@ public class ButtonTagTests extends AbstractFormTagTests {
|
||||
assertContainsAttribute(output, "value", "My Button");
|
||||
assertAttributeNotPresent(output, "disabled");
|
||||
}
|
||||
|
||||
|
||||
public void testDisabled() throws Exception {
|
||||
this.tag.setDisabled("true");
|
||||
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ButtonTagTests extends AbstractFormTagTests {
|
||||
|
||||
assertContainsAttribute(output, "disabled", "disabled");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TestBean createTestBean() {
|
||||
return new TestBean();
|
||||
@@ -78,7 +78,7 @@ public class ButtonTagTests extends AbstractFormTagTests {
|
||||
protected final void assertTagOpened(String output) {
|
||||
assertTrue("Tag not opened properly", output.startsWith("<button "));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
protected ButtonTag createTag(final Writer writer) {
|
||||
return new ButtonTag() {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
assertEquals("checked", checkboxElement.attribute("checked").getValue());
|
||||
assertEquals("true", checkboxElement.attribute("value").getValue());
|
||||
}
|
||||
|
||||
|
||||
public void testWithIndexedBooleanObjectNotChecked() throws Exception {
|
||||
this.tag.setPath("someMap[key]");
|
||||
int result = this.tag.doStartTag();
|
||||
@@ -110,7 +110,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
this.tag.setPath("someBoolean");
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
|
||||
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
String output = getOutput();
|
||||
@@ -612,7 +612,7 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
assertEquals("checked", checkboxElement.attribute("checked").getValue());
|
||||
assertEquals("true", checkboxElement.attribute("value").getValue());
|
||||
}
|
||||
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "email");
|
||||
@@ -622,8 +622,8 @@ public class CheckboxTagTests extends AbstractFormTagTests {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Date getDate() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 10);
|
||||
|
||||
@@ -105,16 +105,16 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
assertEquals("baz", checkboxElement3.attribute("value").getValue());
|
||||
assertEquals("baz", spanElement3.getStringValue());
|
||||
}
|
||||
|
||||
|
||||
public void testWithMultiValueArrayAndDynamicAttributes() throws Exception {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
|
||||
this.tag.setPath("stringArray");
|
||||
this.tag.setItems(new Object[] {"foo", "bar", "baz"});
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
|
||||
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
|
||||
@@ -257,12 +257,12 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
tag.setItemValue("name");
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
|
||||
|
||||
String output = getOutput();
|
||||
|
||||
|
||||
// wrap the output so it is valid XML
|
||||
output = "<doc>" + output + "</doc>";
|
||||
|
||||
|
||||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new StringReader(output));
|
||||
Element spanElement1 = (Element) document.getRootElement().elements().get(0);
|
||||
@@ -544,15 +544,15 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
this.tag.setItems(allPets);
|
||||
this.tag.setItemValue("name");
|
||||
this.tag.setItemLabel("label");
|
||||
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
|
||||
|
||||
String output = getOutput();
|
||||
|
||||
|
||||
// wrap the output so it is valid XML
|
||||
output = "<doc>" + output + "</doc>";
|
||||
|
||||
|
||||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new StringReader(output));
|
||||
Element spanElement1 = (Element) document.getRootElement().elements().get(0);
|
||||
@@ -687,7 +687,7 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
assertEquals("disabled", checkboxElement.attribute("disabled").getValue());
|
||||
assertEquals("foo", checkboxElement.attribute("value").getValue());
|
||||
}
|
||||
|
||||
|
||||
public void testSpanElementCustomizable() throws Exception {
|
||||
this.tag.setPath("stringArray");
|
||||
this.tag.setItems(new Object[] {"foo", "bar", "baz"});
|
||||
@@ -714,8 +714,8 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Date getDate() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 10);
|
||||
@@ -742,7 +742,7 @@ public class CheckboxesTagTests extends AbstractFormTagTests {
|
||||
Set someObjects = new HashSet();
|
||||
someObjects.add(new ItemPet("PET1"));
|
||||
someObjects.add(new ItemPet("PET2"));
|
||||
|
||||
|
||||
this.bean = new TestBean();
|
||||
this.bean.setDate(getDate());
|
||||
this.bean.setName("Rob Harrop");
|
||||
|
||||
@@ -159,11 +159,11 @@ public class ErrorsTagTests extends AbstractFormTagTests {
|
||||
assertBlockTagContains(output, "Default Message");
|
||||
assertBlockTagContains(output, "Too Short");
|
||||
}
|
||||
|
||||
|
||||
public void testWithErrorsAndDynamicAttributes() throws Exception {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
|
||||
|
||||
|
||||
@@ -39,14 +39,14 @@ import org.springframework.web.servlet.support.RequestDataValueProcessor;
|
||||
* @author Jeremy Grelle
|
||||
*/
|
||||
public class FormTagTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
|
||||
private static final String REQUEST_URI = "/my/form";
|
||||
|
||||
private static final String QUERY_STRING = "foo=bar";
|
||||
|
||||
|
||||
private FormTag tag;
|
||||
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
|
||||
@@ -187,25 +187,10 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
|
||||
assertEquals("<form id=\"command\" action=\"/my/form?foo=bar&stuff="><script>alert('XSS!')</script>\" method=\"post\">",
|
||||
getOutput());
|
||||
}
|
||||
|
||||
|
||||
public void testGet() throws Exception {
|
||||
this.tag.setMethod("get");
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
this.tag.doFinally();
|
||||
|
||||
String output = getOutput();
|
||||
String formOutput = getFormTag(output);
|
||||
String inputOutput = getInputTag(output);
|
||||
|
||||
assertContainsAttribute(formOutput, "method", "get");
|
||||
assertEquals("", inputOutput);
|
||||
}
|
||||
|
||||
public void testPost() throws Exception {
|
||||
this.tag.setMethod("post");
|
||||
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
this.tag.doFinally();
|
||||
@@ -213,14 +198,29 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
|
||||
String output = getOutput();
|
||||
String formOutput = getFormTag(output);
|
||||
String inputOutput = getInputTag(output);
|
||||
|
||||
|
||||
assertContainsAttribute(formOutput, "method", "get");
|
||||
assertEquals("", inputOutput);
|
||||
}
|
||||
|
||||
public void testPost() throws Exception {
|
||||
this.tag.setMethod("post");
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
this.tag.doFinally();
|
||||
|
||||
String output = getOutput();
|
||||
String formOutput = getFormTag(output);
|
||||
String inputOutput = getInputTag(output);
|
||||
|
||||
assertContainsAttribute(formOutput, "method", "post");
|
||||
assertEquals("", inputOutput);
|
||||
}
|
||||
|
||||
|
||||
public void testPut() throws Exception {
|
||||
this.tag.setMethod("put");
|
||||
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
this.tag.doFinally();
|
||||
@@ -234,10 +234,10 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
|
||||
assertContainsAttribute(inputOutput, "value", "put");
|
||||
assertContainsAttribute(inputOutput, "type", "hidden");
|
||||
}
|
||||
|
||||
|
||||
public void testDelete() throws Exception {
|
||||
this.tag.setMethod("delete");
|
||||
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
this.tag.doFinally();
|
||||
@@ -251,11 +251,11 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
|
||||
assertContainsAttribute(inputOutput, "value", "delete");
|
||||
assertContainsAttribute(inputOutput, "type", "hidden");
|
||||
}
|
||||
|
||||
|
||||
public void testCustomMethodParameter() throws Exception {
|
||||
this.tag.setMethod("put");
|
||||
this.tag.setMethodParam("methodParameter");
|
||||
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
this.tag.doFinally();
|
||||
@@ -279,24 +279,24 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
|
||||
this.tag.doFinally();
|
||||
assertNull(getPageContext().getAttribute(FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, PageContext.REQUEST_SCOPE));
|
||||
}
|
||||
|
||||
|
||||
public void testRequestDataValueProcessorHooks() throws Exception {
|
||||
String action = "/my/form?foo=bar";
|
||||
RequestDataValueProcessor processor = getMockRequestDataValueProcessor();
|
||||
expect(processor.processAction(this.request, action)).andReturn(action);
|
||||
expect(processor.getExtraHiddenFields(this.request)).andReturn(Collections.singletonMap("key", "value"));
|
||||
replay(processor);
|
||||
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
this.tag.doFinally();
|
||||
|
||||
|
||||
String output = getOutput();
|
||||
|
||||
|
||||
assertEquals("<input type=\"hidden\" name=\"key\" value=\"value\"></input>", getInputTag(output));
|
||||
assertFormTagOpened(output);
|
||||
assertFormTagClosed(output);
|
||||
|
||||
|
||||
verify(processor);
|
||||
}
|
||||
|
||||
@@ -320,5 +320,5 @@ public class FormTagTests extends AbstractHtmlElementTagTests {
|
||||
private static void assertFormTagClosed(String output) {
|
||||
assertTrue(output.endsWith("</form>"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||
assertContainsAttribute(output, "type", "hidden");
|
||||
assertContainsAttribute(output, "value", "12.34f");
|
||||
}
|
||||
|
||||
|
||||
public void testDynamicTypeAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "email");
|
||||
@@ -86,7 +86,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||
|
||||
public void testDisabledTrue() throws Exception {
|
||||
this.tag.setDisabled("true");
|
||||
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
|
||||
@@ -98,10 +98,10 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||
}
|
||||
|
||||
// SPR-8661
|
||||
|
||||
|
||||
public void testDisabledFalse() throws Exception {
|
||||
this.tag.setDisabled("false");
|
||||
|
||||
|
||||
this.tag.doStartTag();
|
||||
this.tag.doEndTag();
|
||||
|
||||
@@ -111,7 +111,7 @@ public class HiddenInputTagTests extends AbstractFormTagTests {
|
||||
|
||||
assertAttributeNotPresent(output, "disabled");
|
||||
}
|
||||
|
||||
|
||||
private void assertTagClosed(String output) {
|
||||
assertTrue(output.endsWith("/>"));
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ public class InputTagTests extends AbstractFormTagTests {
|
||||
assertContainsAttribute(output, "type", "number");
|
||||
assertValueAttribute(output, "12.34");
|
||||
}
|
||||
|
||||
|
||||
public void testDynamicTypeRadioAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "radio");
|
||||
@@ -366,7 +366,7 @@ public class InputTagTests extends AbstractFormTagTests {
|
||||
assertEquals("Attribute type=\"radio\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testDynamicTypeCheckboxAttribute() throws JspException {
|
||||
try {
|
||||
this.tag.setDynamicAttribute(null, "type", "checkbox");
|
||||
@@ -376,7 +376,7 @@ public class InputTagTests extends AbstractFormTagTests {
|
||||
assertEquals("Attribute type=\"checkbox\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected final void assertTagClosed(String output) {
|
||||
assertTrue("Tag not closed properly", output.endsWith("/>"));
|
||||
}
|
||||
|
||||
@@ -71,15 +71,15 @@ public class LabelTagTests extends AbstractFormTagTests {
|
||||
assertTrue(output.startsWith("<label "));
|
||||
assertTrue(output.endsWith("</label>"));
|
||||
}
|
||||
|
||||
|
||||
public void testSimpleRenderWithDynamicAttributes() throws Exception {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
|
||||
this.tag.setPath("name");
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
|
||||
|
||||
|
||||
int startResult = this.tag.doStartTag();
|
||||
int endResult = this.tag.doEndTag();
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.web.servlet.support.BindStatus;
|
||||
public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||
|
||||
private OptionTag tag;
|
||||
|
||||
|
||||
private SelectTag parentTag;
|
||||
|
||||
protected void onSetUp() {
|
||||
@@ -40,7 +40,7 @@ public class OptionTagEnumTests extends AbstractHtmlElementTagTests {
|
||||
};
|
||||
this.parentTag = new SelectTag() {
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
return "testName";
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
};
|
||||
this.parentTag = new SelectTag() {
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
return "testName";
|
||||
}
|
||||
@@ -106,18 +106,18 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
|
||||
assertContainsAttribute(output, "value", "bar");
|
||||
assertBlockTagContains(output, "Bar");
|
||||
}
|
||||
|
||||
|
||||
public void testRenderWithDynamicAttributes() throws Exception {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
|
||||
String selectName = "testBean.name";
|
||||
getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), selectName, false));
|
||||
this.tag.setValue("bar");
|
||||
this.tag.setLabel("Bar");
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
|
||||
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
|
||||
result = this.tag.doEndTag();
|
||||
|
||||
@@ -65,7 +65,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
return new TagWriter(getWriter());
|
||||
}
|
||||
public String getName() {
|
||||
// Should not be used other than to delegate to
|
||||
// Should not be used other than to delegate to
|
||||
// RequestDataValueDataProcessor
|
||||
return "testName";
|
||||
}
|
||||
@@ -103,11 +103,11 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
assertEquals("myClass", element.attribute("class").getValue());
|
||||
assertEquals("CLICK", element.attribute("onclick").getValue());
|
||||
}
|
||||
|
||||
|
||||
public void testWithCollectionAndDynamicAttributes() throws Exception {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
|
||||
getPageContext().setAttribute(
|
||||
SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));
|
||||
|
||||
@@ -119,7 +119,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
this.tag.setOnclick("CLICK");
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
|
||||
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
String output = getOutput();
|
||||
@@ -203,18 +203,18 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
this.tag.setItemValue("isoCode");
|
||||
this.tag.setItemLabel("name");
|
||||
this.selectTag.setPath("testBean");
|
||||
|
||||
|
||||
this.selectTag.doStartTag();
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
this.tag.doEndTag();
|
||||
this.selectTag.doEndTag();
|
||||
|
||||
|
||||
String output = getOutput();
|
||||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new StringReader(output));
|
||||
Element rootElement = document.getRootElement();
|
||||
|
||||
|
||||
List children = rootElement.elements();
|
||||
assertEquals("Incorrect number of children", 0, children.size());
|
||||
}
|
||||
@@ -223,7 +223,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
BeanWithEnum testBean = new BeanWithEnum();
|
||||
testBean.setTestEnum(TestEnum.VALUE_2);
|
||||
getPageContext().getRequest().setAttribute("testBean", testBean);
|
||||
|
||||
|
||||
this.selectTag.setPath("testBean.testEnum");
|
||||
|
||||
this.selectTag.doStartTag();
|
||||
@@ -237,7 +237,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new StringReader(output));
|
||||
Element rootElement = document.getRootElement();
|
||||
|
||||
|
||||
assertEquals(2, rootElement.elements().size());
|
||||
Node value1 = rootElement.selectSingleNode("option[@value = 'VALUE_1']");
|
||||
Node value2 = rootElement.selectSingleNode("option[@value = 'VALUE_2']");
|
||||
@@ -250,7 +250,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
BeanWithEnum testBean = new BeanWithEnum();
|
||||
testBean.setTestEnum(TestEnum.VALUE_2);
|
||||
getPageContext().getRequest().setAttribute("testBean", testBean);
|
||||
|
||||
|
||||
this.selectTag.setPath("testBean.testEnum");
|
||||
this.tag.setItemLabel("enumLabel");
|
||||
this.tag.setItemValue("enumValue");
|
||||
@@ -266,7 +266,7 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new StringReader(output));
|
||||
Element rootElement = document.getRootElement();
|
||||
|
||||
|
||||
assertEquals(2, rootElement.elements().size());
|
||||
Node value1 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_1']");
|
||||
Node value2 = rootElement.selectSingleNode("option[@value = 'Value: VALUE_2']");
|
||||
@@ -304,5 +304,5 @@ public final class OptionsTagTests extends AbstractHtmlElementTagTests {
|
||||
RequestContext context = new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
|
||||
pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -55,12 +55,12 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
|
||||
public void testWithCheckedValue() throws Exception {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
|
||||
this.tag.setPath("sex");
|
||||
this.tag.setValue("M");
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
|
||||
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
|
||||
@@ -74,7 +74,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
|
||||
assertContainsAttribute(output, dynamicAttribute1, dynamicAttribute1);
|
||||
assertContainsAttribute(output, dynamicAttribute2, dynamicAttribute2);
|
||||
}
|
||||
|
||||
|
||||
public void testWithCheckedValueAndDynamicAttributes() throws Exception {
|
||||
this.tag.setPath("sex");
|
||||
this.tag.setValue("M");
|
||||
@@ -237,7 +237,7 @@ public class RadioButtonTagTests extends AbstractFormTagTests {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void assertTagOpened(String output) {
|
||||
assertTrue(output.indexOf("<input ") > -1);
|
||||
}
|
||||
|
||||
@@ -99,11 +99,11 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
assertEquals("baz", radioButtonElement3.attribute("value").getValue());
|
||||
assertEquals("baz", spanElement3.getStringValue());
|
||||
}
|
||||
|
||||
|
||||
public void testWithMultiValueArrayAndDynamicAttributes() throws Exception {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
|
||||
this.tag.setPath("stringArray");
|
||||
this.tag.setItems(new Object[] {"foo", "bar", "baz"});
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
@@ -460,12 +460,12 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
assertEquals("Mufty", radioButtonElement5.attribute("value").getValue());
|
||||
assertEquals("MUFTY", spanElement5.getStringValue());
|
||||
}
|
||||
|
||||
|
||||
public void testWithoutItemsEnumBindTarget() throws Exception {
|
||||
BeanWithEnum testBean = new BeanWithEnum();
|
||||
testBean.setTestEnum(TestEnum.VALUE_2);
|
||||
getPageContext().getRequest().setAttribute("testBean", testBean);
|
||||
|
||||
|
||||
this.tag.setPath("testEnum");
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
@@ -474,7 +474,7 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new StringReader(output));
|
||||
Element rootElement = document.getRootElement();
|
||||
|
||||
|
||||
assertEquals(2, rootElement.elements().size());
|
||||
Node value1 = rootElement.selectSingleNode("//input[@value = 'VALUE_1']");
|
||||
Node value2 = rootElement.selectSingleNode("//input[@value = 'VALUE_2']");
|
||||
@@ -482,12 +482,12 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
assertEquals("TestEnum: VALUE_2", rootElement.selectSingleNode("//label[@for = '" + value2.valueOf("@id") + "']").getText());
|
||||
assertEquals(value2, rootElement.selectSingleNode("//input[@checked]"));
|
||||
}
|
||||
|
||||
|
||||
public void testWithoutItemsEnumBindTargetWithExplicitLabelsAndValues() throws Exception {
|
||||
BeanWithEnum testBean = new BeanWithEnum();
|
||||
testBean.setTestEnum(TestEnum.VALUE_2);
|
||||
getPageContext().getRequest().setAttribute("testBean", testBean);
|
||||
|
||||
|
||||
this.tag.setPath("testEnum");
|
||||
this.tag.setItemLabel("enumLabel");
|
||||
this.tag.setItemValue("enumValue");
|
||||
@@ -498,7 +498,7 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
SAXReader reader = new SAXReader();
|
||||
Document document = reader.read(new StringReader(output));
|
||||
Element rootElement = document.getRootElement();
|
||||
|
||||
|
||||
assertEquals(2, rootElement.elements().size());
|
||||
Node value1 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_1']");
|
||||
Node value2 = rootElement.selectSingleNode("//input[@value = 'Value: VALUE_2']");
|
||||
@@ -569,7 +569,7 @@ public final class RadioButtonsTagTests extends AbstractFormTagTests {
|
||||
assertEquals("Attribute type=\"email\" is not allowed", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Date getDate() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.YEAR, 10);
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
this.tag.setItemLabel("name");
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2);
|
||||
|
||||
|
||||
int result = this.tag.doStartTag();
|
||||
assertEquals(Tag.SKIP_BODY, result);
|
||||
|
||||
@@ -846,7 +846,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
private TestBean getTestBean() {
|
||||
return (TestBean) getPageContext().getRequest().getAttribute(COMMAND_NAME);
|
||||
}
|
||||
|
||||
|
||||
public static class TestBeanWrapper {
|
||||
private TestBean bean;
|
||||
|
||||
@@ -857,7 +857,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||
public void setBean(TestBean bean) {
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package org.springframework.web.servlet.tags.form;
|
||||
|
||||
/**
|
||||
* Test related data types for <code>org.springframework.web.servlet.tags.form</code> package.
|
||||
*
|
||||
*
|
||||
* @author Scott Andrews
|
||||
*/
|
||||
public class TestTypes { }
|
||||
|
||||
class BeanWithEnum {
|
||||
|
||||
|
||||
private TestEnum testEnum;
|
||||
|
||||
public TestEnum getTestEnum() {
|
||||
|
||||
@@ -52,11 +52,11 @@ public class TextareaTagTests extends AbstractFormTagTests {
|
||||
assertContainsAttribute(output, "readonly", "readonly");
|
||||
assertBlockTagContains(output, "Rob");
|
||||
}
|
||||
|
||||
|
||||
public void testSimpleBindWithDynamicAttributes() throws Exception {
|
||||
String dynamicAttribute1 = "attr1";
|
||||
String dynamicAttribute2 = "attr2";
|
||||
|
||||
|
||||
this.tag.setPath("name");
|
||||
this.tag.setReadonly("true");
|
||||
this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1);
|
||||
@@ -87,7 +87,7 @@ public class TextareaTagTests extends AbstractFormTagTests {
|
||||
public void testSimpleBindWithHtmlEscaping() throws Exception {
|
||||
final String NAME = "Rob \"I Love Mangos\" Harrop";
|
||||
final String HTML_ESCAPED_NAME = "Rob "I Love Mangos" Harrop";
|
||||
|
||||
|
||||
this.tag.setPath("name");
|
||||
this.rob.setName(NAME);
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
@@ -49,7 +49,7 @@ import org.springframework.web.servlet.View;
|
||||
public class BaseViewTests extends TestCase {
|
||||
|
||||
public void testRenderWithoutStaticAttributes() throws Exception {
|
||||
|
||||
|
||||
WebApplicationContext wac = createMock(WebApplicationContext.class);
|
||||
wac.getServletContext();
|
||||
expectLastCall().andReturn(new MockServletContext());
|
||||
@@ -58,11 +58,11 @@ public class BaseViewTests extends TestCase {
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
HttpServletResponse response = new MockHttpServletResponse();
|
||||
TestView tv = new TestView(wac);
|
||||
|
||||
|
||||
// Check superclass handles duplicate init
|
||||
tv.setApplicationContext(wac);
|
||||
tv.setApplicationContext(wac);
|
||||
|
||||
tv.setApplicationContext(wac);
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("foo", "bar");
|
||||
model.put("something", new Object());
|
||||
@@ -70,11 +70,11 @@ public class BaseViewTests extends TestCase {
|
||||
|
||||
// check it contains all
|
||||
checkContainsAll(model, tv.model);
|
||||
|
||||
|
||||
assertTrue(tv.inited);
|
||||
verify(wac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test attribute passing, NOT CSV parsing.
|
||||
*/
|
||||
@@ -87,13 +87,13 @@ public class BaseViewTests extends TestCase {
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
HttpServletResponse response = new MockHttpServletResponse();
|
||||
TestView tv = new TestView(wac);
|
||||
|
||||
|
||||
tv.setApplicationContext(wac);
|
||||
Properties p = new Properties();
|
||||
Properties p = new Properties();
|
||||
p.setProperty("foo", "bar");
|
||||
p.setProperty("something", "else");
|
||||
tv.setAttributes(p);
|
||||
|
||||
tv.setAttributes(p);
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("one", new HashMap<Object, Object>());
|
||||
model.put("two", new Object());
|
||||
@@ -102,7 +102,7 @@ public class BaseViewTests extends TestCase {
|
||||
// Check it contains all
|
||||
checkContainsAll(model, tv.model);
|
||||
checkContainsAll(p, tv.model);
|
||||
|
||||
|
||||
assertTrue(tv.inited);
|
||||
verify(wac);
|
||||
}
|
||||
@@ -118,17 +118,17 @@ public class BaseViewTests extends TestCase {
|
||||
|
||||
TestView tv = new TestView(wac);
|
||||
tv.setApplicationContext(wac);
|
||||
|
||||
Properties p = new Properties();
|
||||
|
||||
Properties p = new Properties();
|
||||
p.setProperty("one", "bar");
|
||||
p.setProperty("something", "else");
|
||||
tv.setAttributes(p);
|
||||
|
||||
tv.setAttributes(p);
|
||||
|
||||
Map<String, Object> pathVars = new HashMap<String, Object>();
|
||||
pathVars.put("one", new HashMap<Object, Object>());
|
||||
pathVars.put("two", new Object());
|
||||
request.setAttribute(View.PATH_VARIABLES, pathVars);
|
||||
|
||||
|
||||
tv.render(new HashMap<String, Object>(), request, response);
|
||||
|
||||
// Check it contains all
|
||||
@@ -140,7 +140,7 @@ public class BaseViewTests extends TestCase {
|
||||
assertTrue(tv.inited);
|
||||
verify(wac);
|
||||
}
|
||||
|
||||
|
||||
public void testDynamicModelOverridesStaticAttributesIfCollision() throws Exception {
|
||||
WebApplicationContext wac = createMock(WebApplicationContext.class);
|
||||
wac.getServletContext();
|
||||
@@ -152,10 +152,10 @@ public class BaseViewTests extends TestCase {
|
||||
TestView tv = new TestView(wac);
|
||||
|
||||
tv.setApplicationContext(wac);
|
||||
Properties p = new Properties();
|
||||
Properties p = new Properties();
|
||||
p.setProperty("one", "bar");
|
||||
p.setProperty("something", "else");
|
||||
tv.setAttributes(p);
|
||||
tv.setAttributes(p);
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("one", new HashMap<Object, Object>());
|
||||
@@ -204,13 +204,13 @@ public class BaseViewTests extends TestCase {
|
||||
assertTrue(tv.inited);
|
||||
verify(wac);
|
||||
}
|
||||
|
||||
|
||||
public void testIgnoresNullAttributes() {
|
||||
AbstractView v = new ConcreteView();
|
||||
v.setAttributes(null);
|
||||
assertTrue(v.getStaticAttributes().size() == 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test only the CSV parsing implementation.
|
||||
*/
|
||||
@@ -219,13 +219,13 @@ public class BaseViewTests extends TestCase {
|
||||
v.setAttributesCSV(null);
|
||||
assertTrue(v.getStaticAttributes().size() == 0);
|
||||
}
|
||||
|
||||
|
||||
public void testAttributeCSVParsingIgnoresEmptyString() {
|
||||
AbstractView v = new ConcreteView();
|
||||
v.setAttributesCSV("");
|
||||
assertTrue(v.getStaticAttributes().size() == 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format is attname0={value1},attname1={value1}
|
||||
*/
|
||||
@@ -236,7 +236,7 @@ public class BaseViewTests extends TestCase {
|
||||
assertTrue(v.getStaticAttributes().get("foo").equals("bar"));
|
||||
assertTrue(v.getStaticAttributes().get("king").equals("kong"));
|
||||
}
|
||||
|
||||
|
||||
public void testAttributeCSVParsingValidWithWeirdCharacters() {
|
||||
AbstractView v = new ConcreteView();
|
||||
String fooval = "owfie fue&3[][[[2 \n\n \r \t 8\ufffd3";
|
||||
@@ -247,7 +247,7 @@ public class BaseViewTests extends TestCase {
|
||||
assertTrue(v.getStaticAttributes().get("foo").equals(fooval));
|
||||
assertTrue(v.getStaticAttributes().get("king").equals(kingval));
|
||||
}
|
||||
|
||||
|
||||
public void testAttributeCSVParsingInvalid() {
|
||||
AbstractView v = new ConcreteView();
|
||||
try {
|
||||
@@ -257,7 +257,7 @@ public class BaseViewTests extends TestCase {
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// No value
|
||||
v.setAttributesCSV("fweoiruiu=");
|
||||
@@ -265,7 +265,7 @@ public class BaseViewTests extends TestCase {
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// No closing ]
|
||||
v.setAttributesCSV("fweoiruiu=[");
|
||||
@@ -281,13 +281,13 @@ public class BaseViewTests extends TestCase {
|
||||
catch (IllegalArgumentException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testAttributeCSVParsingIgoresTrailingComma() {
|
||||
AbstractView v = new ConcreteView();
|
||||
v.setAttributesCSV("foo=[de],");
|
||||
assertTrue(v.getStaticAttributes().size() == 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that all keys in expected have same values in actual
|
||||
* @param expected
|
||||
@@ -299,10 +299,10 @@ public class BaseViewTests extends TestCase {
|
||||
for (Iterator<String> iter = keys.iterator(); iter.hasNext();) {
|
||||
String key = (String) iter.next();
|
||||
//System.out.println("Checking model key " + key);
|
||||
assertTrue("Value for model key '" + key + "' must match", actual.get(key) == expected.get(key));
|
||||
assertTrue("Value for model key '" + key + "' must match", actual.get(key) == expected.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trivial concrete subclass we can use when we're interested only
|
||||
* in CSV parsing, which doesn't require lifecycle management
|
||||
@@ -322,13 +322,13 @@ public class BaseViewTests extends TestCase {
|
||||
private class TestView extends AbstractView {
|
||||
private WebApplicationContext wac;
|
||||
public boolean inited;
|
||||
|
||||
|
||||
/** Captured model in render */
|
||||
public Map<String, Object> model;
|
||||
|
||||
|
||||
public TestView(WebApplicationContext wac) {
|
||||
this.wac = wac;
|
||||
|
||||
|
||||
}
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
@@ -63,7 +63,7 @@ public class InternalResourceViewTests extends TestCase {
|
||||
model.put("I", obj);
|
||||
|
||||
String url = "forward-to";
|
||||
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myservlet/handler.do");
|
||||
request.setContextPath("/mycontext");
|
||||
request.setServletPath("/myservlet");
|
||||
|
||||
@@ -116,7 +116,7 @@ public class RedirectViewTests {
|
||||
assertEquals(301, response.getStatus());
|
||||
assertEquals("http://url.somewhere.com", response.getHeader("Location"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void attributeStatusCodeHttp11() throws Exception {
|
||||
RedirectView rv = new RedirectView();
|
||||
@@ -129,7 +129,7 @@ public class RedirectViewTests {
|
||||
assertEquals(201, response.getStatus());
|
||||
assertEquals("http://url.somewhere.com", response.getHeader("Location"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void flashMap() throws Exception {
|
||||
RedirectView rv = new RedirectView();
|
||||
@@ -144,21 +144,21 @@ public class RedirectViewTests {
|
||||
rv.render(model, request, response);
|
||||
assertEquals(303, response.getStatus());
|
||||
assertEquals("http://url.somewhere.com/path?id=1", response.getHeader("Location"));
|
||||
|
||||
|
||||
assertEquals("/path", flashMap.getTargetRequestPath());
|
||||
assertEquals(model, flashMap.getTargetRequestParams().toSingleValueMap());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void updateTargetUrl() throws Exception {
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
|
||||
wac.setServletContext(new MockServletContext());
|
||||
wac.refresh();
|
||||
|
||||
|
||||
RequestDataValueProcessor mockProcessor = createMock(RequestDataValueProcessor.class);
|
||||
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
|
||||
|
||||
|
||||
RedirectView rv = new RedirectView();
|
||||
rv.setApplicationContext(wac); // Init RedirectView with WebAppCxt
|
||||
rv.setUrl("/path");
|
||||
@@ -175,7 +175,7 @@ public class RedirectViewTests {
|
||||
EasyMock.verify(mockProcessor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void updateTargetUrlWithContextLoader() throws Exception {
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
@@ -183,7 +183,7 @@ public class RedirectViewTests {
|
||||
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
ContextLoader contextLoader = new ContextLoader(wac);
|
||||
contextLoader.initWebApplicationContext(servletContext);
|
||||
contextLoader.initWebApplicationContext(servletContext);
|
||||
|
||||
try {
|
||||
RequestDataValueProcessor mockProcessor = createMock(RequestDataValueProcessor.class);
|
||||
@@ -251,7 +251,7 @@ public class RedirectViewTests {
|
||||
String expectedUrlForEncoding = "http://url.somewhere.com/test.htm" + "?" + key + "=" + val + "#myAnchor";
|
||||
doTest(model, url, false, expectedUrlForEncoding);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void contextRelativeQueryParam() throws Exception {
|
||||
String url = "/test.html?id=1";
|
||||
@@ -376,7 +376,7 @@ public class RedirectViewTests {
|
||||
|
||||
FlashMapManager flashMapManager = new SessionFlashMapManager();
|
||||
expect(request.getAttribute(DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE)).andReturn(flashMapManager);
|
||||
|
||||
|
||||
HttpServletResponse response = createMock("response", HttpServletResponse.class);
|
||||
expect(response.encodeRedirectURL(expectedUrlForEncoding)).andReturn(expectedUrlForEncoding);
|
||||
response.sendRedirect(expectedUrlForEncoding);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class RedirectViewUriTemplateTests {
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.request = new MockHttpServletRequest();
|
||||
@@ -56,7 +56,7 @@ public class RedirectViewUriTemplateTests {
|
||||
|
||||
assertEquals(baseUrl + "/bar", this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uriTemplateEncode() throws Exception {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
@@ -68,7 +68,7 @@ public class RedirectViewUriTemplateTests {
|
||||
|
||||
assertEquals(baseUrl + "/context path/bar%2Fbar%20baz", this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uriTemplateAndArrayQueryParam() throws Exception {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
@@ -98,7 +98,7 @@ public class RedirectViewUriTemplateTests {
|
||||
model.put("key1", "value1");
|
||||
model.put("name", "value2");
|
||||
model.put("key3", "value3");
|
||||
|
||||
|
||||
Map<String, String> currentRequestUriTemplateVars = new HashMap<String, String>();
|
||||
currentRequestUriTemplateVars.put("var1", "v1");
|
||||
currentRequestUriTemplateVars.put("name", "v2");
|
||||
@@ -116,7 +116,7 @@ public class RedirectViewUriTemplateTests {
|
||||
public void uriTemplateNullValue() throws Exception {
|
||||
new RedirectView("/{foo}").renderMergedOutputModel(new ModelMap(), this.request, this.response);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void emptyRedirectString() throws Exception {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
@@ -138,5 +138,5 @@ public class RedirectViewUriTemplateTests {
|
||||
|
||||
assertEquals(url, this.response.getRedirectedUrl());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -20,7 +20,7 @@ package org.springframework.web.servlet.view;
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class ResourceBundleViewResolverNoCacheTests extends ResourceBundleViewResolverTests {
|
||||
|
||||
|
||||
protected boolean getCache() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ResourceBundleViewResolverTests extends TestCase {
|
||||
private static String PROPS_FILE = "org.springframework.web.servlet.view.testviews";
|
||||
|
||||
private ResourceBundleViewResolver rb;
|
||||
|
||||
|
||||
private StaticWebApplicationContext wac;
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class ResourceBundleViewResolverTests extends TestCase {
|
||||
assertTrue("test has correct name", "test".equals(tv.getBeanName()));
|
||||
assertTrue("test should have been initialized once, not " + tv.initCount + " times", tv.initCount == 1);
|
||||
}
|
||||
|
||||
|
||||
public void testNoSuchBasename() throws Exception {
|
||||
try {
|
||||
rb.setBasename("weoriwoierqupowiuer");
|
||||
|
||||
@@ -485,13 +485,13 @@ public class ViewResolverTests {
|
||||
InternalResourceViewResolver vr = new InternalResourceViewResolver();
|
||||
vr.setViewClass(JstlView.class);
|
||||
vr.setApplicationContext(wac);
|
||||
|
||||
View view = vr.resolveViewName("example1", Locale.getDefault());
|
||||
|
||||
View view = vr.resolveViewName("example1", Locale.getDefault());
|
||||
View cached = vr.resolveViewName("example1", Locale.getDefault());
|
||||
if (view != cached) {
|
||||
fail("Caching doesn't work");
|
||||
}
|
||||
|
||||
|
||||
vr.removeFromCache("example1", Locale.getDefault());
|
||||
cached = vr.resolveViewName("example1", Locale.getDefault());
|
||||
if (view == cached) {
|
||||
@@ -515,11 +515,11 @@ public class ViewResolverTests {
|
||||
|
||||
viewResolver.resolveViewName("view", Locale.getDefault());
|
||||
viewResolver.resolveViewName("view", Locale.getDefault());
|
||||
|
||||
|
||||
assertEquals(2, count.intValue());
|
||||
|
||||
viewResolver.setCacheUnresolved(true);
|
||||
|
||||
|
||||
viewResolver.resolveViewName("view", Locale.getDefault());
|
||||
viewResolver.resolveViewName("view", Locale.getDefault());
|
||||
viewResolver.resolveViewName("view", Locale.getDefault());
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -105,7 +105,7 @@ public class ExcelViewTests extends TestCase {
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
HSSFSheet sheet = wb.getSheet("Sheet1");
|
||||
|
||||
|
||||
// test all possible permutation of row or column not existing
|
||||
HSSFCell cell = getCell(sheet, 2, 4);
|
||||
cell.setCellValue("Test Value");
|
||||
@@ -139,7 +139,7 @@ public class ExcelViewTests extends TestCase {
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
HSSFSheet sheet = wb.getSheet("Sheet1");
|
||||
|
||||
|
||||
// test all possible permutation of row or column not existing
|
||||
HSSFCell cell = getCell(sheet, 2, 4);
|
||||
cell.setCellValue("Test Value");
|
||||
@@ -173,7 +173,7 @@ public class ExcelViewTests extends TestCase {
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
HSSFSheet sheet = wb.getSheet("Sheet1");
|
||||
|
||||
|
||||
// test all possible permutation of row or column not existing
|
||||
HSSFCell cell = getCell(sheet, 2, 4);
|
||||
cell.setCellValue("Test Value");
|
||||
|
||||
@@ -35,4 +35,3 @@ public class ConfigurableJasperReportsViewWithStreamTests extends AbstractConfig
|
||||
return "application/pdf";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ConfigurableJasperReportsViewWithWriterTests extends AbstractConfig
|
||||
view.setExporterClass(JRPdfExporter.class);
|
||||
view.setUseWriter(false);
|
||||
view.setContentType("text/html");
|
||||
return view;
|
||||
return view;
|
||||
}
|
||||
|
||||
protected String getDesiredContentType() {
|
||||
|
||||
@@ -100,17 +100,17 @@ public class VelocityViewTests {
|
||||
public void testMergeTemplateSucceeds() throws Exception {
|
||||
testValidTemplateName(null);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMergeTemplateFailureWithIOException() throws Exception {
|
||||
testValidTemplateName(new IOException());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMergeTemplateFailureWithParseErrorException() throws Exception {
|
||||
testValidTemplateName(new ParseErrorException(""));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMergeTemplateFailureWithUnspecifiedException() throws Exception {
|
||||
testValidTemplateName(new Exception(""));
|
||||
@@ -241,7 +241,7 @@ public class VelocityViewTests {
|
||||
expectLastCall().andReturn(null);
|
||||
wac.getServletContext();
|
||||
expectLastCall().andReturn(new MockServletContext());
|
||||
|
||||
|
||||
final Template expectedTemplate = new Template();
|
||||
VelocityConfig vc = new VelocityConfig() {
|
||||
public VelocityEngine getVelocityEngine() {
|
||||
|
||||
@@ -46,7 +46,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link AbstractXsltView} class.
|
||||
*
|
||||
*
|
||||
* @author Darren Davison
|
||||
* @author Rick Evans
|
||||
* @author Juergen Hoeller
|
||||
@@ -325,7 +325,7 @@ public class TestXsltViewTests extends TestCase {
|
||||
wordList.add("hello");
|
||||
wordList.add("world");
|
||||
map.put("wordList", wordList);
|
||||
|
||||
|
||||
view.render(new ModelAndView("home", map).getModel(), request, response);
|
||||
String text = response.getContentAsString();
|
||||
assertTrue(text.trim().startsWith("<html"));
|
||||
|
||||
Reference in New Issue
Block a user