Skip to content

Commit

Permalink
WW-5265 Allow removal of a single/specific container provider from St…
Browse files Browse the repository at this point in the history
…ruts configuration
  • Loading branch information
kusalk committed Dec 13, 2022
1 parent b795a92 commit 45aa172
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public synchronized void setConfiguration(Configuration configuration) {
* </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
Expand Down Expand Up @@ -137,6 +137,13 @@ public void addContainerProvider(ContainerProvider provider) {
}
}

public void removeContainerProvider(ContainerProvider provider) {
if (containerProviders.remove(provider)) {
clearContainerProvider(provider);
providersChanged = true;
}
}

public void clearContainerProviders() {
for (ContainerProvider containerProvider : containerProviders) {
clearContainerProvider(containerProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

import java.util.Properties;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;


/**
* ConfigurationManagerTest
Expand Down Expand Up @@ -147,6 +150,19 @@ public void register(ContainerBuilder builder, LocatableProperties props) throws
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();
Expand Down

0 comments on commit 45aa172

Please sign in to comment.