Introduce MockEnvironment in the spring-test module
For legacy reasons, a MockEnvironment implementation already exists in multiple places within Spring's test suite; however, it is not available to the general public. This commit promotes MockEnvironment to a first-class citizen in the spring-test module, alongside the existing MockPropertySource. In addition, the following house cleaning has been performed. - deleted MockPropertySource from the spring-expression module - deleted MockEnvironment from the "spring" integration testing module - updated test copies of MockPropertySource and MockEnvironment - documented MockEnvironment and MockPropertySource in the testing chapter of the reference manual Issue: SPR-9492
This commit is contained in:
46
src/dist/changelog.txt
vendored
46
src/dist/changelog.txt
vendored
@@ -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)
|
||||
|
||||
@@ -47,6 +47,22 @@
|
||||
<section xml:id="mock-objects">
|
||||
<title>Mock Objects</title>
|
||||
|
||||
<section xml:id="mock-objects-env">
|
||||
<title>Environment</title>
|
||||
|
||||
<para>The <literal>org.springframework.mock.env</literal> package
|
||||
contains mock implementations of the
|
||||
<interfacename>Environment</interfacename> and
|
||||
<interfacename>PropertySource</interfacename> abstractions introduced
|
||||
in Spring 3.1 (see <xref
|
||||
linkend="new-in-3.1-environment-abstraction" /> and <xref
|
||||
linkend="new-in-3.1-property-source-abstraction" />).
|
||||
<classname>MockEnvironment</classname> and
|
||||
<classname>MockPropertySource</classname> are useful for developing
|
||||
<emphasis>out-of-container</emphasis> unit tests for code that depends
|
||||
on environment-specific properties.</para>
|
||||
</section>
|
||||
|
||||
<section xml:id="mock-objects-jndi">
|
||||
<title>JNDI</title>
|
||||
|
||||
|
||||
@@ -1,60 +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 org.springframework.core.env.AbstractEnvironment;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
/**
|
||||
* Simple {@link ConfigurableEnvironment} implementation exposing a
|
||||
* {@link #setProperty(String, String)} and {@link #withProperty(String, String)}
|
||||
* methods for testing purposes.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
* @see MockPropertySource
|
||||
*/
|
||||
public class MockEnvironment extends AbstractEnvironment {
|
||||
|
||||
private MockPropertySource propertySource = new MockPropertySource();
|
||||
|
||||
/**
|
||||
* Create a new {@code MockEnvironment} with a single {@link MockPropertySource}.
|
||||
*/
|
||||
public MockEnvironment() {
|
||||
getPropertySources().addLast(propertySource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property on the underlying {@link MockPropertySource} for this environment.
|
||||
*/
|
||||
public void setProperty(String key, String value) {
|
||||
propertySource.setProperty(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient synonym for {@link #setProperty} that returns the current instance.
|
||||
* Useful for method chaining and fluent-style use.
|
||||
* @return this {@link MockEnvironment} instance
|
||||
* @see MockPropertySource#withProperty(String, String)
|
||||
*/
|
||||
public MockEnvironment withProperty(String key, String value) {
|
||||
this.setProperty(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user