language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | spring-projects | spring-framework | 028e15faa33888673bfc7b55eaa65eb93f7bca0c.json | Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.
Issue: SPR-8420 | spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-3.2.xsd | @@ -120,6 +120,22 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
+ <xsd:attribute name="content-negotiation-manager" type="xsd:string">
+ <xsd:annotation>
+ <xsd:documentation source="java:org.springframework.web.accept.ContentNegotiationManager"><![CDATA[
+ The bean name of a ContentNegotiationManager that is to be used to determine requested media types. If not specified,
+ a default ContentNegotiationManager is configured that checks the request path extension first and the "Accept" header
+ second where path extensions such as ".json", ".xml", ".atom", and ".rss" are recognized if Jackson, JAXB2, or the
+ Rome libraries are available. As a fallback option, the path extension is also used to perform a lookup through
+ the ServletContext and the Java Activation Framework (if available).
+ ]]></xsd:documentation>
+ <xsd:appinfo>
+ <tool:annotation kind="ref">
+ <tool:expected-type type="java:org.springframework.web.accept.ContentNegotiationManager" />
+ </tool:annotation>
+ </xsd:appinfo>
+ </xsd:annotation>
+ </xsd:attribute>
<xsd:attribute name="message-codes-resolver" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[ | true |
Other | spring-projects | spring-framework | 028e15faa33888673bfc7b55eaa65eb93f7bca0c.json | Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.
Issue: SPR-8420 | spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java | @@ -19,6 +19,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@@ -38,6 +39,7 @@
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
+import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -49,8 +51,11 @@
import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
+import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.support.InvocableHandlerMethod;
@@ -98,13 +103,18 @@ public void setUp() throws Exception {
@Test
public void testDefaultConfig() throws Exception {
- loadBeanDefinitions("mvc-config.xml", 11);
+ loadBeanDefinitions("mvc-config.xml", 12);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
assertEquals(0, mapping.getOrder());
mapping.setDefaultHandler(handlerMethod);
+ MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
+ NativeWebRequest webRequest = new ServletWebRequest(request);
+ ContentNegotiationManager manager = mapping.getContentNegotiationManager();
+ assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
+
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
@@ -118,7 +128,7 @@ public void testDefaultConfig() throws Exception {
assertNotNull(appContext.getBean(Validator.class));
// default web binding initializer behavior test
- MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
+ request = new MockHttpServletRequest("GET", "/");
request.addParameter("date", "2009-10-31");
MockHttpServletResponse response = new MockHttpServletResponse();
@@ -135,7 +145,7 @@ public void testDefaultConfig() throws Exception {
@Test(expected=TypeMismatchException.class)
public void testCustomConversionService() throws Exception {
- loadBeanDefinitions("mvc-config-custom-conversion-service.xml", 11);
+ loadBeanDefinitions("mvc-config-custom-conversion-service.xml", 12);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
@@ -161,7 +171,7 @@ public void testCustomConversionService() throws Exception {
@Test
public void testCustomValidator() throws Exception {
- loadBeanDefinitions("mvc-config-custom-validator.xml", 11);
+ loadBeanDefinitions("mvc-config-custom-validator.xml", 12);
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
@@ -179,7 +189,7 @@ public void testCustomValidator() throws Exception {
@Test
public void testInterceptors() throws Exception {
- loadBeanDefinitions("mvc-config-interceptors.xml", 16);
+ loadBeanDefinitions("mvc-config-interceptors.xml", 17);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
@@ -308,7 +318,7 @@ public void testDefaultServletHandlerWithOptionalAttributes() throws Exception {
@Test
public void testBeanDecoration() throws Exception {
- loadBeanDefinitions("mvc-config-bean-decoration.xml", 13);
+ loadBeanDefinitions("mvc-config-bean-decoration.xml", 14);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
@@ -329,7 +339,7 @@ public void testBeanDecoration() throws Exception {
@Test
public void testViewControllers() throws Exception {
- loadBeanDefinitions("mvc-config-view-controllers.xml", 14);
+ loadBeanDefinitions("mvc-config-view-controllers.xml", 15);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
@@ -389,7 +399,7 @@ public void testViewControllers() throws Exception {
/** WebSphere gives trailing servlet path slashes by default!! */
@Test
public void testViewControllersOnWebSphere() throws Exception {
- loadBeanDefinitions("mvc-config-view-controllers.xml", 14);
+ loadBeanDefinitions("mvc-config-view-controllers.xml", 15);
SimpleUrlHandlerMapping mapping2 = appContext.getBean(SimpleUrlHandlerMapping.class);
SimpleControllerHandlerAdapter adapter = appContext.getBean(SimpleControllerHandlerAdapter.class);
@@ -440,6 +450,19 @@ public void testViewControllersDefaultConfig() {
assertEquals(2, beanNameMapping.getOrder());
}
+ @Test
+ public void testCustomContentNegotiationManager() throws Exception {
+ loadBeanDefinitions("mvc-config-content-negotiation-manager.xml", 14);
+
+ RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
+ ContentNegotiationManager manager = mapping.getContentNegotiationManager();
+
+ MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
+ NativeWebRequest webRequest = new ServletWebRequest(request);
+ assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));
+ }
+
+
private void loadBeanDefinitions(String fileName, int expectedBeanCount) {
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
ClassPathResource resource = new ClassPathResource(fileName, AnnotationDrivenBeanDefinitionParserTests.class);
@@ -448,6 +471,7 @@ private void loadBeanDefinitions(String fileName, int expectedBeanCount) {
appContext.refresh();
}
+
@Controller
public static class TestController {
| true |
Other | spring-projects | spring-framework | 028e15faa33888673bfc7b55eaa65eb93f7bca0c.json | Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.
Issue: SPR-8420 | spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurerTests.java | @@ -0,0 +1,112 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.web.servlet.config.annotation;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.http.MediaType;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.web.accept.ContentNegotiationManager;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.context.request.ServletWebRequest;
+
+/**
+ * Test fixture for {@link ContentNegotiationConfigurer} tests.
+ * @author Rossen Stoyanchev
+ */
+public class ContentNegotiationConfigurerTests {
+
+ private ContentNegotiationConfigurer configurer;
+
+ private NativeWebRequest webRequest;
+
+ private MockHttpServletRequest servletRequest;
+
+ @Before
+ public void setup() {
+ this.configurer = new ContentNegotiationConfigurer();
+ this.servletRequest = new MockHttpServletRequest();
+ this.webRequest = new ServletWebRequest(this.servletRequest);
+ }
+
+ @Test
+ public void defaultSettings() throws Exception {
+ ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();
+
+ this.servletRequest.setRequestURI("/flower.gif");
+
+ assertEquals("Should be able to resolve file extensions by default",
+ Arrays.asList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest));
+
+ this.servletRequest.setRequestURI("/flower?format=gif");
+ this.servletRequest.addParameter("format", "gif");
+
+ assertEquals("Should not resolve request parameters by default",
+ Collections.emptyList(), manager.resolveMediaTypes(this.webRequest));
+
+ this.servletRequest.setRequestURI("/flower");
+ this.servletRequest.addHeader("Accept", MediaType.IMAGE_GIF_VALUE);
+
+ assertEquals("Should resolve Accept header by default",
+ Arrays.asList(MediaType.IMAGE_GIF), manager.resolveMediaTypes(this.webRequest));
+ }
+
+ @Test
+ public void addMediaTypes() throws Exception {
+ this.configurer.addMediaTypes(Collections.singletonMap("json", MediaType.APPLICATION_JSON));
+ ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();
+
+ this.servletRequest.setRequestURI("/flower.json");
+ assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
+ }
+
+ @Test
+ public void favorParameter() throws Exception {
+ this.configurer.setFavorParameter(true);
+ this.configurer.setParameterName("f");
+ this.configurer.addMediaTypes(Collections.singletonMap("json", MediaType.APPLICATION_JSON));
+ ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();
+
+ this.servletRequest.setRequestURI("/flower");
+ this.servletRequest.addParameter("f", "json");
+
+ assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
+ }
+
+ @Test
+ public void ignoreAcceptHeader() throws Exception {
+ this.configurer.setIgnoreAcceptHeader(true);
+ ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();
+
+ this.servletRequest.setRequestURI("/flower");
+ this.servletRequest.addHeader("Accept", MediaType.IMAGE_GIF_VALUE);
+
+ assertEquals(Collections.emptyList(), manager.resolveMediaTypes(this.webRequest));
+ }
+
+ @Test
+ public void setDefaultContentType() throws Exception {
+ this.configurer.setDefaultContentType(MediaType.APPLICATION_JSON);
+ ContentNegotiationManager manager = this.configurer.getContentNegotiationManager();
+
+ assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(this.webRequest));
+ }
+} | true |
Other | spring-projects | spring-framework | 028e15faa33888673bfc7b55eaa65eb93f7bca0c.json | Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.
Issue: SPR-8420 | spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java | @@ -67,11 +67,13 @@ public void setUp() {
@Test
public void requestMappingHandlerAdapter() throws Exception {
Capture<List<HttpMessageConverter<?>>> converters = new Capture<List<HttpMessageConverter<?>>>();
+ Capture<ContentNegotiationConfigurer> contentNegotiationConfigurer = new Capture<ContentNegotiationConfigurer>();
Capture<FormattingConversionService> conversionService = new Capture<FormattingConversionService>();
Capture<List<HandlerMethodArgumentResolver>> resolvers = new Capture<List<HandlerMethodArgumentResolver>>();
Capture<List<HandlerMethodReturnValueHandler>> handlers = new Capture<List<HandlerMethodReturnValueHandler>>();
configurer.configureMessageConverters(capture(converters));
+ configurer.configureContentNegotiation(capture(contentNegotiationConfigurer));
expect(configurer.getValidator()).andReturn(null);
expect(configurer.getMessageCodesResolver()).andReturn(null);
configurer.addFormatters(capture(conversionService));
@@ -135,8 +137,10 @@ public void getCustomMessageCodesResolver() {
public void handlerExceptionResolver() throws Exception {
Capture<List<HttpMessageConverter<?>>> converters = new Capture<List<HttpMessageConverter<?>>>();
Capture<List<HandlerExceptionResolver>> exceptionResolvers = new Capture<List<HandlerExceptionResolver>>();
+ Capture<ContentNegotiationConfigurer> contentNegotiationConfigurer = new Capture<ContentNegotiationConfigurer>();
configurer.configureMessageConverters(capture(converters));
+ configurer.configureContentNegotiation(capture(contentNegotiationConfigurer));
configurer.configureHandlerExceptionResolvers(capture(exceptionResolvers));
replay(configurer);
| true |
Other | spring-projects | spring-framework | 028e15faa33888673bfc7b55eaa65eb93f7bca0c.json | Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.
Issue: SPR-8420 | spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportTests.java | @@ -21,6 +21,7 @@
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
@@ -34,6 +35,7 @@
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionService;
+import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -45,8 +47,11 @@
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
+import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
+import org.springframework.web.context.request.NativeWebRequest;
+import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.method.annotation.ModelAttributeMethodProcessor;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
@@ -182,6 +187,24 @@ public void webMvcConfigurerExtensionHooks() throws Exception {
String actual = webConfig.mvcConversionService().convert(new TestBean(), String.class);
assertEquals("converted", actual);
+ MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
+ NativeWebRequest webRequest = new ServletWebRequest(request);
+ ContentNegotiationManager manager = webConfig.requestMappingHandlerMapping().getContentNegotiationManager();
+ assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
+
+ request.setRequestURI("/foo.xml");
+ assertEquals(Arrays.asList(MediaType.APPLICATION_XML), manager.resolveMediaTypes(webRequest));
+
+ request.setRequestURI("/foo.rss");
+ assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));
+
+ request.setRequestURI("/foo.atom");
+ assertEquals(Arrays.asList(MediaType.APPLICATION_ATOM_XML), manager.resolveMediaTypes(webRequest));
+
+ request.setRequestURI("/foo");
+ request.setParameter("f", "json");
+ assertEquals(Arrays.asList(MediaType.APPLICATION_JSON), manager.resolveMediaTypes(webRequest));
+
RequestMappingHandlerAdapter adapter = webConfig.requestMappingHandlerAdapter();
assertEquals(1, adapter.getMessageConverters().size());
@@ -242,7 +265,6 @@ public void webMvcConfigurerExtensionHooks() throws Exception {
@Controller
private static class TestController {
- @SuppressWarnings("unused")
@RequestMapping("/")
public void handle() {
}
@@ -287,6 +309,11 @@ public boolean supports(Class<?> clazz) {
};
}
+ @Override
+ public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
+ configurer.setFavorParameter(true).setParameterName("f");
+ }
+
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new ModelAttributeMethodProcessor(true)); | true |
Other | spring-projects | spring-framework | 028e15faa33888673bfc7b55eaa65eb93f7bca0c.json | Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.
Issue: SPR-8420 | spring-webmvc/src/test/resources/org/springframework/web/servlet/config/mvc-config-content-negotiation-manager.xml | @@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:mvc="http://www.springframework.org/schema/mvc"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
+
+ <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
+
+ <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManager">
+ <constructor-arg>
+ <list>
+ <ref bean="pathExtensionStrategy" />
+ <ref bean="headerStrategy" />
+ </list>
+ </constructor-arg>
+ </bean>
+
+ <bean id="pathExtensionStrategy" class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
+ <constructor-arg>
+ <map>
+ <entry key="xml" value="application/rss+xml" />
+ </map>
+ </constructor-arg>
+ </bean>
+
+ <bean id="headerStrategy" class="org.springframework.web.accept.HeaderContentNegotiationStrategy" />
+
+</beans> | true |
Other | spring-projects | spring-framework | 028e15faa33888673bfc7b55eaa65eb93f7bca0c.json | Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.
Issue: SPR-8420 | src/dist/changelog.txt | @@ -26,6 +26,7 @@ Changes in version 3.2 M2 (2012-08-xx)
* use reflection to instantiate StandardServletAsyncWebRequest
* fix issue with forward before async request processing
* add exclude patterns for mapped interceptors in MVC namespace and MVC Java config
+* support content negotiation options in MVC namespace and MVC Java config
Changes in version 3.2 M1 (2012-05-28) | true |
Other | spring-projects | spring-framework | 028e15faa33888673bfc7b55eaa65eb93f7bca0c.json | Add options to configure content negotiation
The MVC Java config and the MVC namespace now support options to
configure content negotiation. By default both support checking path
extensions first and the "Accept" header second. For path extensions
.json, .xml, .atom, and .rss are recognized out of the box if the
Jackson, JAXB2, or Rome libraries are available. The ServletContext
and the Java Activation Framework may be used as fallback options
for path extension lookups.
Issue: SPR-8420 | src/reference/docbook/mvc.xml | @@ -4478,6 +4478,54 @@ public class WebConfig extends WebMvcConfigurerAdapter {
</section>
+ <section id="mvc-config-content-negotiation">
+ <title>Configuring Content Negotiation</title>
+
+ <para>You can configure how Spring MVC determines requested media types for content negotiation purposes.
+ The available strategies are to check the request path extension, a
+ request parameter, the "Accept" header, and also to use a default content type.</para>
+
+ <para>By default the path extension is checked first and the "Accept"
+ header is checked second. The path extension check recognizes ".json" if Jackson is available,
+ ".xml" if JAXB2 is available, and ".atom" and ".rss" if the Rome library is available.
+ It also uses the <classname>ServletContext</classname> and the <emphasis>Java Activation Framework</emphasis>
+ to perform lookups as a fallback option.</para>
+
+ <para>An example of customizing content negotiation in Java:</para>
+
+ <programlisting language="java">@EnableWebMvc
+@Configuration
+public class WebConfig extends WebMvcConfigurerAdapter {
+
+ @Override
+ public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
+ configurer.setFavorPathExtension(false).setFavorParameter(true);
+ }
+}</programlisting>
+
+ <para>In XML you'll need to use the <code>content-negotiation-manager</code> property:</para>
+
+ <programlisting language="xml"><mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
+
+<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManager">
+ <constructor-arg>
+ <list>
+ <ref bean="pathExtensionStrategy" />
+ <bean id="headerStrategy" class="org.springframework.web.accept.HeaderContentNegotiationStrategy"/>
+ </list>
+ </constructor-arg>
+</bean>
+
+<bean id="pathExtensionStrategy" class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
+ <constructor-arg>
+ <map>
+ <entry key="xml" value="application/rss+xml" />
+ </map>
+ </constructor-arg>
+</bean></programlisting>
+
+ </section>
+
<section id="mvc-config-view-controller">
<title>Configuring View Controllers</title>
| true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | spring-webmvc/src/main/java/org/springframework/web/servlet/config/InterceptorsBeanDefinitionParser.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * 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.
@@ -31,7 +31,7 @@
/**
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that parses a {@code interceptors} element to register
* a set of {@link MappedInterceptor} definitions.
- *
+ *
* @author Keith Donald
* @since 3.0
*/
@@ -40,37 +40,44 @@ class InterceptorsBeanDefinitionParser implements BeanDefinitionParser {
public BeanDefinition parse(Element element, ParserContext parserContext) {
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
parserContext.pushContainingComponent(compDefinition);
-
+
List<Element> interceptors = DomUtils.getChildElementsByTagName(element, new String[] { "bean", "ref", "interceptor" });
for (Element interceptor : interceptors) {
RootBeanDefinition mappedInterceptorDef = new RootBeanDefinition(MappedInterceptor.class);
mappedInterceptorDef.setSource(parserContext.extractSource(interceptor));
mappedInterceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
-
- String[] pathPatterns;
+
+ String[] includePatterns = null;
+ String[] excludePatterns = null;
Object interceptorBean;
if ("interceptor".equals(interceptor.getLocalName())) {
- List<Element> paths = DomUtils.getChildElementsByTagName(interceptor, "mapping");
- pathPatterns = new String[paths.size()];
- for (int i = 0; i < paths.size(); i++) {
- pathPatterns[i] = paths.get(i).getAttribute("path");
- }
+ includePatterns = getIncludePatterns(interceptor, "mapping");
+ excludePatterns = getIncludePatterns(interceptor, "exclude-mapping");
Element beanElem = DomUtils.getChildElementsByTagName(interceptor, new String[] { "bean", "ref"}).get(0);
interceptorBean = parserContext.getDelegate().parsePropertySubElement(beanElem, null);
}
else {
- pathPatterns = null;
interceptorBean = parserContext.getDelegate().parsePropertySubElement(interceptor, null);
}
- mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, pathPatterns);
- mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, interceptorBean);
+ mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns);
+ mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns);
+ mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(2, interceptorBean);
String beanName = parserContext.getReaderContext().registerWithGeneratedName(mappedInterceptorDef);
parserContext.registerComponent(new BeanComponentDefinition(mappedInterceptorDef, beanName));
}
-
+
parserContext.popAndRegisterContainingComponent();
return null;
}
+ private String[] getIncludePatterns(Element interceptor, String elementName) {
+ List<Element> paths = DomUtils.getChildElementsByTagName(interceptor, elementName);
+ String[] patterns = new String[paths.size()];
+ for (int i = 0; i < paths.size(); i++) {
+ patterns[i] = paths.get(i).getAttribute("path");
+ }
+ return patterns;
+ }
+
} | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * 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.
@@ -21,22 +21,24 @@
import java.util.List;
import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.MappedInterceptor;
/**
- * Encapsulates a {@link HandlerInterceptor} and an optional list of URL patterns.
- * Results in the creation of a {@link MappedInterceptor} if URL patterns are provided.
- *
+ * Assists with the creation of a {@link MappedInterceptor}.
+ *
* @author Rossen Stoyanchev
* @author Keith Donald
* @since 3.1
*/
public class InterceptorRegistration {
private final HandlerInterceptor interceptor;
-
- private final List<String> pathPatterns = new ArrayList<String>();
+
+ private final List<String> includePatterns = new ArrayList<String>();
+
+ private final List<String> excludePatterns = new ArrayList<String>();
/**
* Creates an {@link InterceptorRegistration} instance.
@@ -47,22 +49,39 @@ public InterceptorRegistration(HandlerInterceptor interceptor) {
}
/**
- * Adds one or more URL patterns to which the registered interceptor should apply to.
- * If no URL patterns are provided, the interceptor applies to all paths.
+ * Add URL patterns to which the registered interceptor should apply to.
*/
- public void addPathPatterns(String... pathPatterns) {
- this.pathPatterns.addAll(Arrays.asList(pathPatterns));
+ public InterceptorRegistration addPathPatterns(String... patterns) {
+ this.includePatterns.addAll(Arrays.asList(patterns));
+ return this;
}
/**
- * Returns the underlying interceptor. If URL patterns are provided the returned type is
+ * Add URL patterns to which the registered interceptor should not apply to.
+ */
+ public InterceptorRegistration excludePathPatterns(String... patterns) {
+ this.excludePatterns.addAll(Arrays.asList(patterns));
+ return this;
+ }
+
+ /**
+ * Returns the underlying interceptor. If URL patterns are provided the returned type is
* {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}.
*/
protected Object getInterceptor() {
- if (pathPatterns.isEmpty()) {
- return interceptor;
+ if (this.includePatterns.isEmpty()) {
+ return this.interceptor;
+ }
+ return new MappedInterceptor(toArray(this.includePatterns), toArray(this.excludePatterns), interceptor);
+ }
+
+ private static String[] toArray(List<String> list) {
+ if (CollectionUtils.isEmpty(list)) {
+ return null;
+ }
+ else {
+ return list.toArray(new String[list.size()]);
}
- return new MappedInterceptor(pathPatterns.toArray(new String[pathPatterns.size()]), interceptor);
}
} | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * 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.
@@ -29,38 +29,58 @@
* @since 3.0
*/
public final class MappedInterceptor {
-
- private final String[] pathPatterns;
-
+
+ private final String[] includePatterns;
+
+ private final String[] excludePatterns;
+
private final HandlerInterceptor interceptor;
+ /**
+ * Create a new MappedInterceptor instance.
+ * @param includePatterns the path patterns to map with a {@code null} value matching to all paths
+ * @param interceptor the HandlerInterceptor instance to map to the given patterns
+ */
+ public MappedInterceptor(String[] includePatterns, HandlerInterceptor interceptor) {
+ this(includePatterns, null, interceptor);
+ }
+
/**
* Create a new MappedInterceptor instance.
* @param pathPatterns the path patterns to map with a {@code null} value matching to all paths
* @param interceptor the HandlerInterceptor instance to map to the given patterns
*/
- public MappedInterceptor(String[] pathPatterns, HandlerInterceptor interceptor) {
- this.pathPatterns = pathPatterns;
+ public MappedInterceptor(String[] includePatterns, String[] excludePatterns, HandlerInterceptor interceptor) {
+ this.includePatterns = includePatterns;
+ this.excludePatterns = excludePatterns;
this.interceptor = interceptor;
}
/**
* Create a new MappedInterceptor instance.
- * @param pathPatterns the path patterns to map with a {@code null} value matching to all paths
+ * @param includePatterns the path patterns to map with a {@code null} value matching to all paths
* @param interceptor the WebRequestInterceptor instance to map to the given patterns
*/
- public MappedInterceptor(String[] pathPatterns, WebRequestInterceptor interceptor) {
- this.pathPatterns = pathPatterns;
- this.interceptor = new WebRequestHandlerInterceptorAdapter(interceptor);
+ public MappedInterceptor(String[] includePatterns, WebRequestInterceptor interceptor) {
+ this(includePatterns, null, interceptor);
+ }
+
+ /**
+ * Create a new MappedInterceptor instance.
+ * @param includePatterns the path patterns to map with a {@code null} value matching to all paths
+ * @param interceptor the WebRequestInterceptor instance to map to the given patterns
+ */
+ public MappedInterceptor(String[] includePatterns, String[] excludePatterns, WebRequestInterceptor interceptor) {
+ this(includePatterns, excludePatterns, new WebRequestHandlerInterceptorAdapter(interceptor));
}
/**
* The path into the application the interceptor is mapped to.
*/
public String[] getPathPatterns() {
- return this.pathPatterns;
+ return this.includePatterns;
}
/**
@@ -69,19 +89,26 @@ public String[] getPathPatterns() {
public HandlerInterceptor getInterceptor() {
return this.interceptor;
}
-
+
/**
- * Returns {@code true} if the interceptor applies to the given request path.
+ * Returns {@code true} if the interceptor applies to the given request path.
* @param lookupPath the current request path
* @param pathMatcher a path matcher for path pattern matching
*/
public boolean matches(String lookupPath, PathMatcher pathMatcher) {
- if (pathPatterns == null) {
+ if (this.excludePatterns != null) {
+ for (String pattern : this.excludePatterns) {
+ if (pathMatcher.match(pattern, lookupPath)) {
+ return false;
+ }
+ }
+ }
+ if (this.includePatterns == null) {
return true;
}
else {
- for (String pathPattern : pathPatterns) {
- if (pathMatcher.match(pathPattern, lookupPath)) {
+ for (String pattern : this.includePatterns) {
+ if (pathMatcher.match(pattern, lookupPath)) {
return true;
}
} | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-3.2.xsd | @@ -273,6 +273,18 @@
</xsd:attribute>
</xsd:complexType>
</xsd:element>
+ <xsd:element name="exclude-mapping" minOccurs="0" maxOccurs="unbounded">
+ <xsd:complexType>
+ <xsd:attribute name="path" type="xsd:string" use="required">
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+ A path into the application that should not be intercepted by this interceptor.
+ Exact path mapping URIs (such as "/admin") are supported as well as Ant-stype path patterns (such as /admin/**).
+ ]]></xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
<xsd:choice>
<xsd:element ref="beans:bean">
<xsd:annotation> | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java | @@ -80,7 +80,7 @@
public class MvcNamespaceTests {
private GenericWebApplicationContext appContext;
-
+
private TestController handler;
private HandlerMethod handlerMethod;
@@ -90,7 +90,7 @@ public void setUp() throws Exception {
appContext = new GenericWebApplicationContext();
appContext.setServletContext(new TestMockServletContext());
LocaleContextHolder.setLocale(Locale.US);
-
+
handler = new TestController();
Method method = TestController.class.getMethod("testBind", Date.class, TestBean.class, BindingResult.class);
handlerMethod = new InvocableHandlerMethod(handler, method);
@@ -104,11 +104,11 @@ public void testDefaultConfig() throws Exception {
assertNotNull(mapping);
assertEquals(0, mapping.getOrder());
mapping.setDefaultHandler(handlerMethod);
-
+
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
-
+
List<HttpMessageConverter<?>> messageConverters = adapter.getMessageConverters();
assertTrue(messageConverters.size() > 0);
@@ -128,7 +128,7 @@ public void testDefaultConfig() throws Exception {
ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
interceptor.preHandle(request, response, handlerMethod);
assertSame(appContext.getBean(ConversionService.class), request.getAttribute(ConversionService.class.getName()));
-
+
adapter.handle(request, response, handlerMethod);
assertTrue(handler.recordedValidationError);
}
@@ -140,7 +140,7 @@ public void testCustomConversionService() throws Exception {
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
-
+
// default web binding initializer behavior test
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.setRequestURI("/accounts/12345");
@@ -153,7 +153,7 @@ public void testCustomConversionService() throws Exception {
ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
interceptor.preHandle(request, response, handler);
assertSame(appContext.getBean("conversionService"), request.getAttribute(ConversionService.class.getName()));
-
+
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
adapter.handle(request, response, handlerMethod);
@@ -176,15 +176,15 @@ public void testCustomValidator() throws Exception {
assertTrue(appContext.getBean(TestValidator.class).validatorInvoked);
assertFalse(handler.recordedValidationError);
}
-
+
@Test
public void testInterceptors() throws Exception {
loadBeanDefinitions("mvc-config-interceptors.xml", 16);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
-
+
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.setRequestURI("/accounts/12345");
request.addParameter("locale", "en");
@@ -197,6 +197,10 @@ public void testInterceptors() throws Exception {
assertTrue(chain.getInterceptors()[2] instanceof WebRequestHandlerInterceptorAdapter);
assertTrue(chain.getInterceptors()[3] instanceof ThemeChangeInterceptor);
+ request.setRequestURI("/admin/users");
+ chain = mapping.getHandler(request);
+ assertEquals(3, chain.getInterceptors().length);
+
request.setRequestURI("/logged/accounts/12345");
chain = mapping.getHandler(request);
assertEquals(5, chain.getInterceptors().length);
@@ -207,14 +211,14 @@ public void testInterceptors() throws Exception {
assertEquals(5, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);
}
-
+
@Test
public void testResources() throws Exception {
loadBeanDefinitions("mvc-config-resources.xml", 5);
HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
assertNotNull(adapter);
-
+
ResourceHttpRequestHandler handler = appContext.getBean(ResourceHttpRequestHandler.class);
assertNotNull(handler);
@@ -229,7 +233,7 @@ public void testResources() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/resources/foo.css");
request.setMethod("GET");
-
+
HandlerExecutionChain chain = mapping.getHandler(request);
assertTrue(chain.getHandler() instanceof ResourceHttpRequestHandler);
@@ -240,7 +244,7 @@ public void testResources() throws Exception {
ModelAndView mv = adapter.handle(request, response, chain.getHandler());
assertNull(mv);
}
-
+
@Test
public void testResourcesWithOptionalAttributes() throws Exception {
loadBeanDefinitions("mvc-config-resources-optional-attrs.xml", 5);
@@ -249,14 +253,14 @@ public void testResourcesWithOptionalAttributes() throws Exception {
assertNotNull(mapping);
assertEquals(5, mapping.getOrder());
}
-
+
@Test
public void testDefaultServletHandler() throws Exception {
loadBeanDefinitions("mvc-config-default-servlet.xml", 5);
HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
assertNotNull(adapter);
-
+
DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class);
assertNotNull(handler);
@@ -267,22 +271,22 @@ public void testDefaultServletHandler() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/foo.css");
request.setMethod("GET");
-
+
HandlerExecutionChain chain = mapping.getHandler(request);
assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler);
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = adapter.handle(request, response, chain.getHandler());
assertNull(mv);
}
-
+
@Test
public void testDefaultServletHandlerWithOptionalAttributes() throws Exception {
loadBeanDefinitions("mvc-config-default-servlet-optional-attrs.xml", 5);
HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
assertNotNull(adapter);
-
+
DefaultServletHttpRequestHandler handler = appContext.getBean(DefaultServletHttpRequestHandler.class);
assertNotNull(handler);
@@ -293,7 +297,7 @@ public void testDefaultServletHandlerWithOptionalAttributes() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/foo.css");
request.setMethod("GET");
-
+
HandlerExecutionChain chain = mapping.getHandler(request);
assertTrue(chain.getHandler() instanceof DefaultServletHttpRequestHandler);
@@ -308,28 +312,28 @@ public void testBeanDecoration() throws Exception {
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
- mapping.setDefaultHandler(handlerMethod);
+ mapping.setDefaultHandler(handlerMethod);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(3, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
- assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
+ assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1];
assertEquals("lang", interceptor.getParamName());
ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2];
assertEquals("style", interceptor2.getParamName());
}
-
+
@Test
public void testViewControllers() throws Exception {
loadBeanDefinitions("mvc-config-view-controllers.xml", 14);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
- mapping.setDefaultHandler(handlerMethod);
+ mapping.setDefaultHandler(handlerMethod);
BeanNameUrlHandlerMapping beanNameMapping = appContext.getBean(BeanNameUrlHandlerMapping.class);
assertNotNull(beanNameMapping);
@@ -349,7 +353,7 @@ public void testViewControllers() throws Exception {
SimpleControllerHandlerAdapter adapter = appContext.getBean(SimpleControllerHandlerAdapter.class);
assertNotNull(adapter);
-
+
request.setRequestURI("/foo");
chain = mapping2.getHandler(request);
assertEquals(4, chain.getInterceptors().length);
@@ -435,7 +439,7 @@ public void testViewControllersDefaultConfig() {
assertNotNull(beanNameMapping);
assertEquals(2, beanNameMapping.getOrder());
}
-
+
private void loadBeanDefinitions(String fileName, int expectedBeanCount) {
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
ClassPathResource resource = new ClassPathResource(fileName, AnnotationDrivenBeanDefinitionParserTests.class);
@@ -446,19 +450,19 @@ private void loadBeanDefinitions(String fileName, int expectedBeanCount) {
@Controller
public static class TestController {
-
+
private boolean recordedValidationError;
-
+
@RequestMapping
public void testBind(@RequestParam @DateTimeFormat(iso=ISO.DATE) Date date, @Validated(MyGroup.class) TestBean bean, BindingResult result) {
this.recordedValidationError = (result.getErrorCount() == 1);
}
}
-
+
public static class TestValidator implements Validator {
boolean validatorInvoked;
-
+
public boolean supports(Class<?> clazz) {
return true;
}
@@ -467,13 +471,13 @@ public void validate(Object target, Errors errors) {
this.validatorInvoked = true;
}
}
-
+
@Retention(RetentionPolicy.RUNTIME)
public @interface MyGroup {
}
private static class TestBean {
-
+
@NotNull(groups=MyGroup.class)
private String field;
@@ -487,7 +491,7 @@ public void setField(String field) {
this.field = field;
}
}
-
+
private static class TestMockServletContext extends MockServletContext {
@Override | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * 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.
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.junit.Before;
@@ -72,7 +73,7 @@ public void setUp() {
public void addInterceptor() {
registry.addInterceptor(interceptor1);
List<HandlerInterceptor> interceptors = getInterceptorsForPath(null);
-
+
assertEquals(Arrays.asList(interceptor1), interceptors);
}
@@ -81,24 +82,25 @@ public void addTwoInterceptors() {
registry.addInterceptor(interceptor1);
registry.addInterceptor(interceptor2);
List<HandlerInterceptor> interceptors = getInterceptorsForPath(null);
-
+
assertEquals(Arrays.asList(interceptor1, interceptor2), interceptors);
}
@Test
public void addInterceptorsWithUrlPatterns() {
- registry.addInterceptor(interceptor1).addPathPatterns("/path1");
+ registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").excludePathPatterns("/path1/secret");
registry.addInterceptor(interceptor2).addPathPatterns("/path2");
-
+
assertEquals(Arrays.asList(interceptor1), getInterceptorsForPath("/path1"));
assertEquals(Arrays.asList(interceptor2), getInterceptorsForPath("/path2"));
+ assertEquals(Collections.emptyList(), getInterceptorsForPath("/path1/secret"));
}
@Test
public void addWebRequestInterceptor() throws Exception {
registry.addWebRequestInterceptor(webRequestInterceptor1);
List<HandlerInterceptor> interceptors = getInterceptorsForPath(null);
-
+
assertEquals(1, interceptors.size());
verifyAdaptedInterceptor(interceptors.get(0), webRequestInterceptor1);
} | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java | @@ -0,0 +1,72 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.web.servlet.handler;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.util.AntPathMatcher;
+import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
+
+/**
+ * Test fixture for {@link MappedInterceptor} tests.
+ *
+ * @author Rossen Stoyanchev
+ */
+public class MappedInterceptorTests {
+
+ private LocaleChangeInterceptor interceptor;
+
+ private final AntPathMatcher pathMatcher = new AntPathMatcher();
+
+ @Before
+ public void setup() {
+ this.interceptor = new LocaleChangeInterceptor();
+ }
+
+ @Test
+ public void noPatterns() {
+ MappedInterceptor mappedInterceptor = new MappedInterceptor(null, null, this.interceptor);
+ assertTrue(mappedInterceptor.matches("/foo", pathMatcher));
+ }
+
+ @Test
+ public void includePatternOnly() {
+ MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] { "/foo/*" }, this.interceptor);
+
+ assertTrue(mappedInterceptor.matches("/foo/bar", pathMatcher));
+ assertFalse(mappedInterceptor.matches("/bar/foo", pathMatcher));
+ }
+
+ @Test
+ public void excludePatternOnly() {
+ MappedInterceptor mappedInterceptor = new MappedInterceptor(null, new String[] { "/admin/**" }, this.interceptor);
+
+ assertTrue(mappedInterceptor.matches("/foo", pathMatcher));
+ assertFalse(mappedInterceptor.matches("/admin/foo", pathMatcher));
+ }
+
+ @Test
+ public void includeAndExcludePatterns() {
+ MappedInterceptor mappedInterceptor = new MappedInterceptor(
+ new String[] { "/**" }, new String[] { "/admin/**" }, this.interceptor);
+
+ assertTrue(mappedInterceptor.matches("/foo", pathMatcher));
+ assertFalse(mappedInterceptor.matches("/admin/foo", pathMatcher));
+ }
+
+} | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | spring-webmvc/src/test/resources/org/springframework/web/servlet/config/mvc-config-interceptors.xml | @@ -3,7 +3,7 @@
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
+ http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<mvc:annotation-driven />
@@ -12,6 +12,8 @@
<ref bean="log4jInterceptor"/>
<mvc:interceptor>
<mvc:mapping path="/**" />
+ <mvc:exclude-mapping path="/admin/**" />
+ <mvc:exclude-mapping path="/images/**" />
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor" />
</mvc:interceptor>
<mvc:interceptor> | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | src/dist/changelog.txt | @@ -25,6 +25,7 @@ Changes in version 3.2 M2 (2012-08-xx)
* parameterize DeferredResult type
* use reflection to instantiate StandardServletAsyncWebRequest
* fix issue with forward before async request processing
+* add exclude patterns for mapped interceptors in MVC namespace and MVC Java config
Changes in version 3.2 M1 (2012-05-28) | true |
Other | spring-projects | spring-framework | 92759ed1f881fcb1a92aa661d80c53a2827e67db.json | Add exclude patterns for mapped interceptors
Add the ability provide exclude patterns for mapped interceptors in the
MVC namespace and in the MVC Java config.
Issue: SPR-6570 | src/reference/docbook/mvc.xml | @@ -4453,7 +4453,8 @@ public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(new LocalInterceptor());
+ registry.addInterceptor(new LocaleInterceptor());
+ registry.addInterceptor(new ThemeInterceptor()).addPathPatterns("/**").excludePathPatterns("/admin/**");
registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*");
}
@@ -4463,6 +4464,11 @@ public class WebConfig extends WebMvcConfigurerAdapter {
<programlisting language="xml"><mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
+ <mvc:interceptor>
+ <mapping path="/**"/>
+ <exclude-mapping path="/admin/**"/>
+ <bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor" />
+ </mvc:interceptor>
<mvc:interceptor>
<mapping path="/secure/*"/>
<bean class="org.example.SecurityInterceptor" /> | true |
Other | spring-projects | spring-framework | 5a365074c2bddb3e4517ec5eceb39d4e6ca85b56.json | Fix issue with failing test from previous commit
Issue: SPR-9611 | spring-orm/src/main/java/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.java | @@ -217,7 +217,7 @@ protected void doFilterInternal(
closeSession(sessionHolder.getSession(), sessionFactory);
}
else {
- if (!chain.pop()) {
+ if (chain.isAsyncStarted()) {
throw new IllegalStateException("Deferred close is not supported with async requests.");
}
// deferred close mode | false |
Other | spring-projects | spring-framework | 33a3681975751692ef2937f058fb5eed4fb343e3.json | Fix DeferredResult typo in changelog | src/dist/changelog.txt | @@ -22,7 +22,7 @@ Changes in version 3.2 M2 (2012-08-xx)
* add @ExceptionResolver annotation to detect classes with @ExceptionHandler methods
* move RSS/Atom message converter registration ahead of jackson/jaxb2
* handle BindException in DefaultHandlerExceptionResolver
-* parameterize DefaultResult type
+* parameterize DeferredResult type
* use reflection to instantiate StandardServletAsyncWebRequest
| false |
Other | spring-projects | spring-framework | 55bd99fa161624ec7bf69ab51d7a9e3a5f657a64.json | Fix typos in Spring MVC chapter of reference docs | src/reference/docbook/mvc.xml | @@ -3666,7 +3666,7 @@ public class SimpleController {
}</programlisting>
<para>The <classname>@ExceptionHandler</classname> value can be set to
- an array of Exception types. If an exception is thrown matches one of
+ an array of Exception types. If an exception is thrown that matches one of
the types in the list, then the method annotated with the matching
<classname>@ExceptionHandler</classname> will be invoked. If the
annotation value is not set then the exception types listed as method
@@ -3687,7 +3687,7 @@ public class SimpleController {
<note><para>To better understand how <interfacename>@ExceptionHandler</interfacename>
methods work, consider that in Spring MVC there is only one abstraction
- for handling exception and that's the
+ for handling exceptions and that's the
<interfacename>HandlerExceptionResolver</interfacename>. There is a special
implementation of that interface,
the <classname>ExceptionHandlerExceptionResolver</classname>, which detects | false |
Other | spring-projects | spring-framework | 59d80ec19e7e6333a2af64b98f68d3efecc58a97.json | Fix minor issue in MockHttpServletRequest
Previously MockHttpServletRequest#sendRedirect did not set the HTTP status
or the Location header. This does not conform to the HttpServletRequest
interface.
MockHttpServletRequest will now:
- Set the HTTP status to 302 on sendRedirect
- Set the Location header on sendRedirect
- Ensure the Location header and getRedirectedUrl are kept in synch
Issue: SPR-9594 | spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * 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.
@@ -54,6 +54,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
private static final String CONTENT_LENGTH_HEADER = "Content-Length";
+ private static final String LOCATION_HEADER = "Location";
+
//---------------------------------------------------------------------
// ServletResponse properties
//---------------------------------------------------------------------
@@ -95,8 +97,6 @@ public class MockHttpServletResponse implements HttpServletResponse {
private String errorMessage;
- private String redirectedUrl;
-
private String forwardedUrl;
private final List<String> includedUrls = new ArrayList<String>();
@@ -306,7 +306,7 @@ public Set<String> getHeaderNames() {
/**
* Return the primary value for the given header as a String, if any.
* Will return the first value in case of multiple values.
- * <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
+ * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
* As of Spring 3.1, it returns a stringified value for Servlet 3.0 compatibility.
* Consider using {@link #getHeaderValue(String)} for raw Object access.
* @param name the name of the header
@@ -319,7 +319,7 @@ public String getHeader(String name) {
/**
* Return all values for the given header as a List of Strings.
- * <p>As of Servlet 3.0, this method is also defined HttpServletResponse.
+ * <p>As of Servlet 3.0, this method is also defined in HttpServletResponse.
* As of Spring 3.1, it returns a List of stringified values for Servlet 3.0 compatibility.
* Consider using {@link #getHeaderValues(String)} for raw Object access.
* @param name the name of the header
@@ -374,7 +374,7 @@ public String encodeURL(String url) {
* returning the given URL String as-is.
* <p>Can be overridden in subclasses, appending a session id or the like
* in a redirect-specific fashion. For general URL encoding rules,
- * override the common {@link #encodeURL} method instead, appyling
+ * override the common {@link #encodeURL} method instead, applying
* to redirect URLs as well as to general URLs.
*/
public String encodeRedirectURL(String url) {
@@ -411,12 +411,13 @@ public void sendRedirect(String url) throws IOException {
throw new IllegalStateException("Cannot send redirect - response is already committed");
}
Assert.notNull(url, "Redirect URL must not be null");
- this.redirectedUrl = url;
+ setHeader(LOCATION_HEADER, url);
+ setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
setCommitted(true);
}
public String getRedirectedUrl() {
- return this.redirectedUrl;
+ return getHeader(LOCATION_HEADER);
}
public void setDateHeader(String name, long value) { | true |
Other | spring-projects | spring-framework | 59d80ec19e7e6333a2af64b98f68d3efecc58a97.json | Fix minor issue in MockHttpServletRequest
Previously MockHttpServletRequest#sendRedirect did not set the HTTP status
or the Location header. This does not conform to the HttpServletRequest
interface.
MockHttpServletRequest will now:
- Set the HTTP status to 302 on sendRedirect
- Set the Location header on sendRedirect
- Ensure the Location header and getRedirectedUrl are kept in synch
Issue: SPR-9594 | spring-test/src/test/java/org/springframework/mock/web/MockHttpServletResponseTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * 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.
@@ -16,43 +16,54 @@
package org.springframework.mock.web;
+import static org.junit.Assert.*;
+
import java.io.IOException;
import java.util.Arrays;
import java.util.Set;
-import junit.framework.TestCase;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Test;
import org.springframework.web.util.WebUtils;
/**
+ * Unit tests for {@link MockHttpServletResponse}.
+ *
* @author Juergen Hoeller
* @author Rick Evans
* @author Rossen Stoyanchev
+ * @author Rob Winch
+ * @author Sam Brannen
* @since 19.02.2006
*/
-public class MockHttpServletResponseTests extends TestCase {
+public class MockHttpServletResponseTests {
+
+ private MockHttpServletResponse response = new MockHttpServletResponse();
- public void testSetContentType() {
+
+ @Test
+ public void setContentType() {
String contentType = "test/plain";
- MockHttpServletResponse response = new MockHttpServletResponse();
response.setContentType(contentType);
assertEquals(contentType, response.getContentType());
assertEquals(contentType, response.getHeader("Content-Type"));
assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
}
- public void testSetContentTypeUTF8() {
+ @Test
+ public void setContentTypeUTF8() {
String contentType = "test/plain;charset=UTF-8";
- MockHttpServletResponse response = new MockHttpServletResponse();
response.setContentType(contentType);
assertEquals("UTF-8", response.getCharacterEncoding());
assertEquals(contentType, response.getContentType());
assertEquals(contentType, response.getHeader("Content-Type"));
}
-
- public void testContentTypeHeader() {
+
+ @Test
+ public void contentTypeHeader() {
String contentType = "test/plain";
- MockHttpServletResponse response = new MockHttpServletResponse();
response.addHeader("Content-Type", contentType);
assertEquals(contentType, response.getContentType());
assertEquals(contentType, response.getHeader("Content-Type"));
@@ -65,9 +76,9 @@ public void testContentTypeHeader() {
assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
}
- public void testContentTypeHeaderUTF8() {
+ @Test
+ public void contentTypeHeaderUTF8() {
String contentType = "test/plain;charset=UTF-8";
- MockHttpServletResponse response = new MockHttpServletResponse();
response.setHeader("Content-Type", contentType);
assertEquals(contentType, response.getContentType());
assertEquals(contentType, response.getHeader("Content-Type"));
@@ -80,51 +91,50 @@ public void testContentTypeHeaderUTF8() {
assertEquals("UTF-8", response.getCharacterEncoding());
}
- public void testSetContentTypeThenCharacterEncoding() {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void setContentTypeThenCharacterEncoding() {
response.setContentType("test/plain");
response.setCharacterEncoding("UTF-8");
assertEquals("test/plain", response.getContentType());
assertEquals("test/plain;charset=UTF-8", response.getHeader("Content-Type"));
assertEquals("UTF-8", response.getCharacterEncoding());
}
- public void testSetCharacterEncodingThenContentType() {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void setCharacterEncodingThenContentType() {
response.setCharacterEncoding("UTF-8");
response.setContentType("test/plain");
assertEquals("test/plain", response.getContentType());
assertEquals("test/plain;charset=UTF-8", response.getHeader("Content-Type"));
assertEquals("UTF-8", response.getCharacterEncoding());
}
- public void testContentLength() {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void contentLength() {
response.setContentLength(66);
assertEquals(66, response.getContentLength());
assertEquals("66", response.getHeader("Content-Length"));
}
-
- public void testContentLengthHeader() {
- MockHttpServletResponse response = new MockHttpServletResponse();
+
+ @Test
+ public void contentLengthHeader() {
response.addHeader("Content-Length", "66");
- assertEquals(66,response.getContentLength());
+ assertEquals(66, response.getContentLength());
assertEquals("66", response.getHeader("Content-Length"));
}
-
- public void testHttpHeaderNameCasingIsPreserved() throws Exception {
- final String headerName = "Header1";
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void httpHeaderNameCasingIsPreserved() throws Exception {
+ final String headerName = "Header1";
response.addHeader(headerName, "value1");
Set<String> responseHeaders = response.getHeaderNames();
assertNotNull(responseHeaders);
assertEquals(1, responseHeaders.size());
assertEquals("HTTP header casing not being preserved", headerName, responseHeaders.iterator().next());
}
- public void testServletOutputStreamCommittedWhenBufferSizeExceeded() throws IOException {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void servletOutputStreamCommittedWhenBufferSizeExceeded() throws IOException {
assertFalse(response.isCommitted());
response.getOutputStream().write('X');
assertFalse(response.isCommitted());
@@ -134,8 +144,8 @@ public void testServletOutputStreamCommittedWhenBufferSizeExceeded() throws IOEx
assertEquals(size + 1, response.getContentAsByteArray().length);
}
- public void testServletOutputStreamCommittedOnFlushBuffer() throws IOException {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void servletOutputStreamCommittedOnFlushBuffer() throws IOException {
assertFalse(response.isCommitted());
response.getOutputStream().write('X');
assertFalse(response.isCommitted());
@@ -144,8 +154,8 @@ public void testServletOutputStreamCommittedOnFlushBuffer() throws IOException {
assertEquals(1, response.getContentAsByteArray().length);
}
- public void testServletWriterCommittedWhenBufferSizeExceeded() throws IOException {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void servletWriterCommittedWhenBufferSizeExceeded() throws IOException {
assertFalse(response.isCommitted());
response.getWriter().write("X");
assertFalse(response.isCommitted());
@@ -157,8 +167,8 @@ public void testServletWriterCommittedWhenBufferSizeExceeded() throws IOExceptio
assertEquals(size + 1, response.getContentAsByteArray().length);
}
- public void testServletOutputStreamCommittedOnOutputStreamFlush() throws IOException {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void servletOutputStreamCommittedOnOutputStreamFlush() throws IOException {
assertFalse(response.isCommitted());
response.getOutputStream().write('X');
assertFalse(response.isCommitted());
@@ -167,8 +177,8 @@ public void testServletOutputStreamCommittedOnOutputStreamFlush() throws IOExcep
assertEquals(1, response.getContentAsByteArray().length);
}
- public void testServletWriterCommittedOnWriterFlush() throws IOException {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void servletWriterCommittedOnWriterFlush() throws IOException {
assertFalse(response.isCommitted());
response.getWriter().write("X");
assertFalse(response.isCommitted());
@@ -177,22 +187,39 @@ public void testServletWriterCommittedOnWriterFlush() throws IOException {
assertEquals(1, response.getContentAsByteArray().length);
}
- public void testServletWriterAutoFlushedForString() throws IOException {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void servletWriterAutoFlushedForString() throws IOException {
response.getWriter().write("X");
assertEquals("X", response.getContentAsString());
}
- public void testServletWriterAutoFlushedForChar() throws IOException {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void servletWriterAutoFlushedForChar() throws IOException {
response.getWriter().write('X');
assertEquals("X", response.getContentAsString());
}
- public void testServletWriterAutoFlushedForCharArray() throws IOException {
- MockHttpServletResponse response = new MockHttpServletResponse();
+ @Test
+ public void servletWriterAutoFlushedForCharArray() throws IOException {
response.getWriter().write("XY".toCharArray());
assertEquals("XY", response.getContentAsString());
}
+ @Test
+ public void sendRedirect() throws IOException {
+ String redirectUrl = "/redirect";
+ response.sendRedirect(redirectUrl);
+ assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
+ assertEquals(redirectUrl, response.getHeader("Location"));
+ assertEquals(redirectUrl, response.getRedirectedUrl());
+ assertTrue(response.isCommitted());
+ }
+
+ @Test
+ public void locationHeaderUpdatesGetRedirectedUrl() {
+ String redirectUrl = "/redirect";
+ response.setHeader("Location", redirectUrl);
+ assertEquals(redirectUrl, response.getRedirectedUrl());
+ }
+
} | true |
Other | spring-projects | spring-framework | cf147a82ef0c5592041ddfdde3d1340fd47e89aa.json | Fix issue with incorrect class import
Issue: SPR-9112 | spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java | @@ -18,6 +18,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -58,8 +59,6 @@
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver;
-import edu.emory.mathcs.backport.java.util.Collections;
-
/**
* An {@link AbstractHandlerMethodExceptionResolver} that resolves exceptions
* through {@code @ExceptionHandler} methods. | false |
Other | spring-projects | spring-framework | c846198e4697f2ac5d79f0f4f62d25fa7d62fa26.json | Add support for global @ExceptionHandler methods
Before this change @ExceptionHandler methods could be located in and
apply locally within a controller. The change makes it possible to have
such methods applicable globally regardless of the controller that
raised the exception.
The easiest way to do that is to add them to a class annotated with
`@ExceptionResolver`, a new annotation that is also an `@Component`
annotation (and therefore works with component scanning). It is also
possible to register classes containing `@ExceptionHandler` methods
directly with the ExceptionHandlerExceptionResolver.
When multiple `@ExceptionResolver` classes are detected, or registered
directly, the order in which they're used depends on the the `@Order`
annotation (if present) or on the value of the order field (if the
Ordered interface is implemented).
Issue: SPR-9112 | spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java | @@ -76,6 +76,15 @@
* {@link org.springframework.web.servlet.RequestToViewNameTranslator}.
* <li>A {@link org.springframework.web.servlet.View} object.
* <li>A {@link java.lang.String} value which is interpreted as view name.
+ * <li>{@link ResponseBody @ResponseBody} annotated methods (Servlet-only)
+ * to set the response content. The return value will be converted to the
+ * response stream using
+ * {@linkplain org.springframework.http.converter.HttpMessageConverter message converters}.
+ * <li>An {@link org.springframework.http.HttpEntity HttpEntity<?>} or
+ * {@link org.springframework.http.ResponseEntity ResponseEntity<?>} object
+ * (Servlet-only) to set response headers and content. The ResponseEntity body
+ * will be converted and written to the response stream using
+ * {@linkplain org.springframework.http.converter.HttpMessageConverter message converters}.
* <li><code>void</code> if the method handles the response itself (by
* writing the response content directly, declaring an argument of type
* {@link javax.servlet.ServletResponse} / {@link javax.servlet.http.HttpServletResponse} | true |
Other | spring-projects | spring-framework | c846198e4697f2ac5d79f0f4f62d25fa7d62fa26.json | Add support for global @ExceptionHandler methods
Before this change @ExceptionHandler methods could be located in and
apply locally within a controller. The change makes it possible to have
such methods applicable globally regardless of the controller that
raised the exception.
The easiest way to do that is to add them to a class annotated with
`@ExceptionResolver`, a new annotation that is also an `@Component`
annotation (and therefore works with component scanning). It is also
possible to register classes containing `@ExceptionHandler` methods
directly with the ExceptionHandlerExceptionResolver.
When multiple `@ExceptionResolver` classes are detected, or registered
directly, the order in which they're used depends on the the `@Order`
annotation (if present) or on the value of the order field (if the
Ordered interface is implemented).
Issue: SPR-9112 | spring-web/src/main/java/org/springframework/web/bind/annotation/ExceptionResolver.java | @@ -0,0 +1,57 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.web.bind.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+/**
+ * An {@linkplain Component @Component} annotation that indicates the annotated class
+ * contains {@linkplain ExceptionHandler @ExceptionHandler} methods. Such methods
+ * will be used in addition to {@code @ExceptionHandler} methods in
+ * {@code @Controller}-annotated classes.
+ *
+ * <p>In order for the the annotation to detected, an instance of
+ * {@code org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver}
+ * is configured.
+ *
+ * <p>Classes with this annotation may use the {@linkplain Order @Order} annotation
+ * or implement the {@link Ordered} interface to indicate the order in which they
+ * should be used relative to other such annotated components. However, note that
+ * the order is only for components registered through {@code @ExceptionResolver},
+ * i.e. within an
+ * {@code org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver}.
+ *
+ * @author Rossen Stoyanchev
+ * @since 3.2
+ *
+ * @see org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Component
+public @interface ExceptionResolver {
+
+}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | c846198e4697f2ac5d79f0f4f62d25fa7d62fa26.json | Add support for global @ExceptionHandler methods
Before this change @ExceptionHandler methods could be located in and
apply locally within a controller. The change makes it possible to have
such methods applicable globally regardless of the controller that
raised the exception.
The easiest way to do that is to add them to a class annotated with
`@ExceptionResolver`, a new annotation that is also an `@Component`
annotation (and therefore works with component scanning). It is also
possible to register classes containing `@ExceptionHandler` methods
directly with the ExceptionHandlerExceptionResolver.
When multiple `@ExceptionResolver` classes are detected, or registered
directly, the order in which they're used depends on the the `@Order`
annotation (if present) or on the value of the order field (if the
Ordered interface is implemented).
Issue: SPR-9112 | spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java | @@ -18,22 +18,31 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Source;
+import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.core.annotation.AnnotationAwareOrderComparator;
+import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ExceptionResolver;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.annotation.ExceptionHandlerMethodResolver;
@@ -49,6 +58,8 @@
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver;
+import edu.emory.mathcs.backport.java.util.Collections;
+
/**
* An {@link AbstractHandlerMethodExceptionResolver} that resolves exceptions
* through {@code @ExceptionHandler} methods.
@@ -62,7 +73,7 @@
* @since 3.1
*/
public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExceptionResolver implements
- InitializingBean {
+ InitializingBean, ApplicationContextAware {
private List<HandlerMethodArgumentResolver> customArgumentResolvers;
@@ -72,13 +83,18 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager();
- private final Map<Class<?>, ExceptionHandlerMethodResolver> exceptionHandlerMethodResolvers =
- new ConcurrentHashMap<Class<?>, ExceptionHandlerMethodResolver>();
+ private final Map<Class<?>, ExceptionHandlerMethodResolver> exceptionHandlersByType =
+ new ConcurrentHashMap<Class<?>, ExceptionHandlerMethodResolver>();
+
+ private final Map<Object, ExceptionHandlerMethodResolver> globalExceptionHandlers =
+ new LinkedHashMap<Object, ExceptionHandlerMethodResolver>();
private HandlerMethodArgumentResolverComposite argumentResolvers;
private HandlerMethodReturnValueHandlerComposite returnValueHandlers;
+ private ApplicationContext applicationContext;
+
/**
* Default constructor.
*/
@@ -193,6 +209,22 @@ public void setContentNegotiationManager(ContentNegotiationManager contentNegoti
this.contentNegotiationManager = contentNegotiationManager;
}
+ /**
+ * Provide instances of objects with {@link ExceptionHandler @ExceptionHandler}
+ * methods to apply globally, i.e. regardless of the selected controller.
+ * <p>{@code @ExceptionHandler} methods in the controller are always looked
+ * up before {@code @ExceptionHandler} methods in global handlers.
+ */
+ public void setGlobalExceptionHandlers(Object... handlers) {
+ for (Object handler : handlers) {
+ this.globalExceptionHandlers.put(handler, new ExceptionHandlerMethodResolver(handler.getClass()));
+ }
+ }
+
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ this.applicationContext = applicationContext;
+ }
+
public void afterPropertiesSet() {
if (this.argumentResolvers == null) {
List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers();
@@ -202,6 +234,7 @@ public void afterPropertiesSet() {
List<HandlerMethodReturnValueHandler> handlers = getDefaultReturnValueHandlers();
this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite().addHandlers(handlers);
}
+ initGlobalExceptionHandlers();
}
/**
@@ -255,6 +288,36 @@ protected List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers()
return handlers;
}
+ private void initGlobalExceptionHandlers() {
+ if (this.applicationContext == null) {
+ logger.warn("Can't detect @ExceptionResolver components if the ApplicationContext property is not set");
+ }
+ else {
+ String[] beanNames = this.applicationContext.getBeanNamesForType(Object.class);
+ for (String name : beanNames) {
+ Class<?> type = this.applicationContext.getType(name);
+ if (AnnotationUtils.findAnnotation(type , ExceptionResolver.class) != null) {
+ Object bean = this.applicationContext.getBean(name);
+ this.globalExceptionHandlers.put(bean, new ExceptionHandlerMethodResolver(bean.getClass()));
+ }
+ }
+ }
+ if (this.globalExceptionHandlers.size() > 0) {
+ sortGlobalExceptionHandlers();
+ }
+ }
+
+ private void sortGlobalExceptionHandlers() {
+ Map<Object, ExceptionHandlerMethodResolver> handlersCopy =
+ new HashMap<Object, ExceptionHandlerMethodResolver>(this.globalExceptionHandlers);
+ List<Object> handlers = new ArrayList<Object>(handlersCopy.keySet());
+ Collections.sort(handlers, new AnnotationAwareOrderComparator());
+ this.globalExceptionHandlers.clear();
+ for (Object handler : handlers) {
+ this.globalExceptionHandlers.put(handler, handlersCopy.get(handler));
+ }
+ }
+
/**
* Find an @{@link ExceptionHandler} method and invoke it to handle the
* raised exception.
@@ -307,24 +370,32 @@ protected ModelAndView doResolveHandlerMethodException(HttpServletRequest reques
* @return a method to handle the exception, or {@code null}
*/
protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
- if (handlerMethod == null) {
- return null;
+ if (handlerMethod != null) {
+ Class<?> handlerType = handlerMethod.getBeanType();
+ ExceptionHandlerMethodResolver resolver = this.exceptionHandlersByType.get(handlerType);
+ if (resolver == null) {
+ resolver = new ExceptionHandlerMethodResolver(handlerType);
+ this.exceptionHandlersByType.put(handlerType, resolver);
+ }
+ Method method = resolver.resolveMethod(exception);
+ if (method != null) {
+ return new ServletInvocableHandlerMethod(handlerMethod.getBean(), method);
+ }
}
- Class<?> handlerType = handlerMethod.getBeanType();
- Method method = getExceptionHandlerMethodResolver(handlerType).resolveMethod(exception);
- return (method != null ? new ServletInvocableHandlerMethod(handlerMethod.getBean(), method) : null);
+ return getGlobalExceptionHandlerMethod(exception);
}
/**
- * Return a method resolver for the given handler type, never {@code null}.
+ * Return a global {@code @ExceptionHandler} method for the given exception or {@code null}.
*/
- private ExceptionHandlerMethodResolver getExceptionHandlerMethodResolver(Class<?> handlerType) {
- ExceptionHandlerMethodResolver resolver = this.exceptionHandlerMethodResolvers.get(handlerType);
- if (resolver == null) {
- resolver = new ExceptionHandlerMethodResolver(handlerType);
- this.exceptionHandlerMethodResolvers.put(handlerType, resolver);
+ private ServletInvocableHandlerMethod getGlobalExceptionHandlerMethod(Exception exception) {
+ for (Entry<Object, ExceptionHandlerMethodResolver> entry : this.globalExceptionHandlers.entrySet()) {
+ Method method = entry.getValue().resolveMethod(exception);
+ if (method != null) {
+ return new ServletInvocableHandlerMethod(entry.getKey(), method);
+ }
}
- return resolver;
+ return null;
}
} | true |
Other | spring-projects | spring-framework | c846198e4697f2ac5d79f0f4f62d25fa7d62fa26.json | Add support for global @ExceptionHandler methods
Before this change @ExceptionHandler methods could be located in and
apply locally within a controller. The change makes it possible to have
such methods applicable globally regardless of the controller that
raised the exception.
The easiest way to do that is to add them to a class annotated with
`@ExceptionResolver`, a new annotation that is also an `@Component`
annotation (and therefore works with component scanning). It is also
possible to register classes containing `@ExceptionHandler` methods
directly with the ExceptionHandlerExceptionResolver.
When multiple `@ExceptionResolver` classes are detected, or registered
directly, the order in which they're used depends on the the `@Order`
annotation (if present) or on the value of the order field (if the
Ordered interface is implemented).
Issue: SPR-9112 | spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolverTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * 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.
@@ -30,11 +30,17 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ExceptionResolver;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.annotation.ModelMethodProcessor;
@@ -44,15 +50,15 @@
/**
* Test fixture with {@link ExceptionHandlerExceptionResolver}.
- *
+ *
* @author Rossen Stoyanchev
* @author Arjen Poutsma
* @since 3.1
*/
public class ExceptionHandlerExceptionResolverTests {
private static int RESOLVER_COUNT;
-
+
private static int HANDLER_COUNT;
private ExceptionHandlerExceptionResolver resolver;
@@ -63,12 +69,12 @@ public class ExceptionHandlerExceptionResolverTests {
@BeforeClass
public static void setupOnce() {
- ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();
- resolver.afterPropertiesSet();
- RESOLVER_COUNT = resolver.getArgumentResolvers().getResolvers().size();
- HANDLER_COUNT = resolver.getReturnValueHandlers().getHandlers().size();
+ ExceptionHandlerExceptionResolver r = new ExceptionHandlerExceptionResolver();
+ r.afterPropertiesSet();
+ RESOLVER_COUNT = r.getArgumentResolvers().getResolvers().size();
+ HANDLER_COUNT = r.getReturnValueHandlers().getHandlers().size();
}
-
+
@Before
public void setUp() throws Exception {
this.resolver = new ExceptionHandlerExceptionResolver();
@@ -89,7 +95,7 @@ public void setCustomArgumentResolvers() throws Exception {
HandlerMethodArgumentResolver resolver = new ServletRequestMethodArgumentResolver();
this.resolver.setCustomArgumentResolvers(Arrays.asList(resolver));
this.resolver.afterPropertiesSet();
-
+
assertTrue(this.resolver.getArgumentResolvers().getResolvers().contains(resolver));
assertMethodProcessorCount(RESOLVER_COUNT + 1, HANDLER_COUNT);
}
@@ -112,7 +118,7 @@ public void setCustomReturnValueHandlers() {
assertTrue(this.resolver.getReturnValueHandlers().getHandlers().contains(handler));
assertMethodProcessorCount(RESOLVER_COUNT, HANDLER_COUNT + 1);
}
-
+
@Test
public void setReturnValueHandlers() {
HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
@@ -151,7 +157,7 @@ public void resolveExceptionResponseBody() throws UnsupportedEncodingException,
HandlerMethod handlerMethod = new HandlerMethod(new ResponseBodyController(), "handle");
this.resolver.afterPropertiesSet();
ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, ex);
-
+
assertNotNull(mav);
assertTrue(mav.isEmpty());
assertEquals("IllegalArgumentException", this.response.getContentAsString());
@@ -169,7 +175,41 @@ public void resolveExceptionResponseWriter() throws UnsupportedEncodingException
assertEquals("IllegalArgumentException", this.response.getContentAsString());
}
-
+ @Test
+ public void resolveExceptionGlobalHandler() throws UnsupportedEncodingException, NoSuchMethodException {
+ AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyConfig.class);
+ this.resolver.setApplicationContext(cxt);
+ this.resolver.setGlobalExceptionHandlers(new GlobalExceptionHandler());
+ this.resolver.afterPropertiesSet();
+
+ IllegalStateException ex = new IllegalStateException();
+ HandlerMethod handlerMethod = new HandlerMethod(new ResponseBodyController(), "handle");
+ ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, ex);
+
+ assertNotNull("Exception was not handled", mav);
+ assertTrue(mav.isEmpty());
+ assertEquals("IllegalStateException", this.response.getContentAsString());
+ }
+
+ @Test
+ public void resolveExceptionGlobalHandlerOrdered() throws UnsupportedEncodingException, NoSuchMethodException {
+ AnnotationConfigApplicationContext cxt = new AnnotationConfigApplicationContext(MyConfig.class);
+ this.resolver.setApplicationContext(cxt);
+ GlobalExceptionHandler globalHandler = new GlobalExceptionHandler();
+ globalHandler.setOrder(2);
+ this.resolver.setGlobalExceptionHandlers(globalHandler);
+ this.resolver.afterPropertiesSet();
+
+ IllegalStateException ex = new IllegalStateException();
+ HandlerMethod handlerMethod = new HandlerMethod(new ResponseBodyController(), "handle");
+ ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, ex);
+
+ assertNotNull("Exception was not handled", mav);
+ assertTrue(mav.isEmpty());
+ assertEquals("@ExceptionResolver: IllegalStateException", this.response.getContentAsString());
+ }
+
+
private void assertMethodProcessorCount(int resolverCount, int handlerCount) {
assertEquals(resolverCount, this.resolver.getArgumentResolvers().getResolvers().size());
assertEquals(handlerCount, this.resolver.getReturnValueHandlers().getHandlers().size());
@@ -185,7 +225,7 @@ public ModelAndView handle(Exception ex) throws IOException {
return new ModelAndView("errorView", "detail", ex.getMessage());
}
}
-
+
@Controller
static class ResponseWriterController {
@@ -204,7 +244,7 @@ public void handle() {}
@ExceptionHandler
@ResponseBody
- public String handleException(Exception ex) {
+ public String handleException(IllegalArgumentException ex) {
return ClassUtils.getShortName(ex.getClass());
}
}
@@ -219,4 +259,42 @@ public void handleException() {
}
}
+ static class GlobalExceptionHandler implements Ordered {
+
+ private int order;
+
+ public int getOrder() {
+ return order;
+ }
+
+ public void setOrder(int order) {
+ this.order = order;
+ }
+
+ @ExceptionHandler
+ @ResponseBody
+ public String handleException(IllegalStateException ex) {
+ return ClassUtils.getShortName(ex.getClass());
+ }
+ }
+
+ @ExceptionResolver
+ @Order(1)
+ static class AnnotatedExceptionResolver {
+
+ @ExceptionHandler
+ @ResponseBody
+ public String handleException(IllegalStateException ex) {
+ return "@ExceptionResolver: " + ClassUtils.getShortName(ex.getClass());
+ }
+ }
+
+ @Configuration
+ static class MyConfig {
+
+ @Bean public AnnotatedExceptionResolver exceptionResolver() {
+ return new AnnotatedExceptionResolver();
+ }
+ }
+
}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | c846198e4697f2ac5d79f0f4f62d25fa7d62fa26.json | Add support for global @ExceptionHandler methods
Before this change @ExceptionHandler methods could be located in and
apply locally within a controller. The change makes it possible to have
such methods applicable globally regardless of the controller that
raised the exception.
The easiest way to do that is to add them to a class annotated with
`@ExceptionResolver`, a new annotation that is also an `@Component`
annotation (and therefore works with component scanning). It is also
possible to register classes containing `@ExceptionHandler` methods
directly with the ExceptionHandlerExceptionResolver.
When multiple `@ExceptionResolver` classes are detected, or registered
directly, the order in which they're used depends on the the `@Order`
annotation (if present) or on the value of the order field (if the
Ordered interface is implemented).
Issue: SPR-9112 | src/dist/changelog.txt | @@ -18,6 +18,8 @@ Changes in version 3.2 M2 (2012-08-xx)
* added support for the HTTP PATCH method to Spring MVC and to RestTemplate (SPR-7985)
* enable smart suffix pattern match in @RequestMapping methods (SPR-7632)
* DispatcherPortlet does not forward event exceptions to the render phase by default (SPR-9287)
+* add defaultCharset property to StringHttpMessageConverter
+* add @ExceptionResolver annotation to detect classes with @ExceptionHandler methods
Changes in version 3.2 M1 (2012-05-28) | true |
Other | spring-projects | spring-framework | c846198e4697f2ac5d79f0f4f62d25fa7d62fa26.json | Add support for global @ExceptionHandler methods
Before this change @ExceptionHandler methods could be located in and
apply locally within a controller. The change makes it possible to have
such methods applicable globally regardless of the controller that
raised the exception.
The easiest way to do that is to add them to a class annotated with
`@ExceptionResolver`, a new annotation that is also an `@Component`
annotation (and therefore works with component scanning). It is also
possible to register classes containing `@ExceptionHandler` methods
directly with the ExceptionHandlerExceptionResolver.
When multiple `@ExceptionResolver` classes are detected, or registered
directly, the order in which they're used depends on the the `@Order`
annotation (if present) or on the value of the order field (if the
Ordered interface is implemented).
Issue: SPR-9112 | src/reference/docbook/mvc.xml | @@ -3620,18 +3620,91 @@ public String onSubmit(<emphasis role="bold">@RequestPart("meta-data") MetaData
<interfacename>HandlerExceptionResolver</interfacename> interface, which
is only a matter of implementing the
<literal>resolveException(Exception, Handler)</literal> method and
- returning a <classname>ModelAndView</classname>, you may also use the
+ returning a <classname>ModelAndView</classname>, you may also use the provided
<classname>SimpleMappingExceptionResolver</classname>. This resolver
enables you to take the class name of any exception that might be thrown
and map it to a view name. This is functionally equivalent to the
exception mapping feature from the Servlet API, but it is also possible
to implement more finely grained mappings of exceptions from different
handlers.</para>
+ </section>
+
+ <section id="mvc-ann-exceptionhandler">
+ <title><interfacename>@ExceptionHandler</interfacename></title>
+
+ <para>The <interfacename>HandlerExceptionResolver</interfacename> interface
+ and the <classname>SimpleMappingExceptionResolver</classname> implementations
+ allow you to map Exceptions to specific views along with some Java logic
+ before forwarding to those views. However, in some cases, especially when
+ working with programmatic clients (Ajax or non-browser) it is more
+ convenient to set the status and optionally write error information to the
+ response body.</para>
+
+ <para>For that you can use <interfacename>@ExceptionHandler</interfacename>
+ methods. When present within a controller such methods apply to exceptions
+ raised by that contoroller or any of its sub-classes.
+ Or you can also declare <interfacename>@ExceptionHandler</interfacename>
+ methods in a type annotated with <interfacename>@ExceptionResolver</interfacename>
+ in which case they apply globally.
+ The <interfacename>@ExceptionResolver</interfacename> annotation is
+ a component annotation that can also be used with a component scan.
+ </para>
+
+ <para>Here is an example with a controller-level
+ <interfacename>@ExceptionHandler</interfacename> method:</para>
+
+ <programlisting language="java">@Controller
+public class SimpleController {
+
+ // other controller method omitted
+
+ @ExceptionHandler(IOException.class)
+ public ResponseEntity handleIOException(IOException ex) {
+ // prepare responseEntity
+ return responseEntity;
+ }
+}</programlisting>
+
+ <para>The <classname>@ExceptionHandler</classname> value can be set to
+ an array of Exception types. If an exception is thrown matches one of
+ the types in the list, then the method annotated with the matching
+ <classname>@ExceptionHandler</classname> will be invoked. If the
+ annotation value is not set then the exception types listed as method
+ arguments are used.</para>
+
+ <para>Much like standard controller methods annotated with a
+ <interfacename>@RequestMapping</interfacename> annotation, the method arguments
+ and return values of <interfacename>@ExceptionHandler</interfacename> methods
+ can be flexible. For example, the
+ <classname>HttpServletRequest</classname> can be accessed in Servlet
+ environments and the <classname>PortletRequest</classname> in Portlet
+ environments. The return type can be a <classname>String</classname>,
+ which is interpreted as a view name, a
+ <classname>ModelAndView</classname> object, a
+ <classname>ResponseEntity</classname>, or you can also add the
+ <interfacename>@ResponseBody</interfacename> to have the method return value
+ converted with message converters and written to the response stream.</para>
+
+ <note><para>To better understand how <interfacename>@ExceptionHandler</interfacename>
+ methods work, consider that in Spring MVC there is only one abstraction
+ for handling exception and that's the
+ <interfacename>HandlerExceptionResolver</interfacename>. There is a special
+ implementation of that interface,
+ the <classname>ExceptionHandlerExceptionResolver</classname>, which detects
+ and invokes <interfacename>@ExceptionHandler</interfacename> methods.</para></note>
+ </section>
+
+ <section id="mvc-ann-rest-handler-exception-resolvers">
+ <title><classname>DefaultHandlerExceptionResolver</classname>
+ and <classname>ResponseStatusExceptionResolver</classname></title>
<para>By default, the <classname>DispatcherServlet</classname> registers
the <classname>DefaultHandlerExceptionResolver</classname>. This
resolver handles certain standard Spring MVC exceptions by setting a
- specific response status code: <informaltable>
+ specific response status code. This is useful when responding to programmatic
+ clients (e.g. Ajax, non-browser) in which the client uses the response code
+ to interpret the result.
+ <informaltable>
<tgroup cols="2">
<thead>
<row>
@@ -3697,51 +3770,21 @@ public String onSubmit(<emphasis role="bold">@RequestPart("meta-data") MetaData
</row>
</tbody>
</tgroup>
- </informaltable></para>
- </section>
-
- <section id="mvc-ann-exceptionhandler">
- <title><interfacename>@ExceptionHandler</interfacename></title>
-
- <para>An alternative to the
- <interfacename>HandlerExceptionResolver</interfacename> interface is the
- <interfacename>@ExceptionHandler</interfacename> annotation. You use the
- <classname>@ExceptionHandler</classname> method annotation within a
- controller to specify which method is invoked when an exception of a
- specific type is thrown during the execution of controller methods. For
- example:</para>
-
- <programlisting language="java">@Controller
-public class SimpleController {
-
- // other controller method omitted
-
- @ExceptionHandler(IOException.class)
- public String handleIOException(IOException ex, HttpServletRequest request) {
- return ClassUtils.getShortName(ex.getClass());
- }
-}</programlisting>
-
- <para>will invoke the 'handlerIOException' method when a
- <classname>java.io.IOException</classname> is thrown.</para>
-
- <para>The <classname>@ExceptionHandler</classname> value can be set to
- an array of Exception types. If an exception is thrown matches one of
- the types in the list, then the method annotated with the matching
- <classname>@ExceptionHandler</classname> will be invoked. If the
- annotation value is not set then the exception types listed as method
- arguments are used.</para>
+ </informaltable>
+ </para>
- <para>Much like standard controller methods annotated with a
- <classname>@RequestMapping</classname> annotation, the method arguments
- and return values of <classname>@ExceptionHandler</classname> methods
- are very flexible. For example, the
- <classname>HttpServletRequest</classname> can be accessed in Servlet
- environments and the <classname>PortletRequest</classname> in Portlet
- environments. The return type can be a <classname>String</classname>,
- which is interpreted as a view name or a
- <classname>ModelAndView</classname> object. Refer to the API
- documentation for more details.</para>
+ <para>The <classname>DispatcherServlet</classname> also registers the
+ <classname>ResponseStatusExceptionResolver</classname>, which handles
+ exceptions annotated with <interfacename>@ResponseStatus</interfacename>
+ by setting the response status code to that indicated in the annotation.
+ Once again this is useful in scenarios with programmatic clients.</para>
+
+ <para>Note however that if you explicitly register one or more
+ <interfacename>HandlerExceptionResolver</interfacename> instances in your configuration
+ then the defaults registered by the <classname>DispatcherServlet</classname> are
+ cancelled. This is standard behavior with regards to
+ <classname>DispatcherServlet</classname> defaults.
+ See <xref linkend="mvc-servlet-special-bean-types"/> for more details.</para>
</section>
</section>
| true |
Other | spring-projects | spring-framework | 2ec7834124dfa32d7b90afbb23805433a4567bf5.json | Resolve nested placeholders via PropertyResolver
Prior to this change, PropertySourcesPropertyResolver (and therefore
all AbstractEnvironment) implementations failed to resolve nested
placeholders as in the following example:
p1=v1
p2=v2
p3=${v1}:{$v2}
Calls to PropertySource#getProperty for keys 'p1' and 'v1' would
successfully return their respective values, but for 'p3' the return
value would be the unresolved placeholders. This behavior is
inconsistent with that of PropertyPlaceholderConfigurer.
PropertySourcesPropertyResolver #getProperty variants now resolve any
nested placeholders recursively, throwing IllegalArgumentException for
any unresolvable placeholders (as is the default behavior for
PropertyPlaceholderConfigurer). See SPR-9569 for an enhancement that
will intoduce an 'ignoreUnresolvablePlaceholders' switch to make this
behavior configurable.
This commit also improves error output in
PropertyPlaceholderHelper#parseStringValue by including the original
string in which an unresolvable placeholder was found.
Issue: SPR-9473, SPR-9569 | spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java | @@ -72,6 +72,9 @@ public <T> T getProperty(String key, Class<T> targetValueType) {
Object value;
if ((value = propertySource.getProperty(key)) != null) {
Class<?> valueType = value.getClass();
+ if (String.class.equals(valueType)) {
+ value = this.resolveRequiredPlaceholders((String) value);
+ }
if (debugEnabled) {
logger.debug(
format("Found key '%s' in [%s] with type [%s] and value '%s'", | true |
Other | spring-projects | spring-framework | 2ec7834124dfa32d7b90afbb23805433a4567bf5.json | Resolve nested placeholders via PropertyResolver
Prior to this change, PropertySourcesPropertyResolver (and therefore
all AbstractEnvironment) implementations failed to resolve nested
placeholders as in the following example:
p1=v1
p2=v2
p3=${v1}:{$v2}
Calls to PropertySource#getProperty for keys 'p1' and 'v1' would
successfully return their respective values, but for 'p3' the return
value would be the unresolved placeholders. This behavior is
inconsistent with that of PropertyPlaceholderConfigurer.
PropertySourcesPropertyResolver #getProperty variants now resolve any
nested placeholders recursively, throwing IllegalArgumentException for
any unresolvable placeholders (as is the default behavior for
PropertyPlaceholderConfigurer). See SPR-9569 for an enhancement that
will intoduce an 'ignoreUnresolvablePlaceholders' switch to make this
behavior configurable.
This commit also improves error output in
PropertyPlaceholderHelper#parseStringValue by including the original
string in which an unresolvable placeholder was found.
Issue: SPR-9473, SPR-9569 | spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java | @@ -171,7 +171,8 @@ else if (this.ignoreUnresolvablePlaceholders) {
startIndex = buf.indexOf(this.placeholderPrefix, endIndex + this.placeholderSuffix.length());
}
else {
- throw new IllegalArgumentException("Could not resolve placeholder '" + placeholder + "'");
+ throw new IllegalArgumentException("Could not resolve placeholder '" +
+ placeholder + "'" + " in string value [" + strVal + "]");
}
visitedPlaceholders.remove(originalPlaceholder); | true |
Other | spring-projects | spring-framework | 2ec7834124dfa32d7b90afbb23805433a4567bf5.json | Resolve nested placeholders via PropertyResolver
Prior to this change, PropertySourcesPropertyResolver (and therefore
all AbstractEnvironment) implementations failed to resolve nested
placeholders as in the following example:
p1=v1
p2=v2
p3=${v1}:{$v2}
Calls to PropertySource#getProperty for keys 'p1' and 'v1' would
successfully return their respective values, but for 'p3' the return
value would be the unresolved placeholders. This behavior is
inconsistent with that of PropertyPlaceholderConfigurer.
PropertySourcesPropertyResolver #getProperty variants now resolve any
nested placeholders recursively, throwing IllegalArgumentException for
any unresolvable placeholders (as is the default behavior for
PropertyPlaceholderConfigurer). See SPR-9569 for an enhancement that
will intoduce an 'ignoreUnresolvablePlaceholders' switch to make this
behavior configurable.
This commit also improves error output in
PropertyPlaceholderHelper#parseStringValue by including the original
string in which an unresolvable placeholder was found.
Issue: SPR-9473, SPR-9569 | spring-core/src/test/java/org/springframework/core/env/PropertySourcesPropertyResolverTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * 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.
@@ -16,22 +16,20 @@
package org.springframework.core.env;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
+
import org.springframework.core.convert.ConversionException;
import org.springframework.mock.env.MockPropertySource;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
/**
* Unit tests for {@link PropertySourcesPropertyResolver}.
*
@@ -352,6 +350,39 @@ public void setRequiredProperties_andValidateRequiredProperties() {
propertyResolver.validateRequiredProperties();
}
+ @Test
+ public void resolveNestedPropertyPlaceholders() {
+ MutablePropertySources ps = new MutablePropertySources();
+ ps.addFirst(new MockPropertySource()
+ .withProperty("p1", "v1")
+ .withProperty("p2", "v2")
+ .withProperty("p3", "${p1}:${p2}") // nested placeholders
+ .withProperty("p4", "${p3}") // deeply nested placeholders
+ .withProperty("p5", "${p1}:${p2}:${bogus}") // unresolvable placeholder
+ .withProperty("p6", "${p1}:${p2}:${bogus:def}") // unresolvable w/ default
+ .withProperty("pL", "${pR}") // cyclic reference left
+ .withProperty("pR", "${pL}") // cyclic reference right
+ );
+ PropertySourcesPropertyResolver pr = new PropertySourcesPropertyResolver(ps);
+ assertThat(pr.getProperty("p1"), equalTo("v1"));
+ assertThat(pr.getProperty("p2"), equalTo("v2"));
+ assertThat(pr.getProperty("p3"), equalTo("v1:v2"));
+ assertThat(pr.getProperty("p4"), equalTo("v1:v2"));
+ try {
+ pr.getProperty("p5");
+ } catch (IllegalArgumentException ex) {
+ assertThat(ex.getMessage(), Matchers.containsString(
+ "Could not resolve placeholder 'bogus' in string value [${p1}:${p2}:${bogus}]"));
+ }
+ assertThat(pr.getProperty("p6"), equalTo("v1:v2:def"));
+ try {
+ pr.getProperty("pL");
+ } catch (StackOverflowError ex) {
+ // no explicit handling for cyclic references for now
+ }
+ }
+
+
static interface SomeType { }
static class SpecificType implements SomeType { }
} | true |
Other | spring-projects | spring-framework | b9786ccacac2cf90e7fa10a9a74a42c603376f4c.json | Fix minor issue in HandlerMethod
Before this change HandlerMethod used ClassUtils.getUserClass(Class<?>)
to get the real user class, and not one generated by CGlib. However it
failed to that under all circumstances. This change fixes that.
Issue: SPR-9490 | spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java | @@ -124,21 +124,18 @@ public Method getMethod() {
* Note that if the bean type is a CGLIB-generated class, the original, user-defined class is returned.
*/
public Class<?> getBeanType() {
- if (bean instanceof String) {
- String beanName = (String) bean;
- return beanFactory.getType(beanName);
- }
- else {
- return ClassUtils.getUserClass(bean.getClass());
- }
+ Class<?> clazz = (this.bean instanceof String)
+ ? this.beanFactory.getType((String) this.bean) : this.bean.getClass();
+
+ return ClassUtils.getUserClass(clazz);
}
/**
* If the bean method is a bridge method, this method returns the bridged (user-defined) method.
* Otherwise it returns the same method as {@link #getMethod()}.
*/
protected Method getBridgedMethod() {
- return bridgedMethod;
+ return this.bridgedMethod;
}
/**
@@ -153,7 +150,7 @@ public MethodParameter[] getMethodParameters() {
}
this.parameters = p;
}
- return parameters;
+ return this.parameters;
}
/**
@@ -197,7 +194,7 @@ public HandlerMethod createWithResolvedBean() {
String beanName = (String) this.bean;
handler = this.beanFactory.getBean(beanName);
}
- return new HandlerMethod(handler, method);
+ return new HandlerMethod(handler, this.method);
}
@Override | false |
Other | spring-projects | spring-framework | 00a86c37222d92b1477f2480b7bdfaebd12c2d1a.json | Detect split packages at build time
Split packages are a well-known anti-pattern for OSGi and a blocker for
Eclipse Virgo (which prevents split packages being accessed via its
Import-Library construct).
Split packages are also unhelpful with a traditional linear classpath
as a split package name does not uniquely identify the Spring framework
JAR from which it came, thus complicating problem diagnosis and
maintenance.
Juergen Hoeller supports this position in the following comment in
SPR-9990:
>FWIW, I generally find split packages a bad practice, even without
>OSGi in the mix. For the Spring Framework codebase, I consider a
>split-package arrangement a design accident that we want to detect
>in any case - and that we're willing to fix if it happened.
>
>I'm actually equally concerned about the source perspective: After
>all, we want a package to be comprehensible from a single glance
>at the project, not requiring the developer to jump into several
>source modules to understand the overall layout of a package.
Split packages have crept into Spring framework twice in recent months
- see SPR-9811 and SPR-9988. Currently, they are only detected once
the Spring framework has been converted to OSGi bundles and these
bundles have been tested with Eclipse Virgo.
This commit adds a build-time check for split packages to the Spring
framework build.
Issue: SPR-9990
Conflicts:
build.gradle | build.gradle | @@ -8,6 +8,11 @@ buildscript {
}
}
+configure(rootProject) {
+ def splitFound = new org.springframework.build.gradle.SplitPackageDetector('.', logger).diagnoseSplitPackages();
+ assert !splitFound // see error log messages for details of split packages
+}
+
configure(allprojects) { project ->
group = "org.springframework"
version = qualifyVersionIfNecessary(version)
@@ -954,6 +959,7 @@ configure(rootProject) {
"set GRADLE_OPTS=$gradleBatOpts %GRADLE_OPTS%\nset DEFAULT_JVM_OPTS=")
}
}
+
}
/* | true |
Other | spring-projects | spring-framework | 00a86c37222d92b1477f2480b7bdfaebd12c2d1a.json | Detect split packages at build time
Split packages are a well-known anti-pattern for OSGi and a blocker for
Eclipse Virgo (which prevents split packages being accessed via its
Import-Library construct).
Split packages are also unhelpful with a traditional linear classpath
as a split package name does not uniquely identify the Spring framework
JAR from which it came, thus complicating problem diagnosis and
maintenance.
Juergen Hoeller supports this position in the following comment in
SPR-9990:
>FWIW, I generally find split packages a bad practice, even without
>OSGi in the mix. For the Spring Framework codebase, I consider a
>split-package arrangement a design accident that we want to detect
>in any case - and that we're willing to fix if it happened.
>
>I'm actually equally concerned about the source perspective: After
>all, we want a package to be comprehensible from a single glance
>at the project, not requiring the developer to jump into several
>source modules to understand the overall layout of a package.
Split packages have crept into Spring framework twice in recent months
- see SPR-9811 and SPR-9988. Currently, they are only detected once
the Spring framework has been converted to OSGi bundles and these
bundles have been tested with Eclipse Virgo.
This commit adds a build-time check for split packages to the Spring
framework build.
Issue: SPR-9990
Conflicts:
build.gradle | buildSrc/src/main/groovy/org/springframework/build/gradle/SplitPackageDetector.groovy | @@ -0,0 +1,85 @@
+/*
+ * Copyright 2013 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.build.gradle
+
+class SplitPackageDetector {
+
+ private static final String HIDDEN_DIRECTORY_PREFIX = "."
+
+ private static final String JAVA_FILE_SUFFIX = ".java"
+
+ private static final String SRC_MAIN_JAVA = "src" + File.separator + "main" + File.separator + "java"
+
+ private final Map<File, Set<String>> pkgMap = [:]
+
+ private final logger
+
+ SplitPackageDetector(baseDir, logger) {
+ this.logger = logger
+ dirList(baseDir).each { File dir ->
+ def packages = getPackagesInDirectory(dir)
+ if (!packages.isEmpty()) {
+ pkgMap.put(dir, packages)
+ }
+ }
+ }
+
+ private File[] dirList(String dir) {
+ dirList(new File(dir))
+ }
+
+ private File[] dirList(File dir) {
+ dir.listFiles({ file -> file.isDirectory() && !file.getName().startsWith(HIDDEN_DIRECTORY_PREFIX) } as FileFilter)
+ }
+
+ private Set<String> getPackagesInDirectory(File dir) {
+ def pkgs = new HashSet<String>()
+ addPackagesInDirectory(pkgs, new File(dir, SRC_MAIN_JAVA), "")
+ return pkgs;
+ }
+
+ boolean diagnoseSplitPackages() {
+ def splitFound = false;
+ def dirs = pkgMap.keySet().toArray()
+ def numDirs = dirs.length
+ for (int i = 0; i < numDirs - 1; i++) {
+ for (int j = i + 1; j < numDirs - 1; j++) {
+ def di = dirs[i]
+ def pi = new HashSet(pkgMap.get(di))
+ def dj = dirs[j]
+ def pj = pkgMap.get(dj)
+ pi.retainAll(pj)
+ if (!pi.isEmpty()) {
+ logger.error("Packages $pi are split between directories '$di' and '$dj'")
+ splitFound = true
+ }
+ }
+ }
+ return splitFound
+ }
+
+ private void addPackagesInDirectory(HashSet<String> packages, File dir, String pkg) {
+ def scanDir = new File(dir, pkg)
+ def File[] javaFiles = scanDir.listFiles({ file -> !file.isDirectory() && file.getName().endsWith(JAVA_FILE_SUFFIX) } as FileFilter)
+ if (javaFiles != null && javaFiles.length != 0) {
+ packages.add(pkg)
+ }
+ dirList(scanDir).each { File subDir ->
+ addPackagesInDirectory(packages, dir, pkg + File.separator + subDir.getName())
+ }
+ }
+}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | cf68cc5f0b2650bb1cd34064d7e43747f79285a4.json | Eliminate AJ @Async warning in test case
Prior to this commit, ClassWithAsyncAnnotation#return5 forced an
unsuppressable warning in Eclipse, making it virtually impossible to
get to a zero-warnings state in the codebase.
The 'solution' here is simply to comment out the method and it's
associated test case. The 'declare warnings' functionality around
@Async is well-understood and has long been stable.
Also, the entire AnnotationAsyncExecutionAspectTests class has been
added to TestGroup#PERFORMANCE (SPR-9984), as opposed to just
asyncMethodGetsRoutedAsynchronously as it was previously, the
rationale being that all tests are actually timing dependent.
Issue: SPR-9431, SPR-9984 | spring-aspects/src/test/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspectTests.java | @@ -49,14 +49,14 @@ public class AnnotationAsyncExecutionAspectTests {
@Before
public void setUp() {
+ Assume.group(TestGroup.PERFORMANCE);
+
executor = new CountingExecutor();
AnnotationAsyncExecutionAspect.aspectOf().setExecutor(executor);
}
@Test
public void asyncMethodGetsRoutedAsynchronously() {
- Assume.group(TestGroup.PERFORMANCE);
-
ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation();
obj.incrementAsync();
executor.waitForCompletion();
@@ -107,6 +107,7 @@ public void methodReturningFutureInAsyncClassGetsRoutedAsynchronouslyAndReturnsA
assertEquals(1, executor.submitCompleteCounter);
}
+ /*
@Test
public void methodReturningNonVoidNonFutureInAsyncClassGetsRoutedSynchronously() {
ClassWithAsyncAnnotation obj = new ClassWithAsyncAnnotation();
@@ -115,6 +116,7 @@ public void methodReturningNonVoidNonFutureInAsyncClassGetsRoutedSynchronously()
assertEquals(0, executor.submitStartCounter);
assertEquals(0, executor.submitCompleteCounter);
}
+ */
@Test
public void qualifiedAsyncMethodsAreRoutedToCorrectExecutor() throws InterruptedException, ExecutionException {
@@ -198,9 +200,11 @@ public void increment() {
// Manually check that there is a warning from the 'declare warning' statement in
// AnnotationAsyncExecutionAspect
+ /*
public int return5() {
return 5;
}
+ */
public Future<Integer> incrementReturningAFuture() {
counter++; | false |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-jdbc/src/test/java/org/springframework/jdbc/support/custom-error-codes.xml | @@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-
-<beans>
-
- <!--
- Whacky error codes for testing
- -->
- <bean id="Oracle" class="org.springframework.jdbc.support.SQLErrorCodes">
- <property name="badSqlGrammarCodes"><value>1,2</value></property>
- <property name="dataIntegrityViolationCodes"><value>1,1400,1722</value></property>
- <property name="customTranslations">
- <list>
- <bean class="org.springframework.jdbc.support.CustomSQLErrorCodesTranslation">
- <property name="errorCodes"><value>999</value></property>
- <property name="exceptionClass">
- <value>org.springframework.jdbc.support.CustomErrorCodeException</value>
- </property>
- </bean>
- </list>
- </property>
- </bean>
-
-</beans> | true |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-jdbc/src/test/java/org/springframework/jdbc/support/test-error-codes.xml | @@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-
-<beans>
-
- <!--
- Whacky error codes for testing
- -->
- <bean id="Oracle" class="org.springframework.jdbc.support.SQLErrorCodes">
- <property name="badSqlGrammarCodes"><value>1,2</value></property>
- <property name="dataIntegrityViolationCodes"><value>1,1400,1722</value></property>
- </bean>
-
-</beans> | true |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-jdbc/src/test/java/org/springframework/jdbc/support/wildcard-error-codes.xml | @@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-
-<beans>
-
- <!--
- Whacky error codes for testing
- -->
- <bean id="Oracle" class="org.springframework.jdbc.support.SQLErrorCodes">
- <property name="badSqlGrammarCodes"><value>1,2,942</value></property>
- <property name="dataIntegrityViolationCodes"><value>1,1400,1722</value></property>
- </bean>
-
- <bean id="DB0" class="org.springframework.jdbc.support.SQLErrorCodes">
- <property name="databaseProductName"><value>*DB0</value></property>
- <property name="badSqlGrammarCodes"><value>-204,1,2</value></property>
- <property name="dataIntegrityViolationCodes"><value>3,4</value></property>
- </bean>
-
- <bean id="DB1" class="org.springframework.jdbc.support.SQLErrorCodes">
- <property name="databaseProductName"><value>DB1*</value></property>
- <property name="badSqlGrammarCodes"><value>-204,1,2</value></property>
- <property name="dataIntegrityViolationCodes"><value>3,4</value></property>
- </bean>
-
- <bean id="DB2" class="org.springframework.jdbc.support.SQLErrorCodes">
- <property name="databaseProductName"><value>*DB2*</value></property>
- <property name="badSqlGrammarCodes"><value>-204,1,2</value></property>
- <property name="dataIntegrityViolationCodes"><value>3,4</value></property>
- </bean>
-
- <bean id="DB3" class="org.springframework.jdbc.support.SQLErrorCodes">
- <property name="databaseProductName"><value>*DB3*</value></property>
- <property name="badSqlGrammarCodes"><value>-204,1,2</value></property>
- <property name="dataIntegrityViolationCodes"><value>3,4</value></property>
- </bean>
-
-</beans> | true |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-orm/src/test/java/org/springframework/orm/hibernate3/filterDefinitions.xml | @@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-
-<beans>
-
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBeanTests$FilterTestLocalSessionFactoryBean">
- <property name="filterDefinitions">
- <list>
- <bean class="org.springframework.orm.hibernate3.FilterDefinitionFactoryBean">
- <property name="filterName" value="filter1"/>
- <property name="parameterTypes">
- <props>
- <prop key="param1">string</prop>
- <prop key="otherParam">long</prop>
- </props>
- </property>
- <property name="defaultFilterCondition" value="someCondition"/>
- </bean>
- <bean id="filter2" class="org.springframework.orm.hibernate3.FilterDefinitionFactoryBean">
- <property name="parameterTypes">
- <props>
- <prop key="myParam">integer</prop>
- </props>
- </property>
- </bean>
- </list>
- </property>
- </bean>
-
-</beans> | true |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-orm/src/test/java/org/springframework/orm/hibernate3/typeDefinitions.xml | @@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-
-<beans>
-
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBeanTests$TypeTestLocalSessionFactoryBean">
- <property name="typeDefinitions">
- <list>
- <bean class="org.springframework.orm.hibernate3.TypeDefinitionBean">
- <property name="typeName" value="type1"/>
- <property name="typeClass" value="mypackage.MyTypeClass"/>
- <property name="parameters">
- <props>
- <prop key="param1">value1</prop>
- <prop key="otherParam">othervalue</prop>
- </props>
- </property>
- </bean>
- <bean id="type2" class="org.springframework.orm.hibernate3.TypeDefinitionBean">
- <property name="typeName" value="type2"/>
- <property name="typeClass" value="mypackage.MyOtherTypeClass"/>
- <property name="parameters">
- <props>
- <prop key="myParam">myvalue</prop>
- </props>
- </property>
- </bean>
- </list>
- </property>
- </bean>
-
-</beans> | true |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-orm/src/test/java/org/springframework/orm/jdo/test.properties | @@ -1 +0,0 @@
-myKey=myValue | true |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-webmvc/src/test/java/org/springframework/web/context/WEB-INF/empty-servlet.xml | @@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-
-<beans>
-
- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
-
- <bean id="servletContextAwareBean" class="org.springframework.web.context.ServletContextAwareBean"/>
-
- <bean id="servletConfigAwareBean" class="org.springframework.web.context.ServletConfigAwareBean"/>
-
-</beans> | true |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-webmvc/src/test/java/org/springframework/web/context/WEB-INF/sessionContext.xml | @@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
-
-<beans>
-
- <bean id="rob" class="org.springframework.tests.sample.beans.TestBean">
- <property name="name" value="dummy"/>
- <property name="age" value="-1"/>
- </bean>
-
- <bean id="rodProto" class="org.springframework.tests.sample.beans.TestBean" scope="prototype">
- <property name="name" value="dummy"/>
- <property name="age" value="-1"/>
- </bean>
-
-</beans> | true |
Other | spring-projects | spring-framework | 15e9fe638c631c8c75d3499a083c103ddef594a8.json | Remove duplicate test resources
The files deleted in this commit existed in identical form in two places
within a given module; typically in src/test/java and
src/test/resources. The version within src/test/resources has been
favored in all cases.
This change was prompted by associated Eclipse warnings, which have now
been quelled.
Issue: SPR-9431 | spring-webmvc/src/test/java/org/springframework/web/servlet/complexviews.properties | @@ -1,3 +0,0 @@
-form.(class)=org.springframework.web.servlet.view.InternalResourceView
-form.requestContextAttribute=rc
-form.url=myform.jsp | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-aop/src/test/java/org/springframework/aop/interceptor/CustomizableTraceInterceptorTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -24,8 +24,6 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import java.lang.reflect.Method;
-
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.junit.Test; | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-aop/src/test/java/org/springframework/aop/interceptor/SimpleTraceInterceptorTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -24,8 +24,6 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import java.lang.reflect.Method;
-
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.junit.Test; | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java | @@ -47,8 +47,6 @@
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
-import org.springframework.tests.Assume;
-import org.springframework.tests.TestGroup;
import org.springframework.tests.sample.beans.GenericBean;
import org.springframework.tests.sample.beans.GenericIntegerBean;
import org.springframework.tests.sample.beans.GenericSetOfIntegerBean; | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java | @@ -24,8 +24,6 @@
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
-import org.springframework.tests.Assume;
-import org.springframework.tests.TestGroup;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*; | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-beans/src/test/java/org/springframework/tests/beans/CollectingReaderEventListener.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -29,7 +29,6 @@
import org.springframework.beans.factory.parsing.DefaultsDefinition;
import org.springframework.beans.factory.parsing.ImportDefinition;
import org.springframework.beans.factory.parsing.ReaderEventListener;
-import org.springframework.core.CollectionFactory;
/**
* @author Rob Harrop | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -18,7 +18,6 @@
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-jdbc/src/test/java/org/springframework/jdbc/core/AbstractRowMapperTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -26,7 +26,6 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
| true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/TableMetaDataContextTests.java | @@ -1,3 +1,19 @@
+/*
+ * Copyright 2002-2013 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.springframework.jdbc.core.simple;
import static org.junit.Assert.*;
@@ -9,7 +25,6 @@
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
-import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Date; | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-webmvc-portlet/src/test/java/org/springframework/web/portlet/bind/PortletRequestUtilsTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -16,8 +16,6 @@
package org.springframework.web.portlet.bind;
-import junit.framework.TestCase;
-
import org.junit.Test;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup; | true |
Other | spring-projects | spring-framework | 51b307681a8ee7d89180f58f967856b9c4bf9232.json | Fix warnings due to unused import statements
Issue: SPR-9431 | spring-webmvc/src/test/java/org/springframework/web/context/support/ServletContextSupportTests.java | @@ -41,7 +41,6 @@
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.support.ManagedSet;
import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.test.MockServletContext;
| true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/beans/DerivedTestBean.java | @@ -1,87 +0,0 @@
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.beans;
-
-import java.io.Serializable;
-
-/**
- * @author Juergen Hoeller
- * @since 21.08.2003
- */
-@SuppressWarnings("serial")
-public class DerivedTestBean extends TestBean implements Serializable {
-
- private String beanName;
-
- private boolean initialized;
-
- private boolean destroyed;
-
-
- public DerivedTestBean() {
- }
-
- public DerivedTestBean(String[] names) {
- if (names == null || names.length < 2) {
- throw new IllegalArgumentException("Invalid names array");
- }
- setName(names[0]);
- setBeanName(names[1]);
- }
-
- public static DerivedTestBean create(String[] names) {
- return new DerivedTestBean(names);
- }
-
-
- @Override
- public void setBeanName(String beanName) {
- if (this.beanName == null || beanName == null) {
- this.beanName = beanName;
- }
- }
-
- @Override
- public String getBeanName() {
- return beanName;
- }
-
- public void setSpouseRef(String name) {
- setSpouse(new TestBean(name));
- }
-
-
- public void initialize() {
- this.initialized = true;
- }
-
- public boolean wasInitialized() {
- return initialized;
- }
-
-
- @Override
- public void destroy() {
- this.destroyed = true;
- }
-
- @Override
- public boolean wasDestroyed() {
- return destroyed;
- }
-
-} | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/beans/GenericBean.java | @@ -1,237 +0,0 @@
-/*
- * Copyright 2002-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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.beans;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.springframework.core.io.Resource;
-
-/**
- * @author Juergen Hoeller
- */
-public class GenericBean<T> {
-
- private Set<Integer> integerSet;
-
- private List<Resource> resourceList;
-
- private List<List<Integer>> listOfLists;
-
- private ArrayList<String[]> listOfArrays;
-
- private List<Map<Integer, Long>> listOfMaps;
-
- private Map plainMap;
-
- private Map<Short, Integer> shortMap;
-
- private HashMap<Long, ?> longMap;
-
- private Map<Number, Collection<? extends Object>> collectionMap;
-
- private Map<String, Map<Integer, Long>> mapOfMaps;
-
- private Map<Integer, List<Integer>> mapOfLists;
-
- private CustomEnum customEnum;
-
- private T genericProperty;
-
- private List<T> genericListProperty;
-
-
- public GenericBean() {
- }
-
- public GenericBean(Set<Integer> integerSet) {
- this.integerSet = integerSet;
- }
-
- public GenericBean(Set<Integer> integerSet, List<Resource> resourceList) {
- this.integerSet = integerSet;
- this.resourceList = resourceList;
- }
-
- public GenericBean(HashSet<Integer> integerSet, Map<Short, Integer> shortMap) {
- this.integerSet = integerSet;
- this.shortMap = shortMap;
- }
-
- public GenericBean(Map<Short, Integer> shortMap, Resource resource) {
- this.shortMap = shortMap;
- this.resourceList = Collections.singletonList(resource);
- }
-
- public GenericBean(Map plainMap, Map<Short, Integer> shortMap) {
- this.plainMap = plainMap;
- this.shortMap = shortMap;
- }
-
- public GenericBean(HashMap<Long, ?> longMap) {
- this.longMap = longMap;
- }
-
- public GenericBean(boolean someFlag, Map<Number, Collection<? extends Object>> collectionMap) {
- this.collectionMap = collectionMap;
- }
-
-
- public Set<Integer> getIntegerSet() {
- return integerSet;
- }
-
- public void setIntegerSet(Set<Integer> integerSet) {
- this.integerSet = integerSet;
- }
-
- public List<Resource> getResourceList() {
- return resourceList;
- }
-
- public void setResourceList(List<Resource> resourceList) {
- this.resourceList = resourceList;
- }
-
- public List<List<Integer>> getListOfLists() {
- return listOfLists;
- }
-
- public ArrayList<String[]> getListOfArrays() {
- return listOfArrays;
- }
-
- public void setListOfArrays(ArrayList<String[]> listOfArrays) {
- this.listOfArrays = listOfArrays;
- }
-
- public void setListOfLists(List<List<Integer>> listOfLists) {
- this.listOfLists = listOfLists;
- }
-
- public List<Map<Integer, Long>> getListOfMaps() {
- return listOfMaps;
- }
-
- public void setListOfMaps(List<Map<Integer, Long>> listOfMaps) {
- this.listOfMaps = listOfMaps;
- }
-
- public Map getPlainMap() {
- return plainMap;
- }
-
- public Map<Short, Integer> getShortMap() {
- return shortMap;
- }
-
- public void setShortMap(Map<Short, Integer> shortMap) {
- this.shortMap = shortMap;
- }
-
- public HashMap<Long, ?> getLongMap() {
- return longMap;
- }
-
- public void setLongMap(HashMap<Long, ?> longMap) {
- this.longMap = longMap;
- }
-
- public Map<Number, Collection<? extends Object>> getCollectionMap() {
- return collectionMap;
- }
-
- public void setCollectionMap(Map<Number, Collection<? extends Object>> collectionMap) {
- this.collectionMap = collectionMap;
- }
-
- public Map<String, Map<Integer, Long>> getMapOfMaps() {
- return mapOfMaps;
- }
-
- public void setMapOfMaps(Map<String, Map<Integer, Long>> mapOfMaps) {
- this.mapOfMaps = mapOfMaps;
- }
-
- public Map<Integer, List<Integer>> getMapOfLists() {
- return mapOfLists;
- }
-
- public void setMapOfLists(Map<Integer, List<Integer>> mapOfLists) {
- this.mapOfLists = mapOfLists;
- }
-
- public T getGenericProperty() {
- return genericProperty;
- }
-
- public void setGenericProperty(T genericProperty) {
- this.genericProperty = genericProperty;
- }
-
- public List<T> getGenericListProperty() {
- return genericListProperty;
- }
-
- public void setGenericListProperty(List<T> genericListProperty) {
- this.genericListProperty = genericListProperty;
- }
-
- public CustomEnum getCustomEnum() {
- return customEnum;
- }
-
- public void setCustomEnum(CustomEnum customEnum) {
- this.customEnum = customEnum;
- }
-
-
- public static GenericBean createInstance(Set<Integer> integerSet) {
- return new GenericBean(integerSet);
- }
-
- public static GenericBean createInstance(Set<Integer> integerSet, List<Resource> resourceList) {
- return new GenericBean(integerSet, resourceList);
- }
-
- public static GenericBean createInstance(HashSet<Integer> integerSet, Map<Short, Integer> shortMap) {
- return new GenericBean(integerSet, shortMap);
- }
-
- public static GenericBean createInstance(Map<Short, Integer> shortMap, Resource resource) {
- return new GenericBean(shortMap, resource);
- }
-
- public static GenericBean createInstance(Map map, Map<Short, Integer> shortMap) {
- return new GenericBean(map, shortMap);
- }
-
- public static GenericBean createInstance(HashMap<Long, ?> longMap) {
- return new GenericBean(longMap);
- }
-
- public static GenericBean createInstance(boolean someFlag, Map<Number, Collection<? extends Object>> collectionMap) {
- return new GenericBean(someFlag, collectionMap);
- }
-
-}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/beans/ITestBean.java | @@ -1,71 +0,0 @@
-/*
- * Copyright 2002-2007 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.beans;
-
-import java.io.IOException;
-
-/**
- * Interface used for {@link org.springframework.beans.TestBean}.
- *
- * <p>Two methods are the same as on Person, but if this
- * extends person it breaks quite a few tests..
- *
- * @author Rod Johnson
- * @author Juergen Hoeller
- */
-public interface ITestBean {
-
- int getAge();
-
- void setAge(int age);
-
- String getName();
-
- void setName(String name);
-
- ITestBean getSpouse();
-
- void setSpouse(ITestBean spouse);
-
- ITestBean[] getSpouses();
-
- String[] getStringArray();
-
- void setStringArray(String[] stringArray);
-
- /**
- * Throws a given (non-null) exception.
- */
- void exceptional(Throwable t) throws Throwable;
-
- Object returnsThis();
-
- INestedTestBean getDoctor();
-
- INestedTestBean getLawyer();
-
- IndexedTestBean getNestedIndexedBean();
-
- /**
- * Increment the age by one.
- * @return the previous age
- */
- int haveBirthday();
-
- void unreliableFileOperation() throws IOException;
-
-}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/beans/IndexedTestBean.java | @@ -1,145 +0,0 @@
-/*
- * Copyright 2002-2006 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.beans;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-/**
- * @author Juergen Hoeller
- * @since 11.11.2003
- */
-public class IndexedTestBean {
-
- private TestBean[] array;
-
- private Collection collection;
-
- private List list;
-
- private Set set;
-
- private SortedSet sortedSet;
-
- private Map map;
-
- private SortedMap sortedMap;
-
-
- public IndexedTestBean() {
- this(true);
- }
-
- public IndexedTestBean(boolean populate) {
- if (populate) {
- populate();
- }
- }
-
- public void populate() {
- TestBean tb0 = new TestBean("name0", 0);
- TestBean tb1 = new TestBean("name1", 0);
- TestBean tb2 = new TestBean("name2", 0);
- TestBean tb3 = new TestBean("name3", 0);
- TestBean tb4 = new TestBean("name4", 0);
- TestBean tb5 = new TestBean("name5", 0);
- TestBean tb6 = new TestBean("name6", 0);
- TestBean tb7 = new TestBean("name7", 0);
- TestBean tbX = new TestBean("nameX", 0);
- TestBean tbY = new TestBean("nameY", 0);
- this.array = new TestBean[] {tb0, tb1};
- this.list = new ArrayList();
- this.list.add(tb2);
- this.list.add(tb3);
- this.set = new TreeSet();
- this.set.add(tb6);
- this.set.add(tb7);
- this.map = new HashMap();
- this.map.put("key1", tb4);
- this.map.put("key2", tb5);
- this.map.put("key.3", tb5);
- List list = new ArrayList();
- list.add(tbX);
- list.add(tbY);
- this.map.put("key4", list);
- }
-
-
- public TestBean[] getArray() {
- return array;
- }
-
- public void setArray(TestBean[] array) {
- this.array = array;
- }
-
- public Collection getCollection() {
- return collection;
- }
-
- public void setCollection(Collection collection) {
- this.collection = collection;
- }
-
- public List getList() {
- return list;
- }
-
- public void setList(List list) {
- this.list = list;
- }
-
- public Set getSet() {
- return set;
- }
-
- public void setSet(Set set) {
- this.set = set;
- }
-
- public SortedSet getSortedSet() {
- return sortedSet;
- }
-
- public void setSortedSet(SortedSet sortedSet) {
- this.sortedSet = sortedSet;
- }
-
- public Map getMap() {
- return map;
- }
-
- public void setMap(Map map) {
- this.map = map;
- }
-
- public SortedMap getSortedMap() {
- return sortedMap;
- }
-
- public void setSortedMap(SortedMap sortedMap) {
- this.sortedMap = sortedMap;
- }
-
-}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/beans/NestedTestBean.java | @@ -1,61 +0,0 @@
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.beans;
-
-/**
- * Simple nested test bean used for testing bean factories, AOP framework etc.
- *
- * @author Trevor D. Cook
- * @since 30.09.2003
- */
-public class NestedTestBean implements INestedTestBean {
-
- private String company = "";
-
- public NestedTestBean() {
- }
-
- public NestedTestBean(String company) {
- setCompany(company);
- }
-
- public void setCompany(String company) {
- this.company = (company != null ? company : "");
- }
-
- @Override
- public String getCompany() {
- return company;
- }
-
- public boolean equals(Object obj) {
- if (!(obj instanceof NestedTestBean)) {
- return false;
- }
- NestedTestBean ntb = (NestedTestBean) obj;
- return this.company.equals(ntb.company);
- }
-
- public int hashCode() {
- return this.company.hashCode();
- }
-
- public String toString() {
- return "NestedTestBean: " + this.company;
- }
-
-}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/beans/TestBean.java | @@ -1,442 +0,0 @@
-/*
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.beans;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.springframework.util.ObjectUtils;
-
-/**
- * Simple test bean used for testing bean factories, the AOP framework etc.
- *
- * @author Rod Johnson
- * @author Juergen Hoeller
- * @since 15 April 2001
- */
-public class TestBean implements ITestBean, IOther, Comparable {
-
- private String beanName;
-
- private String country;
-
- private boolean postProcessed;
-
- private String name;
-
- private String sex;
-
- private int age;
-
- private boolean jedi;
-
- private ITestBean[] spouses;
-
- private String touchy;
-
- private String[] stringArray;
-
- private Integer[] someIntegerArray;
-
- private Date date = new Date();
-
- private Float myFloat = new Float(0.0);
-
- private Collection friends = new LinkedList();
-
- private Set someSet = new HashSet();
-
- private Map someMap = new HashMap();
-
- private List someList = new ArrayList();
-
- private Properties someProperties = new Properties();
-
- private INestedTestBean doctor = new NestedTestBean();
-
- private INestedTestBean lawyer = new NestedTestBean();
-
- private IndexedTestBean nestedIndexedBean;
-
- private boolean destroyed;
-
- private Number someNumber;
-
- private Colour favouriteColour;
-
- private Boolean someBoolean;
-
- private List otherColours;
-
- private List pets;
-
-
- public TestBean() {
- }
-
- public TestBean(String name) {
- this.name = name;
- }
-
- public TestBean(ITestBean spouse) {
- this.spouses = new ITestBean[] {spouse};
- }
-
- public TestBean(String name, int age) {
- this.name = name;
- this.age = age;
- }
-
- public TestBean(ITestBean spouse, Properties someProperties) {
- this.spouses = new ITestBean[] {spouse};
- this.someProperties = someProperties;
- }
-
- public TestBean(List someList) {
- this.someList = someList;
- }
-
- public TestBean(Set someSet) {
- this.someSet = someSet;
- }
-
- public TestBean(Map someMap) {
- this.someMap = someMap;
- }
-
- public TestBean(Properties someProperties) {
- this.someProperties = someProperties;
- }
-
-
- public void setBeanName(String beanName) {
- this.beanName = beanName;
- }
-
- public String getBeanName() {
- return beanName;
- }
-
- public void setPostProcessed(boolean postProcessed) {
- this.postProcessed = postProcessed;
- }
-
- public boolean isPostProcessed() {
- return postProcessed;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(String name) {
- this.name = name;
- }
-
- public String getSex() {
- return sex;
- }
-
- public void setSex(String sex) {
- this.sex = sex;
- if (this.name == null) {
- this.name = sex;
- }
- }
-
- @Override
- public int getAge() {
- return age;
- }
-
- @Override
- public void setAge(int age) {
- this.age = age;
- }
-
- public boolean isJedi() {
- return jedi;
- }
-
- public void setJedi(boolean jedi) {
- this.jedi = jedi;
- }
-
- @Override
- public ITestBean getSpouse() {
- return (spouses != null ? spouses[0] : null);
- }
-
- @Override
- public void setSpouse(ITestBean spouse) {
- this.spouses = new ITestBean[] {spouse};
- }
-
- @Override
- public ITestBean[] getSpouses() {
- return spouses;
- }
-
- public String getTouchy() {
- return touchy;
- }
-
- public void setTouchy(String touchy) throws Exception {
- if (touchy.indexOf('.') != -1) {
- throw new Exception("Can't contain a .");
- }
- if (touchy.indexOf(',') != -1) {
- throw new NumberFormatException("Number format exception: contains a ,");
- }
- this.touchy = touchy;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-
- @Override
- public String[] getStringArray() {
- return stringArray;
- }
-
- @Override
- public void setStringArray(String[] stringArray) {
- this.stringArray = stringArray;
- }
-
- public Integer[] getSomeIntegerArray() {
- return someIntegerArray;
- }
-
- public void setSomeIntegerArray(Integer[] someIntegerArray) {
- this.someIntegerArray = someIntegerArray;
- }
-
- public Date getDate() {
- return date;
- }
-
- public void setDate(Date date) {
- this.date = date;
- }
-
- public Float getMyFloat() {
- return myFloat;
- }
-
- public void setMyFloat(Float myFloat) {
- this.myFloat = myFloat;
- }
-
- public Collection getFriends() {
- return friends;
- }
-
- public void setFriends(Collection friends) {
- this.friends = friends;
- }
-
- public Set getSomeSet() {
- return someSet;
- }
-
- public void setSomeSet(Set someSet) {
- this.someSet = someSet;
- }
-
- public Map getSomeMap() {
- return someMap;
- }
-
- public void setSomeMap(Map someMap) {
- this.someMap = someMap;
- }
-
- public List getSomeList() {
- return someList;
- }
-
- public void setSomeList(List someList) {
- this.someList = someList;
- }
-
- public Properties getSomeProperties() {
- return someProperties;
- }
-
- public void setSomeProperties(Properties someProperties) {
- this.someProperties = someProperties;
- }
-
- @Override
- public INestedTestBean getDoctor() {
- return doctor;
- }
-
- public void setDoctor(INestedTestBean doctor) {
- this.doctor = doctor;
- }
-
- @Override
- public INestedTestBean getLawyer() {
- return lawyer;
- }
-
- public void setLawyer(INestedTestBean lawyer) {
- this.lawyer = lawyer;
- }
-
- public Number getSomeNumber() {
- return someNumber;
- }
-
- public void setSomeNumber(Number someNumber) {
- this.someNumber = someNumber;
- }
-
- public Colour getFavouriteColour() {
- return favouriteColour;
- }
-
- public void setFavouriteColour(Colour favouriteColour) {
- this.favouriteColour = favouriteColour;
- }
-
- public Boolean getSomeBoolean() {
- return someBoolean;
- }
-
- public void setSomeBoolean(Boolean someBoolean) {
- this.someBoolean = someBoolean;
- }
-
- @Override
- public IndexedTestBean getNestedIndexedBean() {
- return nestedIndexedBean;
- }
-
- public void setNestedIndexedBean(IndexedTestBean nestedIndexedBean) {
- this.nestedIndexedBean = nestedIndexedBean;
- }
-
- public List getOtherColours() {
- return otherColours;
- }
-
- public void setOtherColours(List otherColours) {
- this.otherColours = otherColours;
- }
-
- public List getPets() {
- return pets;
- }
-
- public void setPets(List pets) {
- this.pets = pets;
- }
-
-
- /**
- * @see ITestBean#exceptional(Throwable)
- */
- @Override
- public void exceptional(Throwable t) throws Throwable {
- if (t != null) {
- throw t;
- }
- }
-
- @Override
- public void unreliableFileOperation() throws IOException {
- throw new IOException();
- }
- /**
- * @see ITestBean#returnsThis()
- */
- @Override
- public Object returnsThis() {
- return this;
- }
-
- /**
- * @see IOther#absquatulate()
- */
- @Override
- public void absquatulate() {
- }
-
- @Override
- public int haveBirthday() {
- return age++;
- }
-
-
- public void destroy() {
- this.destroyed = true;
- }
-
- public boolean wasDestroyed() {
- return destroyed;
- }
-
-
- public boolean equals(Object other) {
- if (this == other) {
- return true;
- }
- if (other == null || !(other instanceof TestBean)) {
- return false;
- }
- TestBean tb2 = (TestBean) other;
- return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age);
- }
-
- public int hashCode() {
- return this.age;
- }
-
- @Override
- public int compareTo(Object other) {
- if (this.name != null && other instanceof TestBean) {
- return this.name.compareTo(((TestBean) other).getName());
- }
- else {
- return 1;
- }
- }
-
- public String toString() {
- return this.name;
- }
-
-}
\ No newline at end of file | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/core/ConventionsTests.java | @@ -23,31 +23,31 @@
import junit.framework.TestCase;
-import org.springframework.beans.TestBean;
+import org.springframework.tests.sample.objects.TestObject;
/**
* @author Rob Harrop
*/
public class ConventionsTests extends TestCase {
public void testSimpleObject() {
- TestBean testBean = new TestBean();
- assertEquals("Incorrect singular variable name", "testBean", Conventions.getVariableName(testBean));
+ TestObject testObject = new TestObject();
+ assertEquals("Incorrect singular variable name", "testObject", Conventions.getVariableName(testObject));
}
public void testArray() {
- TestBean[] testBeans = new TestBean[0];
- assertEquals("Incorrect plural array form", "testBeanList", Conventions.getVariableName(testBeans));
+ TestObject[] testObjects = new TestObject[0];
+ assertEquals("Incorrect plural array form", "testObjectList", Conventions.getVariableName(testObjects));
}
public void testCollections() {
- List<TestBean> list = new ArrayList<TestBean>();
- list.add(new TestBean());
- assertEquals("Incorrect plural List form", "testBeanList", Conventions.getVariableName(list));
+ List<TestObject> list = new ArrayList<TestObject>();
+ list.add(new TestObject());
+ assertEquals("Incorrect plural List form", "testObjectList", Conventions.getVariableName(list));
- Set<TestBean> set = new HashSet<TestBean>();
- set.add(new TestBean());
- assertEquals("Incorrect plural Set form", "testBeanList", Conventions.getVariableName(set));
+ Set<TestObject> set = new HashSet<TestObject>();
+ set.add(new TestObject());
+ assertEquals("Incorrect plural Set form", "testObjectList", Conventions.getVariableName(set));
List<?> emptyList = new ArrayList<Object>();
try { | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/core/GenericCollectionTypeResolverTests.java | @@ -25,8 +25,8 @@
import java.util.Map;
import java.util.Set;
-import org.springframework.beans.GenericBean;
import org.springframework.core.io.Resource;
+import org.springframework.tests.sample.objects.GenericObject;
/**
* @author Serge Bogatyrjov
@@ -93,11 +93,11 @@ public void testE3() throws Exception {
}
public void testProgrammaticListIntrospection() throws Exception {
- Method setter = GenericBean.class.getMethod("setResourceList", List.class);
+ Method setter = GenericObject.class.getMethod("setResourceList", List.class);
assertEquals(Resource.class,
GenericCollectionTypeResolver.getCollectionParameterType(new MethodParameter(setter, 0)));
- Method getter = GenericBean.class.getMethod("getResourceList");
+ Method getter = GenericObject.class.getMethod("getResourceList");
assertEquals(Resource.class,
GenericCollectionTypeResolver.getCollectionReturnType(getter));
} | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/core/LocalVariableTableParameterNameDiscovererTests.java | @@ -25,7 +25,7 @@
import junit.framework.TestCase;
import org.junit.Ignore;
-import org.springframework.beans.TestBean;
+import org.springframework.tests.sample.objects.TestObject;
/**
* @author Adrian Colyer
@@ -35,29 +35,29 @@ public class LocalVariableTableParameterNameDiscovererTests extends TestCase {
private LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
public void testMethodParameterNameDiscoveryNoArgs() throws NoSuchMethodException {
- Method getName = TestBean.class.getMethod("getName", new Class[0]);
+ Method getName = TestObject.class.getMethod("getName", new Class[0]);
String[] names = discoverer.getParameterNames(getName);
assertNotNull("should find method info", names);
assertEquals("no argument names", 0, names.length);
}
public void testMethodParameterNameDiscoveryWithArgs() throws NoSuchMethodException {
- Method setName = TestBean.class.getMethod("setName", new Class[] { String.class });
+ Method setName = TestObject.class.getMethod("setName", new Class[] { String.class });
String[] names = discoverer.getParameterNames(setName);
assertNotNull("should find method info", names);
assertEquals("one argument", 1, names.length);
assertEquals("name", names[0]);
}
public void testConsParameterNameDiscoveryNoArgs() throws NoSuchMethodException {
- Constructor<TestBean> noArgsCons = TestBean.class.getConstructor(new Class[0]);
+ Constructor<TestObject> noArgsCons = TestObject.class.getConstructor(new Class[0]);
String[] names = discoverer.getParameterNames(noArgsCons);
assertNotNull("should find cons info", names);
assertEquals("no argument names", 0, names.length);
}
public void testConsParameterNameDiscoveryArgs() throws NoSuchMethodException {
- Constructor<TestBean> twoArgCons = TestBean.class.getConstructor(new Class[] { String.class, int.class });
+ Constructor<TestObject> twoArgCons = TestObject.class.getConstructor(new Class[] { String.class, int.class });
String[] names = discoverer.getParameterNames(twoArgCons);
assertNotNull("should find cons info", names);
assertEquals("one argument", 2, names.length); | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/core/PrioritizedParameterNameDiscovererTests.java | @@ -22,7 +22,7 @@
import junit.framework.TestCase;
-import org.springframework.beans.TestBean;
+import org.springframework.tests.sample.objects.TestObject;
public class PrioritizedParameterNameDiscovererTests extends TestCase {
@@ -56,7 +56,7 @@ public String[] getParameterNames(Constructor ctor) {
private final Class anyClass = Object.class;
public PrioritizedParameterNameDiscovererTests() throws SecurityException, NoSuchMethodException {
- anyMethod = TestBean.class.getMethod("getAge", (Class[]) null);
+ anyMethod = TestObject.class.getMethod("getAge", (Class[]) null);
}
public void testNoParametersDiscoverers() { | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/tests/sample/objects/DerivedTestObject.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -14,17 +14,11 @@
* limitations under the License.
*/
-package org.springframework.beans;
+package org.springframework.tests.sample.objects;
-/**
- * @author Juergen Hoeller
- */
-public enum CustomEnum {
-
- VALUE_1, VALUE_2;
+import java.io.Serializable;
- public String toString() {
- return "CustomEnum: " + name();
- }
+@SuppressWarnings("serial")
+public class DerivedTestObject extends TestObject implements Serializable {
-}
\ No newline at end of file
+} | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/tests/sample/objects/GenericObject.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -14,23 +14,23 @@
* limitations under the License.
*/
-package org.springframework.beans;
+package org.springframework.tests.sample.objects;
-import org.springframework.core.enums.ShortCodedLabeledEnum;
+import java.util.List;
-/**
- * @author Rob Harrop
- */
-@SuppressWarnings("serial")
-public class Colour extends ShortCodedLabeledEnum {
+import org.springframework.core.io.Resource;
+
+
+public class GenericObject<T> {
- public static final Colour RED = new Colour(0, "RED");
- public static final Colour BLUE = new Colour(1, "BLUE");
- public static final Colour GREEN = new Colour(2, "GREEN");
- public static final Colour PURPLE = new Colour(3, "PURPLE");
+ private List<Resource> resourceList;
+
+ public List<Resource> getResourceList() {
+ return this.resourceList;
+ }
- private Colour(int code, String label) {
- super(code, label);
+ public void setResourceList(List<Resource> resourceList) {
+ this.resourceList = resourceList;
}
} | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/tests/sample/objects/ITestInterface.java | @@ -1,6 +1,5 @@
-
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -15,10 +14,11 @@
* limitations under the License.
*/
-package org.springframework.beans;
+package org.springframework.tests.sample.objects;
+
-public interface IOther {
+public interface ITestInterface {
void absquatulate();
-}
\ No newline at end of file
+} | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/tests/sample/objects/ITestObject.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -14,10 +14,20 @@
* limitations under the License.
*/
-package org.springframework.beans;
+package org.springframework.tests.sample.objects;
-public interface INestedTestBean {
+public interface ITestObject {
- public String getCompany();
+ String getName();
-}
\ No newline at end of file
+ void setName(String name);
+
+ int getAge();
+
+ void setAge(int age);
+
+ TestObject getSpouse();
+
+ void setSpouse(TestObject spouse);
+
+} | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/tests/sample/objects/TestObject.java | @@ -0,0 +1,72 @@
+/*
+ * Copyright 2002-2013 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.tests.sample.objects;
+
+public class TestObject implements ITestObject, ITestInterface, Comparable<Object> {
+
+ private String name;
+
+ private int age;
+
+ private TestObject spouse;
+
+ public TestObject() {
+ }
+
+ public TestObject(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return this.age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public TestObject getSpouse() {
+ return this.spouse;
+ }
+
+ public void setSpouse(TestObject spouse) {
+ this.spouse = spouse;
+ }
+
+ @Override
+ public void absquatulate() {
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ if (this.name != null && o instanceof TestObject) {
+ return this.name.compareTo(((TestObject) o).getName());
+ }
+ else {
+ return 1;
+ }
+ }
+} | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/tests/sample/objects/package-info.java | @@ -0,0 +1,4 @@
+/**
+ * General purpose sample objects that can be used with tests.
+ */
+package org.springframework.tests.sample.objects; | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java | @@ -20,7 +20,7 @@
import junit.framework.*;
-import org.springframework.beans.TestBean;
+import org.springframework.tests.sample.objects.TestObject;
/**
* @author Rob Harrop
@@ -29,11 +29,11 @@
public class AutoPopulatingListTests extends TestCase {
public void testWithClass() throws Exception {
- doTestWithClass(new AutoPopulatingList<Object>(TestBean.class));
+ doTestWithClass(new AutoPopulatingList<Object>(TestObject.class));
}
public void testWithClassAndUserSuppliedBackingList() throws Exception {
- doTestWithClass(new AutoPopulatingList<Object>(new LinkedList<Object>(), TestBean.class));
+ doTestWithClass(new AutoPopulatingList<Object>(new LinkedList<Object>(), TestObject.class));
}
public void testWithElementFactory() throws Exception {
@@ -49,7 +49,7 @@ private void doTestWithClass(AutoPopulatingList<Object> list) {
for (int x = 0; x < 10; x++) {
Object element = list.get(x);
assertNotNull("Element is null", list.get(x));
- assertTrue("Element is incorrect type", element instanceof TestBean);
+ assertTrue("Element is incorrect type", element instanceof TestObject);
assertNotSame(lastElement, element);
lastElement = element;
}
@@ -59,25 +59,25 @@ private void doTestWithClass(AutoPopulatingList<Object> list) {
list.add(11, helloWorld);
assertEquals(helloWorld, list.get(11));
- assertTrue(list.get(10) instanceof TestBean);
- assertTrue(list.get(12) instanceof TestBean);
- assertTrue(list.get(13) instanceof TestBean);
- assertTrue(list.get(20) instanceof TestBean);
+ assertTrue(list.get(10) instanceof TestObject);
+ assertTrue(list.get(12) instanceof TestObject);
+ assertTrue(list.get(13) instanceof TestObject);
+ assertTrue(list.get(20) instanceof TestObject);
}
private void doTestWithElementFactory(AutoPopulatingList<Object> list) {
doTestWithClass(list);
for(int x = 0; x < list.size(); x++) {
Object element = list.get(x);
- if(element instanceof TestBean) {
- assertEquals(x, ((TestBean) element).getAge());
+ if(element instanceof TestObject) {
+ assertEquals(x, ((TestObject) element).getAge());
}
}
}
public void testSerialization() throws Exception {
- AutoPopulatingList<?> list = new AutoPopulatingList<Object>(TestBean.class);
+ AutoPopulatingList<?> list = new AutoPopulatingList<Object>(TestObject.class);
assertEquals(list, SerializationTestUtils.serializeAndDeserialize(list));
}
@@ -86,7 +86,7 @@ private static class MockElementFactory implements AutoPopulatingList.ElementFac
@Override
public Object createElement(int index) {
- TestBean bean = new TestBean();
+ TestObject bean = new TestObject();
bean.setAge(index);
return bean;
} | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java | @@ -28,10 +28,10 @@
import junit.framework.TestCase;
-import org.springframework.beans.DerivedTestBean;
-import org.springframework.beans.IOther;
-import org.springframework.beans.ITestBean;
-import org.springframework.beans.TestBean;
+import org.springframework.tests.sample.objects.DerivedTestObject;
+import org.springframework.tests.sample.objects.ITestInterface;
+import org.springframework.tests.sample.objects.ITestObject;
+import org.springframework.tests.sample.objects.TestObject;
/**
* @author Colin Sampaleanu
@@ -61,11 +61,11 @@ public void testForName() throws ClassNotFoundException {
assertEquals(String[].class, ClassUtils.forName(String[].class.getName(), classLoader));
assertEquals(String[][].class, ClassUtils.forName(String[][].class.getName(), classLoader));
assertEquals(String[][][].class, ClassUtils.forName(String[][][].class.getName(), classLoader));
- assertEquals(TestBean.class, ClassUtils.forName("org.springframework.beans.TestBean", classLoader));
- assertEquals(TestBean[].class, ClassUtils.forName("org.springframework.beans.TestBean[]", classLoader));
- assertEquals(TestBean[].class, ClassUtils.forName(TestBean[].class.getName(), classLoader));
- assertEquals(TestBean[][].class, ClassUtils.forName("org.springframework.beans.TestBean[][]", classLoader));
- assertEquals(TestBean[][].class, ClassUtils.forName(TestBean[][].class.getName(), classLoader));
+ assertEquals(TestObject.class, ClassUtils.forName("org.springframework.tests.sample.objects.TestObject", classLoader));
+ assertEquals(TestObject[].class, ClassUtils.forName("org.springframework.tests.sample.objects.TestObject[]", classLoader));
+ assertEquals(TestObject[].class, ClassUtils.forName(TestObject[].class.getName(), classLoader));
+ assertEquals(TestObject[][].class, ClassUtils.forName("org.springframework.tests.sample.objects.TestObject[][]", classLoader));
+ assertEquals(TestObject[][].class, ClassUtils.forName(TestObject[][].class.getName(), classLoader));
assertEquals(short[][][].class, ClassUtils.forName("[[[S", classLoader));
}
@@ -201,11 +201,11 @@ public void testGetMethodCountForName() {
}
public void testCountOverloadedMethods() {
- assertFalse(ClassUtils.hasAtLeastOneMethodWithName(TestBean.class, "foobar"));
+ assertFalse(ClassUtils.hasAtLeastOneMethodWithName(TestObject.class, "foobar"));
// no args
- assertTrue(ClassUtils.hasAtLeastOneMethodWithName(TestBean.class, "hashCode"));
+ assertTrue(ClassUtils.hasAtLeastOneMethodWithName(TestObject.class, "hashCode"));
// matches although it takes an arg
- assertTrue(ClassUtils.hasAtLeastOneMethodWithName(TestBean.class, "setAge"));
+ assertTrue(ClassUtils.hasAtLeastOneMethodWithName(TestObject.class, "setAge"));
}
public void testNoArgsStaticMethod() throws IllegalAccessException, InvocationTargetException {
@@ -260,12 +260,12 @@ public void testAddResourcePathToPackagePath() {
}
public void testGetAllInterfaces() {
- DerivedTestBean testBean = new DerivedTestBean();
+ DerivedTestObject testBean = new DerivedTestObject();
List ifcs = Arrays.asList(ClassUtils.getAllInterfaces(testBean));
assertEquals("Correct number of interfaces", 4, ifcs.size());
assertTrue("Contains Serializable", ifcs.contains(Serializable.class));
- assertTrue("Contains ITestBean", ifcs.contains(ITestBean.class));
- assertTrue("Contains IOther", ifcs.contains(IOther.class));
+ assertTrue("Contains ITestBean", ifcs.contains(ITestObject.class));
+ assertTrue("Contains IOther", ifcs.contains(ITestInterface.class));
}
public void testClassNamesToString() { | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/util/ReflectionUtilsTests.java | @@ -35,7 +35,7 @@
import org.junit.Ignore;
import org.junit.Test;
-import org.springframework.beans.TestBean;
+import org.springframework.tests.sample.objects.TestObject;
/**
* @author Rob Harrop
@@ -47,19 +47,19 @@ public class ReflectionUtilsTests {
@Test
public void findField() {
- Field field = ReflectionUtils.findField(TestBeanSubclassWithPublicField.class, "publicField", String.class);
+ Field field = ReflectionUtils.findField(TestObjectSubclassWithPublicField.class, "publicField", String.class);
assertNotNull(field);
assertEquals("publicField", field.getName());
assertEquals(String.class, field.getType());
assertTrue("Field should be public.", Modifier.isPublic(field.getModifiers()));
- field = ReflectionUtils.findField(TestBeanSubclassWithNewField.class, "prot", String.class);
+ field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "prot", String.class);
assertNotNull(field);
assertEquals("prot", field.getName());
assertEquals(String.class, field.getType());
assertTrue("Field should be protected.", Modifier.isProtected(field.getModifiers()));
- field = ReflectionUtils.findField(TestBeanSubclassWithNewField.class, "name", String.class);
+ field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class);
assertNotNull(field);
assertEquals("name", field.getName());
assertEquals(String.class, field.getType());
@@ -68,8 +68,8 @@ public void findField() {
@Test
public void setField() {
- final TestBeanSubclassWithNewField testBean = new TestBeanSubclassWithNewField();
- final Field field = ReflectionUtils.findField(TestBeanSubclassWithNewField.class, "name", String.class);
+ final TestObjectSubclassWithNewField testBean = new TestObjectSubclassWithNewField();
+ final Field field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class);
ReflectionUtils.makeAccessible(field);
@@ -83,20 +83,20 @@ public void setField() {
@Test(expected = IllegalStateException.class)
public void setFieldIllegal() {
- final TestBeanSubclassWithNewField testBean = new TestBeanSubclassWithNewField();
- final Field field = ReflectionUtils.findField(TestBeanSubclassWithNewField.class, "name", String.class);
+ final TestObjectSubclassWithNewField testBean = new TestObjectSubclassWithNewField();
+ final Field field = ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class);
ReflectionUtils.setField(field, testBean, "FooBar");
}
@Test
public void invokeMethod() throws Exception {
String rob = "Rob Harrop";
- TestBean bean = new TestBean();
+ TestObject bean = new TestObject();
bean.setName(rob);
- Method getName = TestBean.class.getMethod("getName", (Class[]) null);
- Method setName = TestBean.class.getMethod("setName", new Class[] { String.class });
+ Method getName = TestObject.class.getMethod("getName", (Class[]) null);
+ Method setName = TestObject.class.getMethod("setName", new Class[] { String.class });
Object name = ReflectionUtils.invokeMethod(getName, bean);
assertEquals("Incorrect name returned", rob, name);
@@ -123,7 +123,7 @@ public void declaresException() throws Exception {
@Test
public void copySrcToDestinationOfIncorrectClass() {
- TestBean src = new TestBean();
+ TestObject src = new TestObject();
String dest = new String();
try {
ReflectionUtils.shallowCopyFieldState(src, dest);
@@ -135,7 +135,7 @@ public void copySrcToDestinationOfIncorrectClass() {
@Test
public void rejectsNullSrc() {
- TestBean src = null;
+ TestObject src = null;
String dest = new String();
try {
ReflectionUtils.shallowCopyFieldState(src, dest);
@@ -147,7 +147,7 @@ public void rejectsNullSrc() {
@Test
public void rejectsNullDest() {
- TestBean src = new TestBean();
+ TestObject src = new TestObject();
String dest = null;
try {
ReflectionUtils.shallowCopyFieldState(src, dest);
@@ -159,15 +159,15 @@ public void rejectsNullDest() {
@Test
public void validCopy() {
- TestBean src = new TestBean();
- TestBean dest = new TestBean();
+ TestObject src = new TestObject();
+ TestObject dest = new TestObject();
testValidCopy(src, dest);
}
@Test
public void validCopyOnSubTypeWithNewField() {
- TestBeanSubclassWithNewField src = new TestBeanSubclassWithNewField();
- TestBeanSubclassWithNewField dest = new TestBeanSubclassWithNewField();
+ TestObjectSubclassWithNewField src = new TestObjectSubclassWithNewField();
+ TestObjectSubclassWithNewField dest = new TestObjectSubclassWithNewField();
src.magic = 11;
// Will check inherited fields are copied
@@ -180,8 +180,8 @@ public void validCopyOnSubTypeWithNewField() {
@Test
public void validCopyToSubType() {
- TestBean src = new TestBean();
- TestBeanSubclassWithNewField dest = new TestBeanSubclassWithNewField();
+ TestObject src = new TestObject();
+ TestObjectSubclassWithNewField dest = new TestObjectSubclassWithNewField();
dest.magic = 11;
testValidCopy(src, dest);
// Should have left this one alone
@@ -190,28 +190,27 @@ public void validCopyToSubType() {
@Test
public void validCopyToSubTypeWithFinalField() {
- TestBeanSubclassWithFinalField src = new TestBeanSubclassWithFinalField();
- TestBeanSubclassWithFinalField dest = new TestBeanSubclassWithFinalField();
+ TestObjectSubclassWithFinalField src = new TestObjectSubclassWithFinalField();
+ TestObjectSubclassWithFinalField dest = new TestObjectSubclassWithFinalField();
// Check that this doesn't fail due to attempt to assign final
testValidCopy(src, dest);
}
- private void testValidCopy(TestBean src, TestBean dest) {
+ private void testValidCopy(TestObject src, TestObject dest) {
src.setName("freddie");
src.setAge(15);
- src.setSpouse(new TestBean());
+ src.setSpouse(new TestObject());
assertFalse(src.getAge() == dest.getAge());
ReflectionUtils.shallowCopyFieldState(src, dest);
assertEquals(src.getAge(), dest.getAge());
assertEquals(src.getSpouse(), dest.getSpouse());
- assertEquals(src.getDoctor(), dest.getDoctor());
}
@Test
public void doWithProtectedMethods() {
ListSavingMethodCallback mc = new ListSavingMethodCallback();
- ReflectionUtils.doWithMethods(TestBean.class, mc, new ReflectionUtils.MethodFilter() {
+ ReflectionUtils.doWithMethods(TestObject.class, mc, new ReflectionUtils.MethodFilter() {
@Override
public boolean matches(Method m) {
return Modifier.isProtected(m.getModifiers());
@@ -227,7 +226,7 @@ public boolean matches(Method m) {
@Test
public void duplicatesFound() {
ListSavingMethodCallback mc = new ListSavingMethodCallback();
- ReflectionUtils.doWithMethods(TestBeanSubclass.class, mc);
+ ReflectionUtils.doWithMethods(TestObjectSubclass.class, mc);
int absquatulateCount = 0;
for (String name : mc.getMethodNames()) {
if (name.equals("absquatulate")) {
@@ -370,28 +369,28 @@ public List<Method> getMethods() {
}
}
- private static class TestBeanSubclass extends TestBean {
+ private static class TestObjectSubclass extends TestObject {
@Override
public void absquatulate() {
throw new UnsupportedOperationException();
}
}
- private static class TestBeanSubclassWithPublicField extends TestBean {
+ private static class TestObjectSubclassWithPublicField extends TestObject {
@SuppressWarnings("unused")
public String publicField = "foo";
}
- private static class TestBeanSubclassWithNewField extends TestBean {
+ private static class TestObjectSubclassWithNewField extends TestObject {
private int magic;
protected String prot = "foo";
}
- private static class TestBeanSubclassWithFinalField extends TestBean {
+ private static class TestObjectSubclassWithFinalField extends TestObject {
@SuppressWarnings("unused")
private final String foo = "will break naive copy that doesn't exclude statics"; | true |
Other | spring-projects | spring-framework | 2a30fa07ea545c5187788825febd6e5eb7460275.json | Replace test beans with test objects
Refactor spring-core tests to replace test beans from
'org.springframework.beans' with lighter test objects in
'org.springframework.tests.sample.objects'. | spring-core/src/test/java/org/springframework/util/SerializationTestUtils.java | @@ -17,7 +17,7 @@
import junit.framework.TestCase;
-import org.springframework.beans.TestBean;
+import org.springframework.tests.sample.objects.TestObject;
/**
* Utilities for testing serializability of objects.
@@ -64,7 +64,7 @@ public SerializationTestUtils(String s) {
}
public void testWithNonSerializableObject() throws IOException {
- TestBean o = new TestBean();
+ TestObject o = new TestObject();
assertFalse(o instanceof Serializable);
assertFalse(isSerializable(o)); | true |
Other | spring-projects | spring-framework | 9f9f1ed2533110081c4a62b20d2b5658c8a68496.json | Fix ClassCastException when setting media types
Issue: SPR-10019 | spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java | @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import javax.servlet.ServletContext;
@@ -52,7 +53,7 @@
private boolean ignoreAcceptHeader = false;
- private Properties mediaTypes = new Properties();
+ private Map<String, MediaType> mediaTypes = new HashMap<String, MediaType>();
private Boolean useJaf;
@@ -64,7 +65,6 @@
private ServletContext servletContext;
-
/**
* Indicate whether the extension of the request path should be used to determine
* the requested media type with the <em>highest priority</em>.
@@ -77,28 +77,51 @@ public void setFavorPathExtension(boolean favorPathExtension) {
}
/**
- * Add mappings from file extensions to media types.
- * <p>If this property is not set, the Java Action Framework, if available, may
- * still be used in conjunction with {@link #setFavorPathExtension(boolean)}.
+ * Add mappings from file extensions to media types represented as strings.
+ * <p>When this mapping is not set or when an extension is not found, the Java
+ * Action Framework, if available, may be used if enabled via
+ * {@link #setFavorPathExtension(boolean)}.
+ *
+ * @see #addMediaType(String, MediaType)
+ * @see #addMediaTypes(Map)
*/
public void setMediaTypes(Properties mediaTypes) {
if (!CollectionUtils.isEmpty(mediaTypes)) {
- for (Map.Entry<Object, Object> entry : mediaTypes.entrySet()) {
- String extension = ((String) entry.getKey()).toLowerCase(Locale.ENGLISH);
+ for (Entry<Object, Object> entry : mediaTypes.entrySet()) {
+ String extension = ((String)entry.getKey()).toLowerCase(Locale.ENGLISH);
this.mediaTypes.put(extension, MediaType.valueOf((String) entry.getValue()));
}
}
}
- public Properties getMediaTypes() {
- return this.mediaTypes;
+ /**
+ * Add a mapping from a file extension to a media type.
+ * <p>If no mapping is added or when an extension is not found, the Java
+ * Action Framework, if available, may be used if enabled via
+ * {@link #setFavorPathExtension(boolean)}.
+ */
+ public void addMediaType(String fileExtension, MediaType mediaType) {
+ this.mediaTypes.put(fileExtension, mediaType);
+ }
+
+ /**
+ * Add mappings from file extensions to media types.
+ * <p>If no mappings are added or when an extension is not found, the Java
+ * Action Framework, if available, may be used if enabled via
+ * {@link #setFavorPathExtension(boolean)}.
+ */
+ public void addMediaTypes(Map<String, MediaType> mediaTypes) {
+ if (mediaTypes != null) {
+ this.mediaTypes.putAll(mediaTypes);
+ }
}
/**
* Indicate whether to use the Java Activation Framework as a fallback option
* to map from file extensions to media types. This is used only when
* {@link #setFavorPathExtension(boolean)} is set to {@code true}.
* <p>The default value is {@code true}.
+ *
* @see #parameterName
* @see #setMediaTypes(Properties)
*/
@@ -115,6 +138,7 @@ public void setUseJaf(boolean useJaf) {
* {@code "application/pdf"} regardless of the {@code Accept} header.
* <p>To use this option effectively you must also configure the MediaType
* type mappings via {@link #setMediaTypes(Properties)}.
+ *
* @see #setParameterName(String)
*/
public void setFavorParameter(boolean favorParameter) {
@@ -145,8 +169,8 @@ public void setIgnoreAcceptHeader(boolean ignoreAcceptHeader) {
/**
* Set the default content type.
* <p>This content type will be used when neither the request path extension,
- * nor a request parameter, nor the {@code Accept} header could help determine
- * the requested content type.
+ * nor a request parameter, nor the {@code Accept} header could help
+ * determine the requested content type.
*/
public void setDefaultContentType(MediaType defaultContentType) {
this.defaultContentType = defaultContentType;
@@ -159,16 +183,12 @@ public void setServletContext(ServletContext servletContext) {
public void afterPropertiesSet() throws Exception {
List<ContentNegotiationStrategy> strategies = new ArrayList<ContentNegotiationStrategy>();
- Map<String, MediaType> mediaTypesMap = new HashMap<String, MediaType>();
- CollectionUtils.mergePropertiesIntoMap(this.mediaTypes, mediaTypesMap);
-
if (this.favorPathExtension) {
PathExtensionContentNegotiationStrategy strategy;
if (this.servletContext != null) {
- strategy = new ServletPathExtensionContentNegotiationStrategy(this.servletContext, mediaTypesMap);
- }
- else {
- strategy = new PathExtensionContentNegotiationStrategy(mediaTypesMap);
+ strategy = new ServletPathExtensionContentNegotiationStrategy(this.servletContext, this.mediaTypes);
+ } else {
+ strategy = new PathExtensionContentNegotiationStrategy(this.mediaTypes);
}
if (this.useJaf != null) {
strategy.setUseJaf(this.useJaf);
@@ -177,7 +197,7 @@ public void afterPropertiesSet() throws Exception {
}
if (this.favorParameter) {
- ParameterContentNegotiationStrategy strategy = new ParameterContentNegotiationStrategy(mediaTypesMap);
+ ParameterContentNegotiationStrategy strategy = new ParameterContentNegotiationStrategy(this.mediaTypes);
strategy.setParameterName(this.parameterName);
strategies.add(strategy);
} | true |
Other | spring-projects | spring-framework | 9f9f1ed2533110081c4a62b20d2b5658c8a68496.json | Fix ClassCastException when setting media types
Issue: SPR-10019 | spring-web/src/test/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBeanTests.java | @@ -19,7 +19,8 @@
import java.util.Arrays;
import java.util.Collections;
-import java.util.Properties;
+import java.util.HashMap;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
@@ -74,9 +75,9 @@ public void defaultSettings() throws Exception {
@Test
public void addMediaTypes() throws Exception {
- Properties mediaTypes = new Properties();
- mediaTypes.put("json", MediaType.APPLICATION_JSON_VALUE);
- this.factoryBean.setMediaTypes(mediaTypes);
+ Map<String, MediaType> mediaTypes = new HashMap<String, MediaType>();
+ mediaTypes.put("json", MediaType.APPLICATION_JSON);
+ this.factoryBean.addMediaTypes(mediaTypes);
this.factoryBean.afterPropertiesSet();
ContentNegotiationManager manager = this.factoryBean.getObject();
@@ -89,9 +90,9 @@ public void addMediaTypes() throws Exception {
public void favorParameter() throws Exception {
this.factoryBean.setFavorParameter(true);
- Properties mediaTypes = new Properties();
- mediaTypes.put("json", MediaType.APPLICATION_JSON_VALUE);
- this.factoryBean.setMediaTypes(mediaTypes);
+ Map<String, MediaType> mediaTypes = new HashMap<String, MediaType>();
+ mediaTypes.put("json", MediaType.APPLICATION_JSON);
+ this.factoryBean.addMediaTypes(mediaTypes);
this.factoryBean.afterPropertiesSet();
ContentNegotiationManager manager = this.factoryBean.getObject(); | true |
Other | spring-projects | spring-framework | 9f9f1ed2533110081c4a62b20d2b5658c8a68496.json | Fix ClassCastException when setting media types
Issue: SPR-10019 | spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java | @@ -15,6 +15,7 @@
*/
package org.springframework.web.servlet.config.annotation;
+import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
@@ -36,7 +37,9 @@
*/
public class ContentNegotiationConfigurer {
- private ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
+ private final ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
+
+ private final Map<String, MediaType> mediaTypes = new HashMap<String, MediaType>();
/**
@@ -64,7 +67,7 @@ public ContentNegotiationConfigurer favorPathExtension(boolean favorPathExtensio
* still be used in conjunction with {@link #favorPathExtension(boolean)}.
*/
public ContentNegotiationConfigurer mediaType(String extension, MediaType mediaType) {
- this.factoryBean.getMediaTypes().put(extension, mediaType);
+ this.mediaTypes.put(extension, mediaType);
return this;
}
@@ -75,7 +78,7 @@ public ContentNegotiationConfigurer mediaType(String extension, MediaType mediaT
*/
public ContentNegotiationConfigurer mediaTypes(Map<String, MediaType> mediaTypes) {
if (mediaTypes != null) {
- this.factoryBean.getMediaTypes().putAll(mediaTypes);
+ this.mediaTypes.putAll(mediaTypes);
}
return this;
}
@@ -86,7 +89,7 @@ public ContentNegotiationConfigurer mediaTypes(Map<String, MediaType> mediaTypes
* still be used in conjunction with {@link #favorPathExtension(boolean)}.
*/
public ContentNegotiationConfigurer replaceMediaTypes(Map<String, MediaType> mediaTypes) {
- this.factoryBean.getMediaTypes().clear();
+ this.mediaTypes.clear();
mediaTypes(mediaTypes);
return this;
}
@@ -157,6 +160,9 @@ public ContentNegotiationConfigurer defaultContentType(MediaType defaultContentT
* Return the configured {@link ContentNegotiationManager} instance
*/
protected ContentNegotiationManager getContentNegotiationManager() throws Exception {
+ if (!this.mediaTypes.isEmpty()) {
+ this.factoryBean.addMediaTypes(mediaTypes);
+ }
this.factoryBean.afterPropertiesSet();
return this.factoryBean.getObject();
} | true |
Other | spring-projects | spring-framework | 9f9f1ed2533110081c4a62b20d2b5658c8a68496.json | Fix ClassCastException when setting media types
Issue: SPR-10019 | spring-webmvc/src/main/java/org/springframework/web/servlet/view/ContentNegotiatingViewResolver.java | @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import javax.activation.FileTypeMap;
@@ -196,7 +197,9 @@ public void setIgnoreAcceptHeader(boolean ignoreAcceptHeader) {
@Deprecated
public void setMediaTypes(Map<String, String> mediaTypes) {
if (mediaTypes != null) {
- this.cnManagerFactoryBean.getMediaTypes().putAll(mediaTypes);
+ Properties props = new Properties();
+ props.putAll(mediaTypes);
+ this.cnManagerFactoryBean.setMediaTypes(props);
}
}
| true |
Other | spring-projects | spring-framework | 830d73b4a7cc046d80068318389891562ed47076.json | Eliminate EBR dependencies and repository config
Swap the following EBR-specific dependencies for their equivalents at
Maven Central:
- atinject-tck
- jaxb
- xmlbeans
Remove the /ebr-maven-external repository from the build script entirely
such that all dependencies are now resolved against a single repository:
http://repo.springsource.org/libs-release | build.gradle | @@ -72,7 +72,6 @@ configure(allprojects) { project ->
repositories {
maven { url "http://repo.springsource.org/libs-release" }
- maven { url "http://repo.springsource.org/ebr-maven-external" }
}
dependencies {
@@ -332,7 +331,7 @@ project("spring-context") {
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1")
testCompile("commons-dbcp:commons-dbcp:1.2.2")
- testCompile("javax.inject:com.springsource.org.atinject.tck:1.0.0")
+ testCompile("javax.inject:javax.inject-tck:1")
}
test { | true |
Other | spring-projects | spring-framework | 830d73b4a7cc046d80068318389891562ed47076.json | Eliminate EBR dependencies and repository config
Swap the following EBR-specific dependencies for their equivalents at
Maven Central:
- atinject-tck
- jaxb
- xmlbeans
Remove the /ebr-maven-external repository from the build script entirely
such that all dependencies are now resolved against a single repository:
http://repo.springsource.org/libs-release | spring-oxm/oxm.gradle | @@ -7,8 +7,8 @@ configurations {
dependencies {
castor "org.codehaus.castor:castor-anttasks:1.2"
castor "velocity:velocity:1.5"
- xjc "com.sun.xml:com.springsource.com.sun.tools.xjc:2.1.7"
- xmlbeans "org.apache.xmlbeans:com.springsource.org.apache.xmlbeans:2.4.0"
+ xjc "com.sun.xml.bind:jaxb-xjc:2.1.7"
+ xmlbeans "org.apache.xmlbeans:xmlbeans:2.4.0"
jibx "org.jibx:jibx-bind:1.2.3"
jibx "bcel:bcel:5.1"
} | true |
Other | spring-projects | spring-framework | c892b8185270daec50f84fcf4cefd88e74b8e195.json | Exclude spring-build-src from maven publish | build.gradle | @@ -111,7 +111,7 @@ configure(allprojects.findAll{it.name in ["spring", "spring-jms", "spring-orm",
}
}
-configure(subprojects) { subproject ->
+configure(subprojects - project(":spring-build-src")) { subproject ->
apply plugin: "merge"
apply from: "${gradleScriptDir}/publish-maven.gradle"
| false |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | build.gradle | @@ -111,7 +111,7 @@ configure(allprojects.findAll{it.name in ["spring", "spring-jms", "spring-orm",
}
}
-configure(subprojects - project(":spring-build-junit")) { subproject ->
+configure(subprojects) { subproject ->
apply plugin: "merge"
apply from: "${gradleScriptDir}/publish-maven.gradle"
@@ -160,15 +160,11 @@ configure(subprojects - project(":spring-build-junit")) { subproject ->
}
}
-configure(allprojects - project(":spring-build-junit")) {
+configure(allprojects) {
dependencies {
- testCompile(project(":spring-build-junit"))
- }
-
- eclipse.classpath.file.whenMerged { classpath ->
- classpath.entries.find{it.path == "/spring-build-junit"}.exported = false
+ testCompile("junit:junit:${junitVersion}")
+ testCompile("org.hamcrest:hamcrest-all:1.3")
}
-
test.systemProperties.put("testGroups", properties.get("testGroups"))
}
@@ -184,23 +180,6 @@ project("spring-build-src") {
configurations.archives.artifacts.clear()
}
-project("spring-build-junit") {
- description = "Build-time JUnit dependencies and utilities"
-
- // NOTE: This is an internal project and is not published.
-
- dependencies {
- compile("commons-logging:commons-logging:1.1.1")
- compile("junit:junit:${junitVersion}")
- compile("org.hamcrest:hamcrest-all:1.3")
- compile("org.easymock:easymock:${easymockVersion}")
- }
-
- // Don't actually generate any artifacts
- configurations.archives.artifacts.clear()
-}
-
-
project("spring-core") {
description = "Spring Core"
@@ -549,7 +528,6 @@ project("spring-orm") {
testCompile("org.eclipse.persistence:org.eclipse.persistence.asm:1.0.1")
testCompile("org.eclipse.persistence:org.eclipse.persistence.antlr:1.0.1")
testCompile("hsqldb:hsqldb:${hsqldbVersion}")
- testCompile(project(":spring-web").sourceSets.test.output)
compile(project(":spring-core"))
compile(project(":spring-beans"))
optional(project(":spring-aop"))
@@ -799,6 +777,7 @@ configure(rootProject) {
dependencies { // for integration tests
testCompile(project(":spring-core"))
+ testCompile(project(":spring-core").sourceSets.test.output)
testCompile(project(":spring-beans"))
testCompile(project(":spring-aop"))
testCompile(project(":spring-expression")) | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | settings.gradle | @@ -22,7 +22,6 @@ include "spring-web"
include "spring-webmvc"
include "spring-webmvc-portlet"
include "spring-webmvc-tiles3"
-include "spring-build-junit"
// Exposes gradle buildSrc for IDE support
include "buildSrc" | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-aop/src/test/java/org/springframework/aop/target/dynamic/RefreshableTargetSourceTests.java | @@ -19,8 +19,8 @@
import static org.junit.Assert.*;
import org.junit.Test;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
/**
* @author Rob Harrop | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java | @@ -49,8 +49,8 @@
import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.support.DerivedFromProtectedBaseBean;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService; | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java | @@ -72,8 +72,8 @@
import org.springframework.beans.factory.xml.ConstructorDependenciesBean;
import org.springframework.beans.factory.xml.DependenciesBean;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService; | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-context-support/src/test/java/org/springframework/scheduling/quartz/QuartzSupportTests.java | @@ -56,8 +56,8 @@
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.io.FileSystemResourceLoader; | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java | @@ -51,8 +51,8 @@
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext; | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-context/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java | @@ -31,8 +31,8 @@
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.StopWatch;
| true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-context/src/test/java/org/springframework/context/expression/ApplicationContextExpressionTests.java | @@ -38,8 +38,8 @@
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.SerializationTestUtils; | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java | @@ -22,8 +22,8 @@
import org.junit.Before;
import org.junit.Test;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java | @@ -35,8 +35,6 @@
import org.junit.Test;
-import org.springframework.build.junit.Assume;
-import org.springframework.build.junit.TestGroup;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
@@ -46,6 +44,8 @@
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.Resource;
+import org.springframework.tests.Assume;
+import org.springframework.tests.TestGroup;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
| true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-core/src/test/java/org/springframework/tests/Assume.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.build.junit;
+package org.springframework.tests;
import static org.junit.Assume.assumeFalse;
@@ -24,8 +24,9 @@
import org.junit.internal.AssumptionViolatedException;
/**
- * Provides utility methods that allow JUnit tests to {@link Assume} certain conditions
- * hold {@code true}. If the assumption fails, it means the test should be skipped.
+ * Provides utility methods that allow JUnit tests to {@link org.junit.Assume} certain
+ * conditions hold {@code true}. If the assumption fails, it means the test should be
+ * skipped.
*
* <p>For example, if a set of tests require at least JDK 1.7 it can use
* {@code Assume#atLeast(JdkVersion.JAVA_17)} as shown below: | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-core/src/test/java/org/springframework/tests/JavaVersion.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.build.junit;
+package org.springframework.tests;
/**
* Enumeration of known JDK versions. | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-core/src/test/java/org/springframework/tests/JavaVersionTests.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.build.junit;
+package org.springframework.tests;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
@@ -26,7 +26,7 @@
*
* @author Phillip Webb
*/
-public class JavaVersionTest {
+public class JavaVersionTests {
@Test
public void runningVersion() { | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-core/src/test/java/org/springframework/tests/Matchers.java | @@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.build.test.hamcrest;
+package org.springframework.tests;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description; | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-core/src/test/java/org/springframework/tests/MockitoUtils.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.build.test.mockito;
+package org.springframework.tests;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is; | true |
Other | spring-projects | spring-framework | 65fb26f847a2249792fa8024c04980fc7a49cd5c.json | Move spring-build-junit into spring-core
Move code from spring-build-junit into spring-core/src/test along with
several other test utility classes. This commit removes the temporary
spring-build-junit project introduced in commit
b083bbdec720d3f5b1c7f065dfe8ccb7a7f3b201. | spring-core/src/test/java/org/springframework/tests/TestGroup.java | @@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.build.junit;
+package org.springframework.tests;
import java.util.Collections;
import java.util.EnumSet; | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.