fix some test compilation issues in webapp module : will fix unit later, must compile at least !

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1134582 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-06-11 12:16:55 +00:00
parent 90eed34339
commit 75ac09e5b5
10 changed files with 185 additions and 141 deletions

View File

@ -215,7 +215,9 @@ public class DeleteProxyConnectorActionTest
{ {
super.setUp(); super.setUp();
action = (DeleteProxyConnectorAction) lookup( Action.class.getName(), "deleteProxyConnectorAction" ); //action = (DeleteProxyConnectorAction) lookup( Action.class.getName(), "deleteProxyConnectorAction" );
action = (DeleteProxyConnectorAction) getActionProxy( "/admin/deleteProxyConnector" ).getAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();

View File

@ -432,7 +432,8 @@ public class EditProxyConnectorActionTest
{ {
super.setUp(); super.setUp();
action = (EditProxyConnectorAction) lookup( Action.class.getName(), "editProxyConnectorAction" ); //action = (EditProxyConnectorAction) lookup( Action.class.getName(), "editProxyConnectorAction" );
action = (EditProxyConnectorAction) getActionProxy( "/admin/editProxyConnector" ).getAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();

View File

@ -209,8 +209,9 @@ public class EnableProxyConnectorActionTest extends AbstractWebworkTestCase
{ {
super.setUp(); super.setUp();
action = (EnableProxyConnectorAction) lookup( Action.class.getName(), "enableProxyConnectorAction" ); //action = (EnableProxyConnectorAction) lookup( Action.class.getName(), "enableProxyConnectorAction" );
action = (EnableProxyConnectorAction) getActionProxy( "/admin/enableProxyConnector" ).getAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
action.setArchivaConfiguration( archivaConfiguration ); action.setArchivaConfiguration( archivaConfiguration );

View File

@ -23,10 +23,10 @@ import com.opensymphony.xwork2.validator.ActionValidatorManager;
import java.io.File; import java.io.File;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.apache.struts2.StrutsSpringTestCase;
public abstract class AbstractManagedRepositoryActionTest public abstract class AbstractManagedRepositoryActionTest
extends PlexusInSpringTestCase extends StrutsSpringTestCase
{ {
protected static final String EMPTY_STRING = ""; protected static final String EMPTY_STRING = "";
@ -63,6 +63,12 @@ public abstract class AbstractManagedRepositoryActionTest
protected File location; protected File location;
@Override
protected String[] getContextLocations()
{
return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
}
@Override @Override
protected void setUp() throws Exception protected void setUp() throws Exception
{ {

View File

@ -19,13 +19,6 @@ package org.apache.maven.archiva.web.action.admin.repositories;
* under the License. * under the License.
*/ */
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@ -39,6 +32,13 @@ import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.easymock.MockControl; import org.easymock.MockControl;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* AddManagedRepositoryActionTest * AddManagedRepositoryActionTest
* *
@ -81,7 +81,7 @@ public class AddManagedRepositoryActionTest
registry = (Registry) registryControl.getMock(); registry = (Registry) registryControl.getMock();
action.setRegistry( registry ); action.setRegistry( registry );
location = getTestFile( "target/test/location" ); location = new File( "target/test/location" );
} }
public void testSecureActionBundle() public void testSecureActionBundle()
@ -175,7 +175,7 @@ public class AddManagedRepositoryActionTest
public void testAddRepositoryExistingLocation() public void testAddRepositoryExistingLocation()
throws Exception throws Exception
{ {
if( !location.exists() ) if ( !location.exists() )
{ {
location.mkdirs(); location.mkdirs();
} }
@ -198,18 +198,20 @@ public class AddManagedRepositoryActionTest
registryControl.verify(); registryControl.verify();
} }
public void testStruts2ValidationFrameworkWithNullInputs() throws Exception public void testStruts2ValidationFrameworkWithNullInputs()
throws Exception
{ {
// prep // prep
// 0 is the default value for primitive int; null for objects // 0 is the default value for primitive int; null for objects
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(null, null, null, null); ManagedRepositoryConfiguration managedRepositoryConfiguration =
action.setRepository(managedRepositoryConfiguration); createManagedRepositoryConfiguration( null, null, null, null );
action.setRepository( managedRepositoryConfiguration );
// test // test
actionValidatorManager.validate(action, EMPTY_STRING); actionValidatorManager.validate( action, EMPTY_STRING );
// verify // verify
assertTrue(action.hasFieldErrors()); assertTrue( action.hasFieldErrors() );
Map<String, List<String>> fieldErrors = action.getFieldErrors(); Map<String, List<String>> fieldErrors = action.getFieldErrors();
@ -218,32 +220,34 @@ public class AddManagedRepositoryActionTest
// populate // populate
List<String> expectedErrorMessages = new ArrayList<String>(); List<String> expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a repository identifier."); expectedErrorMessages.add( "You must enter a repository identifier." );
expectedFieldErrors.put("repository.id", expectedErrorMessages); expectedFieldErrors.put( "repository.id", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a directory."); expectedErrorMessages.add( "You must enter a directory." );
expectedFieldErrors.put("repository.location", expectedErrorMessages); expectedFieldErrors.put( "repository.location", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a repository name."); expectedErrorMessages.add( "You must enter a repository name." );
expectedFieldErrors.put("repository.name", expectedErrorMessages); expectedFieldErrors.put( "repository.name", expectedErrorMessages );
ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
} }
public void testStruts2ValidationFrameworkWithBlankInputs() throws Exception public void testStruts2ValidationFrameworkWithBlankInputs()
throws Exception
{ {
// prep // prep
// 0 is the default value for primitive int // 0 is the default value for primitive int
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING); ManagedRepositoryConfiguration managedRepositoryConfiguration =
action.setRepository(managedRepositoryConfiguration); createManagedRepositoryConfiguration( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING );
action.setRepository( managedRepositoryConfiguration );
// test // test
actionValidatorManager.validate(action, EMPTY_STRING); actionValidatorManager.validate( action, EMPTY_STRING );
// verify // verify
assertTrue(action.hasFieldErrors()); assertTrue( action.hasFieldErrors() );
Map<String, List<String>> fieldErrors = action.getFieldErrors(); Map<String, List<String>> fieldErrors = action.getFieldErrors();
@ -252,31 +256,36 @@ public class AddManagedRepositoryActionTest
// populate // populate
List<String> expectedErrorMessages = new ArrayList<String>(); List<String> expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a repository identifier."); expectedErrorMessages.add( "You must enter a repository identifier." );
expectedFieldErrors.put("repository.id", expectedErrorMessages); expectedFieldErrors.put( "repository.id", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a directory."); expectedErrorMessages.add( "You must enter a directory." );
expectedFieldErrors.put("repository.location", expectedErrorMessages); expectedFieldErrors.put( "repository.location", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a repository name."); expectedErrorMessages.add( "You must enter a repository name." );
expectedFieldErrors.put("repository.name", expectedErrorMessages); expectedFieldErrors.put( "repository.name", expectedErrorMessages );
ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
} }
public void testStruts2ValidationFrameworkWithInvalidInputs() throws Exception public void testStruts2ValidationFrameworkWithInvalidInputs()
throws Exception
{ {
// prep // prep
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT, REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT, REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT); ManagedRepositoryConfiguration managedRepositoryConfiguration =
action.setRepository(managedRepositoryConfiguration); createManagedRepositoryConfiguration( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
REPOSITORY_DAYS_OLDER_INVALID_INPUT,
REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
action.setRepository( managedRepositoryConfiguration );
// test // test
actionValidatorManager.validate(action, EMPTY_STRING); actionValidatorManager.validate( action, EMPTY_STRING );
// verify // verify
assertTrue(action.hasFieldErrors()); assertTrue( action.hasFieldErrors() );
Map<String, List<String>> fieldErrors = action.getFieldErrors(); Map<String, List<String>> fieldErrors = action.getFieldErrors();
@ -285,45 +294,53 @@ public class AddManagedRepositoryActionTest
// populate // populate
List<String> expectedErrorMessages = new ArrayList<String>(); List<String> expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)."); expectedErrorMessages.add(
expectedFieldErrors.put("repository.id", expectedErrorMessages); "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
expectedFieldErrors.put( "repository.id", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)."); expectedErrorMessages.add(
expectedFieldErrors.put("repository.location", expectedErrorMessages); "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
expectedFieldErrors.put( "repository.location", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)."); expectedErrorMessages.add(
expectedFieldErrors.put("repository.name", expectedErrorMessages); "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
expectedFieldErrors.put( "repository.name", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)."); expectedErrorMessages.add(
expectedFieldErrors.put("repository.indexDir", expectedErrorMessages); "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
expectedFieldErrors.put( "repository.indexDir", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Repository Purge By Retention Count needs to be between 1 and 100."); expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
expectedFieldErrors.put("repository.retentionCount", expectedErrorMessages); expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Repository Purge By Days Older Than needs to be larger than 0."); expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." );
expectedFieldErrors.put("repository.daysOlder", expectedErrorMessages); expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages );
ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
} }
public void testStruts2ValidationFrameworkWithValidInputs() throws Exception public void testStruts2ValidationFrameworkWithValidInputs()
throws Exception
{ {
// prep // prep
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT, REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT, REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT); ManagedRepositoryConfiguration managedRepositoryConfiguration =
action.setRepository(managedRepositoryConfiguration); createManagedRepositoryConfiguration( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
REPOSITORY_DAYS_OLDER_VALID_INPUT,
REPOSITORY_RETENTION_COUNT_VALID_INPUT );
action.setRepository( managedRepositoryConfiguration );
// test // test
actionValidatorManager.validate(action, EMPTY_STRING); actionValidatorManager.validate( action, EMPTY_STRING );
// verify // verify
assertFalse(action.hasFieldErrors()); assertFalse( action.hasFieldErrors() );
} }
// TODO: test errors during add, other actions // TODO: test errors during add, other actions
} }

View File

@ -26,7 +26,6 @@ import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
import org.apache.maven.archiva.web.action.AbstractActionTestCase; import org.apache.maven.archiva.web.action.AbstractActionTestCase;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl; import org.easymock.MockControl;
import java.util.Collections; import java.util.Collections;
@ -52,7 +51,8 @@ public class AddRemoteRepositoryActionTest
{ {
super.setUp(); super.setUp();
action = (AddRemoteRepositoryAction) lookup( Action.class.getName(), "addRemoteRepositoryAction" ); //action = (AddRemoteRepositoryAction) lookup( Action.class.getName(), "addRemoteRepositoryAction" );
action = (AddRemoteRepositoryAction) getActionProxy( "/admin/addRemoteRepository" ).getAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();

View File

@ -24,7 +24,6 @@ import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener; import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory; import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@ -40,7 +39,6 @@ import org.apache.maven.archiva.web.action.AuditEventArgumentsMatcher;
import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.redback.role.RoleManagerException;
import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.easymock.MockControl; import org.easymock.MockControl;
@ -90,6 +88,7 @@ public class DeleteManagedRepositoryActionTest
{ {
super.setUp(); super.setUp();
// TODO use getAction .??
action = new DeleteManagedRepositoryAction(); action = new DeleteManagedRepositoryAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
@ -99,7 +98,7 @@ public class DeleteManagedRepositoryActionTest
roleManagerControl = MockControl.createControl( RoleManager.class ); roleManagerControl = MockControl.createControl( RoleManager.class );
roleManager = (RoleManager) roleManagerControl.getMock(); roleManager = (RoleManager) roleManagerControl.getMock();
action.setRoleManager( roleManager ); action.setRoleManager( roleManager );
location = getTestFile( "target/test/location" ); location = new File( "target/test/location" );
repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class ); repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock(); repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
@ -111,7 +110,8 @@ public class DeleteManagedRepositoryActionTest
respositorySession = mock( RepositorySession.class ); respositorySession = mock( RepositorySession.class );
when( respositorySession.getRepository() ).thenReturn( metadataRepository ); when( respositorySession.getRepository() ).thenReturn( metadataRepository );
TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class );
TestRepositorySessionFactory factory = new TestRepositorySessionFactory();
factory.setRepositorySession( respositorySession ); factory.setRepositorySession( respositorySession );
action.setRepositorySessionFactory( factory ); action.setRepositorySessionFactory( factory );

View File

@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.action.admin.repositories;
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory; import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -30,11 +29,9 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.maven.archiva.web.action.AbstractActionTestCase;
import org.apache.maven.archiva.web.validator.utils.ValidatorUtil; import org.apache.maven.archiva.web.validator.utils.ValidatorUtil;
import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.easymock.MockControl; import org.easymock.MockControl;
@ -94,12 +91,13 @@ public class EditManagedRepositoryActionTest
registry = (Registry) registryControl.getMock(); registry = (Registry) registryControl.getMock();
action.setRegistry( registry ); action.setRegistry( registry );
location = getTestFile( "target/test/location" ); location = new File( "target/test/location" );
metadataRepository = mock( MetadataRepository.class ); metadataRepository = mock( MetadataRepository.class );
RepositorySession repositorySession = mock( RepositorySession.class ); RepositorySession repositorySession = mock( RepositorySession.class );
when( repositorySession.getRepository() ).thenReturn( metadataRepository ); when( repositorySession.getRepository() ).thenReturn( metadataRepository );
TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class );
TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class );
factory.setRepositorySession( repositorySession ); factory.setRepositorySession( repositorySession );
action.setRepositorySessionFactory( factory ); action.setRepositorySessionFactory( factory );
} }
@ -279,7 +277,7 @@ public class EditManagedRepositoryActionTest
ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration(); ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
populateRepository( repository ); populateRepository( repository );
File testFile = getTestFile( "target/test/location/new" ); File testFile = new File( "target/test/location/new" );
FileUtils.deleteDirectory( testFile ); FileUtils.deleteDirectory( testFile );
repository.setLocation( "${appserver.base}/location/new" ); repository.setLocation( "${appserver.base}/location/new" );
action.setRepository( repository ); action.setRepository( repository );
@ -294,18 +292,20 @@ public class EditManagedRepositoryActionTest
registryControl.verify(); registryControl.verify();
} }
public void testStruts2ValidationFrameworkWithNullInputs() throws Exception public void testStruts2ValidationFrameworkWithNullInputs()
throws Exception
{ {
// prep // prep
// 0 is the default value for primitive int; null for objects // 0 is the default value for primitive int; null for objects
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(null, null, null, null); ManagedRepositoryConfiguration managedRepositoryConfiguration =
action.setRepository(managedRepositoryConfiguration); createManagedRepositoryConfiguration( null, null, null, null );
action.setRepository( managedRepositoryConfiguration );
// test // test
actionValidatorManager.validate(action, EMPTY_STRING); actionValidatorManager.validate( action, EMPTY_STRING );
// verify // verify
assertTrue(action.hasFieldErrors()); assertTrue( action.hasFieldErrors() );
Map<String, List<String>> fieldErrors = action.getFieldErrors(); Map<String, List<String>> fieldErrors = action.getFieldErrors();
@ -314,32 +314,34 @@ public class EditManagedRepositoryActionTest
// populate // populate
List<String> expectedErrorMessages = new ArrayList<String>(); List<String> expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a repository identifier."); expectedErrorMessages.add( "You must enter a repository identifier." );
expectedFieldErrors.put("repository.id", expectedErrorMessages); expectedFieldErrors.put( "repository.id", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a directory."); expectedErrorMessages.add( "You must enter a directory." );
expectedFieldErrors.put("repository.location", expectedErrorMessages); expectedFieldErrors.put( "repository.location", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a repository name."); expectedErrorMessages.add( "You must enter a repository name." );
expectedFieldErrors.put("repository.name", expectedErrorMessages); expectedFieldErrors.put( "repository.name", expectedErrorMessages );
ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
} }
public void testStruts2ValidationFrameworkWithBlankInputs() throws Exception public void testStruts2ValidationFrameworkWithBlankInputs()
throws Exception
{ {
// prep // prep
// 0 is the default value for primitive int // 0 is the default value for primitive int
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING); ManagedRepositoryConfiguration managedRepositoryConfiguration =
action.setRepository(managedRepositoryConfiguration); createManagedRepositoryConfiguration( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING );
action.setRepository( managedRepositoryConfiguration );
// test // test
actionValidatorManager.validate(action, EMPTY_STRING); actionValidatorManager.validate( action, EMPTY_STRING );
// verify // verify
assertTrue(action.hasFieldErrors()); assertTrue( action.hasFieldErrors() );
Map<String, List<String>> fieldErrors = action.getFieldErrors(); Map<String, List<String>> fieldErrors = action.getFieldErrors();
@ -348,31 +350,36 @@ public class EditManagedRepositoryActionTest
// populate // populate
List<String> expectedErrorMessages = new ArrayList<String>(); List<String> expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a repository identifier."); expectedErrorMessages.add( "You must enter a repository identifier." );
expectedFieldErrors.put("repository.id", expectedErrorMessages); expectedFieldErrors.put( "repository.id", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a directory."); expectedErrorMessages.add( "You must enter a directory." );
expectedFieldErrors.put("repository.location", expectedErrorMessages); expectedFieldErrors.put( "repository.location", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("You must enter a repository name."); expectedErrorMessages.add( "You must enter a repository name." );
expectedFieldErrors.put("repository.name", expectedErrorMessages); expectedFieldErrors.put( "repository.name", expectedErrorMessages );
ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
} }
public void testStruts2ValidationFrameworkWithInvalidInputs() throws Exception public void testStruts2ValidationFrameworkWithInvalidInputs()
throws Exception
{ {
// prep // prep
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT, REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT, REPOSITORY_DAYS_OLDER_INVALID_INPUT, REPOSITORY_RETENTION_COUNT_INVALID_INPUT); ManagedRepositoryConfiguration managedRepositoryConfiguration =
action.setRepository(managedRepositoryConfiguration); createManagedRepositoryConfiguration( REPOSITORY_ID_INVALID_INPUT, REPOSITORY_NAME_INVALID_INPUT,
REPOSITORY_LOCATION_INVALID_INPUT, REPOSITORY_INDEX_DIR_INVALID_INPUT,
REPOSITORY_DAYS_OLDER_INVALID_INPUT,
REPOSITORY_RETENTION_COUNT_INVALID_INPUT );
action.setRepository( managedRepositoryConfiguration );
// test // test
actionValidatorManager.validate(action, EMPTY_STRING); actionValidatorManager.validate( action, EMPTY_STRING );
// verify // verify
assertTrue(action.hasFieldErrors()); assertTrue( action.hasFieldErrors() );
Map<String, List<String>> fieldErrors = action.getFieldErrors(); Map<String, List<String>> fieldErrors = action.getFieldErrors();
@ -381,43 +388,52 @@ public class EditManagedRepositoryActionTest
// populate // populate
List<String> expectedErrorMessages = new ArrayList<String>(); List<String> expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)."); expectedErrorMessages.add(
expectedFieldErrors.put("repository.id", expectedErrorMessages); "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
expectedFieldErrors.put( "repository.id", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)."); expectedErrorMessages.add(
expectedFieldErrors.put("repository.location", expectedErrorMessages); "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
expectedFieldErrors.put( "repository.location", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)."); expectedErrorMessages.add(
expectedFieldErrors.put("repository.name", expectedErrorMessages); "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
expectedFieldErrors.put( "repository.name", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)."); expectedErrorMessages.add(
expectedFieldErrors.put("repository.indexDir", expectedErrorMessages); "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
expectedFieldErrors.put( "repository.indexDir", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Repository Purge By Retention Count needs to be between 1 and 100."); expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." );
expectedFieldErrors.put("repository.retentionCount", expectedErrorMessages); expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages );
expectedErrorMessages = new ArrayList<String>(); expectedErrorMessages = new ArrayList<String>();
expectedErrorMessages.add("Repository Purge By Days Older Than needs to be larger than 0."); expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." );
expectedFieldErrors.put("repository.daysOlder", expectedErrorMessages); expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages );
ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors );
} }
public void testStruts2ValidationFrameworkWithValidInputs() throws Exception public void testStruts2ValidationFrameworkWithValidInputs()
throws Exception
{ {
// prep // prep
ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT, REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT, REPOSITORY_DAYS_OLDER_VALID_INPUT, REPOSITORY_RETENTION_COUNT_VALID_INPUT); ManagedRepositoryConfiguration managedRepositoryConfiguration =
action.setRepository(managedRepositoryConfiguration); createManagedRepositoryConfiguration( REPOSITORY_ID_VALID_INPUT, REPOSITORY_NAME_VALID_INPUT,
REPOSITORY_LOCATION_VALID_INPUT, REPOSITORY_INDEX_DIR_VALID_INPUT,
REPOSITORY_DAYS_OLDER_VALID_INPUT,
REPOSITORY_RETENTION_COUNT_VALID_INPUT );
action.setRepository( managedRepositoryConfiguration );
// test // test
actionValidatorManager.validate(action, EMPTY_STRING); actionValidatorManager.validate( action, EMPTY_STRING );
// verify // verify
assertFalse(action.hasFieldErrors()); assertFalse( action.hasFieldErrors() );
} }
private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository, private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository,

View File

@ -24,10 +24,9 @@ import com.meterware.servletunit.ServletUnitClient;
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory; import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
import org.apache.archiva.metadata.repository.stats.RepositoryStatistics; import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.apache.struts2.StrutsSpringTestCase;
import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException; import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.easymock.MockControl; import org.easymock.MockControl;
@ -41,7 +40,7 @@ import static org.mockito.Mockito.when;
* Test the repositories action returns the correct data. * Test the repositories action returns the correct data.
*/ */
public class RepositoriesActionTest public class RepositoriesActionTest
extends PlexusInSpringTestCase extends StrutsSpringTestCase
{ {
private RepositoriesAction action; private RepositoriesAction action;
@ -50,16 +49,15 @@ public class RepositoriesActionTest
{ {
super.setUp(); super.setUp();
try //action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" );
{ action = (RepositoriesAction) getActionProxy( "/admin/index" ).getAction();
action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" );
} }
catch ( Exception e )
{ @Override
// clean up cache - TODO: move handling to plexus-spring protected String[] getContextLocations()
applicationContext.close(); {
throw e; return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
}
} }
public void testGetRepositories() public void testGetRepositories()
@ -81,7 +79,8 @@ public class RepositoriesActionTest
RepositorySession session = mock( RepositorySession.class ); RepositorySession session = mock( RepositorySession.class );
when( session.getRepository() ).thenReturn( metadataRepository ); when( session.getRepository() ).thenReturn( metadataRepository );
TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class );
TestRepositorySessionFactory factory = new TestRepositorySessionFactory();
factory.setRepositorySession( session ); factory.setRepositorySession( session );
ServletRunner sr = new ServletRunner(); ServletRunner sr = new ServletRunner();

View File

@ -38,6 +38,7 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
@ -123,6 +124,7 @@ public class DependencyTreeTest
repositorySessionFactory.setRepositorySession( repositorySession ); repositorySessionFactory.setRepositorySession( repositorySession );
} }
@Test
public void testTree() public void testTree()
throws ArchivaException throws ArchivaException
{ {