X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=testingtools%2Fsrc%2Fmain%2Fjava%2Fde%2Fjuplo%2Ftestingtools%2FWebContextTestExecutionListener.java;fp=testingtools%2Fsrc%2Fmain%2Fjava%2Fde%2Fjuplo%2Ftestingtools%2FWebContextTestExecutionListener.java;h=0000000000000000000000000000000000000000;hb=f95f687755d54c46975b15dbd0221e82a7458f79;hp=9309584161376b79c3ad0a9e3fbde484fc30864f;hpb=4f07e33a7c246caa3e4cd7c939f75064e4af03b0;p=percentcodec diff --git a/testingtools/src/main/java/de/juplo/testingtools/WebContextTestExecutionListener.java b/testingtools/src/main/java/de/juplo/testingtools/WebContextTestExecutionListener.java deleted file mode 100644 index 93095841..00000000 --- a/testingtools/src/main/java/de/juplo/testingtools/WebContextTestExecutionListener.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.juplo.testingtools; - -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.Scope; -import org.springframework.context.support.GenericApplicationContext; -import org.springframework.context.support.SimpleThreadScope; -import org.springframework.test.context.TestContext; -import org.springframework.test.context.support.AbstractTestExecutionListener; - -/** - * Diese Klasse ermöglicht es, Beans mit dem Scope REQUEST in JUnit-Testfällen - * zu verwenden. - *
- * Source: http://stackoverflow.com/questions/2411343/request-scoped-beans-in-spring-testing - *
- * Anwendung:
- *
- * @RunWith(SpringJUnit4ClassRunner.class)
- * @ContextConfiguration(locations = "classpath:spring/TestScopedBeans-context.xml")
- * @TestExecutionListeners({
- * WebContextTestExecutionListener.class,
- * DependencyInjectionTestExecutionListener.class,
- * DirtiesContextTestExecutionListener.class })
- * public class TestScopedBeans {
- * ...
- *
- */
-public class WebContextTestExecutionListener extends AbstractTestExecutionListener {
- @Override
- public void prepareTestInstance(TestContext testContext) throws Exception {
-
- if (testContext.getApplicationContext() instanceof GenericApplicationContext) {
- GenericApplicationContext context = (GenericApplicationContext) testContext.getApplicationContext();
- ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
- Scope requestScope = new SimpleThreadScope();
- beanFactory.registerScope("request", requestScope);
- Scope sessionScope = new SimpleThreadScope();
- beanFactory.registerScope("session", sessionScope);
- }
- }
-}