mirror of https://github.com/apache/archiva.git
[MRM-451] correct regression in the change listener handling of the default configuration
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@562681 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5391c0e0de
commit
498d33c645
|
@ -33,6 +33,8 @@ import org.codehaus.plexus.util.StringUtils;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of configuration holder that retrieves it from the registry.
|
* Implementation of configuration holder that retrieves it from the registry.
|
||||||
|
@ -77,9 +79,14 @@ public class DefaultArchivaConfiguration
|
||||||
*/
|
*/
|
||||||
private String userConfigFilename;
|
private String userConfigFilename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listeners we've registered.
|
||||||
|
*/
|
||||||
|
private List listeners = new LinkedList();
|
||||||
|
|
||||||
public String getFilteredUserConfigFilename()
|
public String getFilteredUserConfigFilename()
|
||||||
{
|
{
|
||||||
return StringUtils.replace( userConfigFilename, "${user.home}", System.getProperty( "user.home" + "" ) );
|
return StringUtils.replace( userConfigFilename, "${user.home}", System.getProperty( "user.home" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Configuration getConfiguration()
|
public synchronized Configuration getConfiguration()
|
||||||
|
@ -176,6 +183,13 @@ public class DefaultArchivaConfiguration
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
( (Initializable) registry ).initialize();
|
( (Initializable) registry ).initialize();
|
||||||
|
|
||||||
|
for ( Iterator i = listeners.iterator(); i.hasNext(); )
|
||||||
|
{
|
||||||
|
RegistryListener l = (RegistryListener) i.next();
|
||||||
|
|
||||||
|
addRegistryChangeListener( l );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( InitializationException e )
|
catch ( InitializationException e )
|
||||||
{
|
{
|
||||||
|
@ -186,6 +200,14 @@ public class DefaultArchivaConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addChangeListener( RegistryListener listener )
|
public void addChangeListener( RegistryListener listener )
|
||||||
|
{
|
||||||
|
addRegistryChangeListener( listener );
|
||||||
|
|
||||||
|
// keep track for later
|
||||||
|
listeners.add( listener );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addRegistryChangeListener( RegistryListener listener )
|
||||||
{
|
{
|
||||||
Registry section = registry.getSection( KEY + ".user" );
|
Registry section = registry.getSection( KEY + ".user" );
|
||||||
if ( section != null )
|
if ( section != null )
|
||||||
|
|
|
@ -20,7 +20,11 @@ package org.apache.maven.archiva.configuration;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.codehaus.plexus.registry.Registry;
|
||||||
|
import org.codehaus.plexus.registry.RegistryListener;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
import org.easymock.AbstractMatcher;
|
||||||
|
import org.easymock.MockControl;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -33,6 +37,16 @@ import java.util.List;
|
||||||
public class ArchivaConfigurationTest
|
public class ArchivaConfigurationTest
|
||||||
extends PlexusTestCase
|
extends PlexusTestCase
|
||||||
{
|
{
|
||||||
|
private Registry registry;
|
||||||
|
|
||||||
|
protected void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
registry = (Registry) lookup( Registry.ROLE, "commons-configuration" );
|
||||||
|
}
|
||||||
|
|
||||||
public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
|
public void testGetConfigurationFromRegistryWithASingleNamedConfigurationResource()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -162,8 +176,8 @@ public class ArchivaConfigurationTest
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
FileUtils.fileWrite( file.getAbsolutePath(), "<configuration/>" );
|
FileUtils.fileWrite( file.getAbsolutePath(), "<configuration/>" );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration =
|
DefaultArchivaConfiguration archivaConfiguration =
|
||||||
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" );
|
(DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save" );
|
||||||
|
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
configuration.setVersion( "1" );
|
configuration.setVersion( "1" );
|
||||||
|
@ -171,8 +185,23 @@ public class ArchivaConfigurationTest
|
||||||
configuration.getWebapp().setUi( new UserInterfaceOptions() );
|
configuration.getWebapp().setUi( new UserInterfaceOptions() );
|
||||||
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
||||||
|
|
||||||
|
// add a change listener
|
||||||
|
MockControl control = createRegistryListenerMockControl();
|
||||||
|
RegistryListener listener = (RegistryListener) control.getMock();
|
||||||
|
archivaConfiguration.addChangeListener( listener );
|
||||||
|
|
||||||
|
listener.beforeConfigurationChange( registry, "version", "1" );
|
||||||
|
listener.beforeConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
|
||||||
|
|
||||||
|
listener.afterConfigurationChange( registry, "version", "1" );
|
||||||
|
listener.afterConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
|
||||||
|
|
||||||
|
control.replay();
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
|
control.verify();
|
||||||
|
|
||||||
assertTrue( "Check file exists", file.exists() );
|
assertTrue( "Check file exists", file.exists() );
|
||||||
|
|
||||||
// check it
|
// check it
|
||||||
|
@ -180,11 +209,30 @@ public class ArchivaConfigurationTest
|
||||||
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
|
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
|
||||||
|
|
||||||
// read it back
|
// read it back
|
||||||
archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
|
archivaConfiguration =
|
||||||
|
(DefaultArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
|
||||||
configuration = archivaConfiguration.getConfiguration();
|
configuration = archivaConfiguration.getConfiguration();
|
||||||
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
|
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MockControl createRegistryListenerMockControl()
|
||||||
|
{
|
||||||
|
MockControl control = MockControl.createControl( RegistryListener.class );
|
||||||
|
control.setDefaultMatcher( new AbstractMatcher()
|
||||||
|
{
|
||||||
|
protected boolean argumentMatches( Object object, Object object1 )
|
||||||
|
{
|
||||||
|
return object instanceof Registry || super.argumentMatches( object, object1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String argumentToString( Object object )
|
||||||
|
{
|
||||||
|
return object instanceof Registry ? "<any>" : super.argumentToString( object );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
return control;
|
||||||
|
}
|
||||||
|
|
||||||
public void testStoreConfigurationUser()
|
public void testStoreConfigurationUser()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -236,8 +284,20 @@ public class ArchivaConfigurationTest
|
||||||
configuration.getWebapp().setUi( new UserInterfaceOptions() );
|
configuration.getWebapp().setUi( new UserInterfaceOptions() );
|
||||||
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
||||||
|
|
||||||
|
// add a change listener
|
||||||
|
MockControl control = createRegistryListenerMockControl();
|
||||||
|
RegistryListener listener = (RegistryListener) control.getMock();
|
||||||
|
archivaConfiguration.addChangeListener( listener );
|
||||||
|
|
||||||
|
listener.beforeConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
|
||||||
|
listener.afterConfigurationChange( registry, "webapp.ui.appletFindEnabled", Boolean.FALSE );
|
||||||
|
|
||||||
|
control.replay();
|
||||||
|
|
||||||
archivaConfiguration.save( configuration );
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
|
control.verify();
|
||||||
|
|
||||||
assertTrue( "Check file exists", userFile.exists() );
|
assertTrue( "Check file exists", userFile.exists() );
|
||||||
assertFalse( "Check file not created", baseFile.exists() );
|
assertFalse( "Check file not created", baseFile.exists() );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue