Browse Source
SPR-11145 claims that ServletContextAware beans declared in an ApplicationContext loaded for an integration test by the TestContext framework (TCF) do not have their setServletContext() methods invoked if the tests are executed manually using JUnit 4.11. This commit verifies that such ServletContextAware beans are processed properly regardless of how the test was launched. Specifically: - A ServletContextAwareBean has been introduced. - BasicAnnotationConfigWacTests has been retrofitted with a ServletContextAwareBean in its context. - ServletContextAwareBeanWacTests has been introduced to execute BasicAnnotationConfigWacTests manually via JUnitCore. Issue: SPR-11145pull/455/head
3 changed files with 104 additions and 3 deletions
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2002-2014 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.test.context.web; |
||||
|
||||
import javax.servlet.ServletContext; |
||||
|
||||
import org.springframework.web.context.ServletContextAware; |
||||
|
||||
/** |
||||
* Introduced to investigate claims in SPR-11145. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 4.0.2 |
||||
*/ |
||||
public class ServletContextAwareBean implements ServletContextAware { |
||||
|
||||
protected ServletContext servletContext; |
||||
|
||||
@Override |
||||
public void setServletContext(ServletContext servletContext) { |
||||
this.servletContext = servletContext; |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
/* |
||||
* Copyright 2002-2014 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.test.context.web; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.JUnitCore; |
||||
import org.springframework.test.context.junit4.TrackingRunListener; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
/** |
||||
* Introduced to investigate claims in SPR-11145. |
||||
* |
||||
* <p> |
||||
* Yes, this test class does in fact use JUnit to run JUnit. ;) |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 4.0.2 |
||||
*/ |
||||
public class ServletContextAwareBeanWacTests { |
||||
|
||||
@Test |
||||
public void ensureServletContextAwareBeanIsProcessedProperlyWhenExecutingJUnitManually() { |
||||
TrackingRunListener listener = new TrackingRunListener(); |
||||
JUnitCore junit = new JUnitCore(); |
||||
junit.addListener(listener); |
||||
|
||||
junit.run(BasicAnnotationConfigWacTests.class); |
||||
|
||||
assertEquals(3, listener.getTestStartedCount()); |
||||
assertEquals(3, listener.getTestFinishedCount()); |
||||
assertEquals(0, listener.getTestFailureCount()); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue