mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Merge pull request #645 from atlassian/WW-5265-remove-container-provider
WW-5265 Allow removal of a single/specific container provider
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
|
||||
@@ -70,81 +73,94 @@ public class ConfigurationManagerTest extends XWorkTestCase {
|
||||
}
|
||||
|
||||
public void testDestroyConfiguration() throws Exception {
|
||||
class State {
|
||||
public boolean isDestroyed1 =false;
|
||||
public boolean isDestroyed2 =false;
|
||||
}
|
||||
|
||||
final State state = new State();
|
||||
ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
|
||||
configurationManager.addContainerProvider(new ConfigurationProvider() {
|
||||
public void destroy() {
|
||||
throw new RuntimeException("testing testing 123");
|
||||
}
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
public boolean needsReload() { return false;
|
||||
}
|
||||
public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
|
||||
}
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
}
|
||||
});
|
||||
configurationManager.addContainerProvider(new ConfigurationProvider() {
|
||||
public void destroy() {
|
||||
state.isDestroyed1 = true;
|
||||
}
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
public boolean needsReload() { return false;
|
||||
}
|
||||
public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
|
||||
}
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
}
|
||||
});
|
||||
configurationManager.addContainerProvider(new ConfigurationProvider() {
|
||||
public void destroy() {
|
||||
throw new RuntimeException("testing testing 123");
|
||||
}
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
public boolean needsReload() { return false;
|
||||
}
|
||||
public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
|
||||
}
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
}
|
||||
});
|
||||
configurationManager.addContainerProvider(new ConfigurationProvider() {
|
||||
public void destroy() {
|
||||
state.isDestroyed2 = true;
|
||||
}
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
public boolean needsReload() { return false;
|
||||
}
|
||||
public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
|
||||
}
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
}
|
||||
});
|
||||
|
||||
assertFalse(state.isDestroyed1);
|
||||
assertFalse(state.isDestroyed2);
|
||||
|
||||
configurationManager.clearContainerProviders();
|
||||
|
||||
assertTrue(state.isDestroyed1);
|
||||
assertTrue(state.isDestroyed2);
|
||||
class State {
|
||||
public boolean isDestroyed1 =false;
|
||||
public boolean isDestroyed2 =false;
|
||||
}
|
||||
|
||||
final State state = new State();
|
||||
ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
|
||||
configurationManager.addContainerProvider(new ConfigurationProvider() {
|
||||
public void destroy() {
|
||||
throw new RuntimeException("testing testing 123");
|
||||
}
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
public boolean needsReload() { return false;
|
||||
}
|
||||
public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
|
||||
}
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
}
|
||||
});
|
||||
configurationManager.addContainerProvider(new ConfigurationProvider() {
|
||||
public void destroy() {
|
||||
state.isDestroyed1 = true;
|
||||
}
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
public boolean needsReload() { return false;
|
||||
}
|
||||
public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
|
||||
}
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
}
|
||||
});
|
||||
configurationManager.addContainerProvider(new ConfigurationProvider() {
|
||||
public void destroy() {
|
||||
throw new RuntimeException("testing testing 123");
|
||||
}
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
public boolean needsReload() { return false;
|
||||
}
|
||||
public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
|
||||
}
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
}
|
||||
});
|
||||
configurationManager.addContainerProvider(new ConfigurationProvider() {
|
||||
public void destroy() {
|
||||
state.isDestroyed2 = true;
|
||||
}
|
||||
public void init(Configuration configuration) throws ConfigurationException {
|
||||
}
|
||||
public void loadPackages() throws ConfigurationException {
|
||||
}
|
||||
public boolean needsReload() { return false;
|
||||
}
|
||||
public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
|
||||
}
|
||||
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
|
||||
}
|
||||
});
|
||||
|
||||
assertFalse(state.isDestroyed1);
|
||||
assertFalse(state.isDestroyed2);
|
||||
|
||||
configurationManager.clearContainerProviders();
|
||||
|
||||
assertTrue(state.isDestroyed1);
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user