diff --git a/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java b/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java index 0ad1a200c6..9759c99c55 100644 --- a/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java +++ b/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.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. @@ -20,13 +20,14 @@ import org.springframework.core.env.AbstractEnvironment; import org.springframework.core.env.ConfigurableEnvironment; /** - * Simple {@link ConfigurableEnvironment} implementation exposing a + * Simple {@link ConfigurableEnvironment} implementation exposing * {@link #setProperty(String, String)} and {@link #withProperty(String, String)} * methods for testing purposes. * * @author Chris Beams - * @since 3.1 - * @see MockPropertySource + * @author Sam Brannen + * @since 3.2 + * @see org.springframework.mock.env.MockPropertySource */ public class MockEnvironment extends AbstractEnvironment { diff --git a/spring-context/src/test/java/org/springframework/mock/env/MockPropertySource.java b/spring-context/src/test/java/org/springframework/mock/env/MockPropertySource.java index a6f5c6009f..2783f244b1 100644 --- a/spring-context/src/test/java/org/springframework/mock/env/MockPropertySource.java +++ b/spring-context/src/test/java/org/springframework/mock/env/MockPropertySource.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. @@ -36,7 +36,7 @@ import org.springframework.core.env.PropertySource; * * @author Chris Beams * @since 3.1 - * @see MockEnvironment + * @see org.springframework.mock.env.MockEnvironment */ public class MockPropertySource extends PropertiesPropertySource { @@ -75,7 +75,7 @@ public class MockPropertySource extends PropertiesPropertySource { } /** - * Create a new {@code MockPropertySource} with with the given name and backed by the given + * Create a new {@code MockPropertySource} with the given name and backed by the given * {@link Properties} object * @param name the {@linkplain #getName() name} of the property source * @param properties the properties to use @@ -100,4 +100,5 @@ public class MockPropertySource extends PropertiesPropertySource { this.setProperty(name, value); return this; } + } diff --git a/spring-core/src/test/java/org/springframework/mock/env/MockPropertySource.java b/spring-core/src/test/java/org/springframework/mock/env/MockPropertySource.java index a6f5c6009f..2783f244b1 100644 --- a/spring-core/src/test/java/org/springframework/mock/env/MockPropertySource.java +++ b/spring-core/src/test/java/org/springframework/mock/env/MockPropertySource.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. @@ -36,7 +36,7 @@ import org.springframework.core.env.PropertySource; * * @author Chris Beams * @since 3.1 - * @see MockEnvironment + * @see org.springframework.mock.env.MockEnvironment */ public class MockPropertySource extends PropertiesPropertySource { @@ -75,7 +75,7 @@ public class MockPropertySource extends PropertiesPropertySource { } /** - * Create a new {@code MockPropertySource} with with the given name and backed by the given + * Create a new {@code MockPropertySource} with the given name and backed by the given * {@link Properties} object * @param name the {@linkplain #getName() name} of the property source * @param properties the properties to use @@ -100,4 +100,5 @@ public class MockPropertySource extends PropertiesPropertySource { this.setProperty(name, value); return this; } + } diff --git a/spring-expression/src/test/java/org/springframework/mock/env/MockPropertySource.java b/spring-expression/src/test/java/org/springframework/mock/env/MockPropertySource.java deleted file mode 100644 index 157ee58c3c..0000000000 --- a/spring-expression/src/test/java/org/springframework/mock/env/MockPropertySource.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2002-2011 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.mock.env; - -import java.util.Properties; - -import org.springframework.core.env.PropertiesPropertySource; -import org.springframework.core.env.PropertySource; - -/** - * Simple {@link PropertySource} implementation for use in testing. Accepts - * a user-provided {@link Properties} object, or if omitted during construction, - * the implementation will initialize its own. - * - * The {@link #setProperty} and {@link #withProperty} methods are exposed for - * convenience, for example: - *
- * {@code
- *   PropertySource source = new MockPropertySource().withProperty("foo", "bar");
- * }
- * 
- * - * @author Chris Beams - * @since 3.1 - */ -public class MockPropertySource extends PropertiesPropertySource { - - /** - * {@value} is the default name for {@link MockPropertySource} instances not - * otherwise given an explicit name. - * @see #MockPropertySource() - * @see #MockPropertySource(String) - */ - public static final String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME = "mockProperties"; - - /** - * Create a new {@code MockPropertySource} named {@value #MOCK_PROPERTIES_PROPERTY_SOURCE_NAME} - * that will maintain its own internal {@link Properties} instance. - */ - public MockPropertySource() { - this(new Properties()); - } - - /** - * Create a new {@code MockPropertySource} with the given name that will - * maintain its own internal {@link Properties} instance. - * @param name the {@linkplain #getName() name} of the property source - */ - public MockPropertySource(String name) { - this(name, new Properties()); - } - - /** - * Create a new {@code MockPropertySource} named {@value #MOCK_PROPERTIES_PROPERTY_SOURCE_NAME} - * and backed by the given {@link Properties} object. - * @param properties the properties to use - */ - public MockPropertySource(Properties properties) { - this(MOCK_PROPERTIES_PROPERTY_SOURCE_NAME, properties); - } - - /** - * Create a new {@code MockPropertySource} with with the given name and backed by the given - * {@link Properties} object - * @param name the {@linkplain #getName() name} of the property source - * @param properties the properties to use - */ - public MockPropertySource(String name, Properties properties) { - super(name, properties); - } - - /** - * Set the given property on the underlying {@link Properties} object. - */ - public void setProperty(String name, Object value) { - this.source.put(name, value); - } - - /** - * Convenient synonym for {@link #setProperty} that returns the current instance. - * Useful for method chaining and fluent-style use. - * @return this {@link MockPropertySource} instance - */ - public MockPropertySource withProperty(String name, Object value) { - this.setProperty(name, value); - return this; - } -} diff --git a/src/test/java/org/springframework/mock/env/MockEnvironment.java b/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java similarity index 92% rename from src/test/java/org/springframework/mock/env/MockEnvironment.java rename to spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java index 0ad1a200c6..9759c99c55 100644 --- a/src/test/java/org/springframework/mock/env/MockEnvironment.java +++ b/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.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. @@ -20,13 +20,14 @@ import org.springframework.core.env.AbstractEnvironment; import org.springframework.core.env.ConfigurableEnvironment; /** - * Simple {@link ConfigurableEnvironment} implementation exposing a + * Simple {@link ConfigurableEnvironment} implementation exposing * {@link #setProperty(String, String)} and {@link #withProperty(String, String)} * methods for testing purposes. * * @author Chris Beams - * @since 3.1 - * @see MockPropertySource + * @author Sam Brannen + * @since 3.2 + * @see org.springframework.mock.env.MockPropertySource */ public class MockEnvironment extends AbstractEnvironment { diff --git a/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java b/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java index f4d4a834fc..124637e9c6 100644 --- a/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java +++ b/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.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. @@ -36,7 +36,7 @@ import org.springframework.core.env.PropertySource; * * @author Chris Beams * @since 3.1 - * @see MockEnvironment + * @see org.springframework.mock.env.MockEnvironment */ public class MockPropertySource extends PropertiesPropertySource { @@ -75,8 +75,8 @@ public class MockPropertySource extends PropertiesPropertySource { } /** - * Create a new {@code MockPropertySource} with with the given name and backed by the given - * {@link Properties} object + * Create a new {@code MockPropertySource} with the given name and backed by the given + * {@link Properties} object. * @param name the {@linkplain #getName() name} of the property source * @param properties the properties to use */ @@ -100,4 +100,5 @@ public class MockPropertySource extends PropertiesPropertySource { this.setProperty(name, value); return this; } + } diff --git a/spring-test/src/main/java/org/springframework/mock/env/package-info.java b/spring-test/src/main/java/org/springframework/mock/env/package-info.java new file mode 100644 index 0000000000..6be96f5baf --- /dev/null +++ b/spring-test/src/main/java/org/springframework/mock/env/package-info.java @@ -0,0 +1,10 @@ +/** + * This package contains mock implementations of the + * {@link org.springframework.core.env.Environment Environment} and + * {@link org.springframework.core.env.PropertySource PropertySource} + * abstractions introduced in Spring 3.1. + * + *

These mocks are useful for developing out-of-container + * unit tests for code that depends on environment-specific properties. + */ +package org.springframework.mock.env; diff --git a/src/dist/changelog.txt b/src/dist/changelog.txt index 485b040f9f..72e54544b3 100644 --- a/src/dist/changelog.txt +++ b/src/dist/changelog.txt @@ -7,29 +7,29 @@ Changes in version 3.2 M2 (2012-08-xx) -------------------------------------- * spring-test module now depends on junit:junit-dep (SPR-6966) -* infer return type of parameterized factory methods (SPR-9493) -* used BufferedInputStream in SimpleMetaDataReader to double performance (SPR-9528) -* added "repeatCount" bean property to Quartz SimpleTriggerFactoryBean (SPR-9521) -* added "jtaTransactionManager" property to Hibernate 4 LocalSessionFactoryBean/Builder (SPR-9480) -* raise RestClientException instead of IllegalArgumentException for unknown status codes -* added "defaultCharset" property to StringHttpMessageConverter (SPR-9487) -* added JacksonObjectMapperFactoryBean for configuring a Jackson ObjectMapper in XML -* added ContentNegotiationManager/ContentNegotiationStrategy to resolve requested media types -* 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 -* move RSS/Atom message converter registration ahead of jackson/jaxb2 -* handle BindException in DefaultHandlerExceptionResolver -* 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 -* support content negotiation options in MVC namespace and MVC Java config -* support named dispatchers in MockServletContext (SPR-9587) -* support single, unqualified tx manager in the TestContext framework (SPR-9645) -* support TransactionManagementConfigurer in the TestContext framework (SPR-9604) +* now inferring return type of parameterized factory methods (SPR-9493) +* now using BufferedInputStream in SimpleMetaDataReader to double performance (SPR-9528) +* introduced "repeatCount" property in Quartz SimpleTriggerFactoryBean (SPR-9521) +* introduced "jtaTransactionManager" property in Hibernate 4 LocalSessionFactoryBean/Builder (SPR-9480) +* now raising RestClientException instead of IllegalArgumentException for unknown status codes +* introduced JacksonObjectMapperFactoryBean for configuring a Jackson ObjectMapper in XML +* introduced ContentNegotiationManager/ContentNegotiationStrategy for resolving requested media types +* introduced support for the HTTP PATCH method in Spring MVC and RestTemplate (SPR-7985) +* enabled smart suffix pattern matching in @RequestMapping methods (SPR-7632) +* DispatcherPortlet no longer forwards event exceptions to the render phase by default (SPR-9287) +* introduced "defaultCharset" property in StringHttpMessageConverter (SPR-9487) +* introduced @ExceptionResolver annotation for detecting classes with @ExceptionHandler methods +* moved RSS/Atom message converter registration ahead of jackson/jaxb2 +* now handling BindException in DefaultHandlerExceptionResolver +* DeferredResult type is now parameterized +* now using reflection to instantiate StandardServletAsyncWebRequest +* fixed issue with forward before async request processing +* introduced exclude patterns for mapped interceptors in MVC namespace and MVC Java config +* introduced support for content negotiation options in MVC namespace and MVC Java config +* introduced support for named dispatchers in MockServletContext (SPR-9587) +* introduced support for single, unqualified tx manager in the TestContext framework (SPR-9645) +* introduced support for TransactionManagementConfigurer in the TestContext framework (SPR-9604) +* introduced MockEnvironment in the spring-test module (SPR-9492) Changes in version 3.2 M1 (2012-05-28) diff --git a/src/reference/docbook/testing.xml b/src/reference/docbook/testing.xml index ed0f0499aa..8b81ad19c3 100644 --- a/src/reference/docbook/testing.xml +++ b/src/reference/docbook/testing.xml @@ -47,6 +47,22 @@

Mock Objects +
+ Environment + + The org.springframework.mock.env package + contains mock implementations of the + Environment and + PropertySource abstractions introduced + in Spring 3.1 (see and ). + MockEnvironment and + MockPropertySource are useful for developing + out-of-container unit tests for code that depends + on environment-specific properties. +
+
JNDI