Support servlet listener activate attribute

Add a ServletTestExecutionListener.ACTIVATE_LISTENER attribute which
can be set on the TestContext to trigger activation of the listener
even if a `@WebAppConfiguration` is not present.

Issue: SPR-14035
This commit is contained in:
Phillip Webb
2016-03-09 23:33:45 -08:00
committed by Sam Brannen
parent 8ca6a18dae
commit bb590db396
2 changed files with 31 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 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.
@@ -173,6 +173,18 @@ public class ServletTestExecutionListenerTests {
assertWebAppConfigTestCase();
}
@Test
public void activateAttributeAppConfigTestCaseWithoutExistingRequestAttributes() throws Exception {
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(NoAtWebAppConfigWebTestCase.class);
given(testContext.getAttribute(ServletTestExecutionListener.ACTIVATE_LISTENER)).willReturn(true);
RequestContextHolder.resetRequestAttributes();
listener.beforeTestClass(testContext);
assertAttributesNotAvailable();
assertWebAppConfigTestCase();
}
private void assertWebAppConfigTestCase() throws Exception {
listener.prepareTestInstance(testContext);
assertAttributeDoesNotExist();
@@ -200,4 +212,7 @@ public class ServletTestExecutionListenerTests {
static class AtWebAppConfigWebTestCase {
}
static class NoAtWebAppConfigWebTestCase {
}
}