mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-5265 Allow removal of a single/specific container provider from Struts configuration
This commit is contained in:
@@ -90,7 +90,7 @@ public class ConfigurationManager {
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* TODO: The lazy instantiation of XmlConfigurationProvider should be refactored to be elsewhere. The behavior described above seems unintuitive.
|
||||
* TODO: The lazy instantiation of StrutsDefaultConfigurationProvider should be refactored to be elsewhere. The behavior described above seems unintuitive.
|
||||
* </p>
|
||||
*
|
||||
* @return the list of registered ConfigurationProvider objects
|
||||
@@ -137,6 +137,13 @@ public class ConfigurationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeContainerProvider(ContainerProvider provider) {
|
||||
if (containerProviders.remove(provider)) {
|
||||
clearContainerProvider(provider);
|
||||
providersChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearContainerProviders() {
|
||||
for (ContainerProvider containerProvider : containerProviders) {
|
||||
clearContainerProvider(containerProvider);
|
||||
|
||||
@@ -30,6 +30,9 @@ import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
|
||||
/**
|
||||
* ConfigurationManagerTest
|
||||
@@ -147,6 +150,19 @@ public class ConfigurationManagerTest extends XWorkTestCase {
|
||||
assertTrue(state.isDestroyed2);
|
||||
}
|
||||
|
||||
public void testRemoveConfigurationProvider() throws Exception {
|
||||
ConfigurationProvider configProvider1 = mock(ConfigurationProvider.class);
|
||||
ConfigurationProvider configProvider2 = mock(ConfigurationProvider.class);
|
||||
configurationManager.addContainerProvider(configProvider1);
|
||||
configurationManager.addContainerProvider(configProvider2);
|
||||
|
||||
configurationManager.removeContainerProvider(configProvider1);
|
||||
|
||||
verify(configProvider1).destroy();
|
||||
assertFalse(configurationManager.getContainerProviders().contains(configProvider1));
|
||||
assertTrue(configurationManager.getContainerProviders().contains(configProvider2));
|
||||
}
|
||||
|
||||
public void testClearConfigurationProviders() throws Exception {
|
||||
configProviderMock.expect("destroy");
|
||||
configurationManager.clearContainerProviders();
|
||||
|
||||
Reference in New Issue
Block a user