diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java index 89da37e4e..a08d31d98 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java @@ -215,7 +215,9 @@ public class DeleteProxyConnectorActionTest { 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 ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java index bfb5e915f..8bc988080 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java @@ -432,7 +432,8 @@ public class EditProxyConnectorActionTest { 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 ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java index 0f6422f2b..c0a3f0908 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java @@ -209,8 +209,9 @@ public class EnableProxyConnectorActionTest extends AbstractWebworkTestCase { 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 ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); action.setArchivaConfiguration( archivaConfiguration ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java index 1e24d1b01..3fa9d3eac 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java @@ -23,10 +23,10 @@ import com.opensymphony.xwork2.validator.ActionValidatorManager; import java.io.File; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.apache.struts2.StrutsSpringTestCase; public abstract class AbstractManagedRepositoryActionTest - extends PlexusInSpringTestCase + extends StrutsSpringTestCase { protected static final String EMPTY_STRING = ""; @@ -63,6 +63,12 @@ public abstract class AbstractManagedRepositoryActionTest protected File location; + @Override + protected String[] getContextLocations() + { + return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" }; + } + @Override protected void setUp() throws Exception { diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java index 2b890c499..aa09b0379 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java @@ -19,13 +19,6 @@ package org.apache.maven.archiva.web.action.admin.repositories; * 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 org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -39,8 +32,15 @@ import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionException; 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 * * @version $Id$ */ @@ -68,7 +68,7 @@ public class AddManagedRepositoryActionTest super.setUp(); action = new AddManagedRepositoryAction(); - + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); action.setArchivaConfiguration( archivaConfiguration ); @@ -81,7 +81,7 @@ public class AddManagedRepositoryActionTest registry = (Registry) registryControl.getMock(); action.setRegistry( registry ); - location = getTestFile( "target/test/location" ); + location = new File( "target/test/location" ); } public void testSecureActionBundle() @@ -170,12 +170,12 @@ public class AddManagedRepositoryActionTest archivaConfigurationControl.verify(); registryControl.verify(); } - - + + public void testAddRepositoryExistingLocation() throws Exception { - if( !location.exists() ) + if ( !location.exists() ) { location.mkdirs(); } @@ -190,7 +190,7 @@ public class AddManagedRepositoryActionTest action.prepare(); ManagedRepositoryConfiguration repository = action.getRepository(); populateRepository( repository ); - + assertTrue( location.exists() ); String status = action.commit(); assertEquals( AddManagedRepositoryAction.CONFIRM, status ); @@ -198,18 +198,20 @@ public class AddManagedRepositoryActionTest registryControl.verify(); } - public void testStruts2ValidationFrameworkWithNullInputs() throws Exception + public void testStruts2ValidationFrameworkWithNullInputs() + throws Exception { // prep // 0 is the default value for primitive int; null for objects - ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(null, null, null, null); - action.setRepository(managedRepositoryConfiguration); + ManagedRepositoryConfiguration managedRepositoryConfiguration = + createManagedRepositoryConfiguration( null, null, null, null ); + action.setRepository( managedRepositoryConfiguration ); // test - actionValidatorManager.validate(action, EMPTY_STRING); + actionValidatorManager.validate( action, EMPTY_STRING ); // verify - assertTrue(action.hasFieldErrors()); + assertTrue( action.hasFieldErrors() ); Map> fieldErrors = action.getFieldErrors(); @@ -218,32 +220,34 @@ public class AddManagedRepositoryActionTest // populate List expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a repository identifier."); - expectedFieldErrors.put("repository.id", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a repository identifier." ); + expectedFieldErrors.put( "repository.id", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a directory."); - expectedFieldErrors.put("repository.location", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a directory." ); + expectedFieldErrors.put( "repository.location", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a repository name."); - expectedFieldErrors.put("repository.name", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a repository name." ); + expectedFieldErrors.put( "repository.name", expectedErrorMessages ); - ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); + ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors ); } - public void testStruts2ValidationFrameworkWithBlankInputs() throws Exception + public void testStruts2ValidationFrameworkWithBlankInputs() + throws Exception { // prep // 0 is the default value for primitive int - ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING); - action.setRepository(managedRepositoryConfiguration); + ManagedRepositoryConfiguration managedRepositoryConfiguration = + createManagedRepositoryConfiguration( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING ); + action.setRepository( managedRepositoryConfiguration ); // test - actionValidatorManager.validate(action, EMPTY_STRING); + actionValidatorManager.validate( action, EMPTY_STRING ); // verify - assertTrue(action.hasFieldErrors()); + assertTrue( action.hasFieldErrors() ); Map> fieldErrors = action.getFieldErrors(); @@ -252,31 +256,36 @@ public class AddManagedRepositoryActionTest // populate List expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a repository identifier."); - expectedFieldErrors.put("repository.id", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a repository identifier." ); + expectedFieldErrors.put( "repository.id", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a directory."); - expectedFieldErrors.put("repository.location", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a directory." ); + expectedFieldErrors.put( "repository.location", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a repository name."); - expectedFieldErrors.put("repository.name", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a repository name." ); + expectedFieldErrors.put( "repository.name", expectedErrorMessages ); - ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); + ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors ); } - public void testStruts2ValidationFrameworkWithInvalidInputs() throws Exception + public void testStruts2ValidationFrameworkWithInvalidInputs() + throws Exception { // 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); - action.setRepository(managedRepositoryConfiguration); + 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 ); + action.setRepository( managedRepositoryConfiguration ); // test - actionValidatorManager.validate(action, EMPTY_STRING); + actionValidatorManager.validate( action, EMPTY_STRING ); // verify - assertTrue(action.hasFieldErrors()); + assertTrue( action.hasFieldErrors() ); Map> fieldErrors = action.getFieldErrors(); @@ -285,45 +294,53 @@ public class AddManagedRepositoryActionTest // populate List expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)."); - expectedFieldErrors.put("repository.id", expectedErrorMessages); + expectedErrorMessages.add( + "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." ); + expectedFieldErrors.put( "repository.id", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("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.add( + "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(); - expectedErrorMessages.add("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.add( + "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(); - 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(-)."); - expectedFieldErrors.put("repository.indexDir", expectedErrorMessages); + 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(-)." ); + expectedFieldErrors.put( "repository.indexDir", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("Repository Purge By Retention Count needs to be between 1 and 100."); - expectedFieldErrors.put("repository.retentionCount", expectedErrorMessages); + expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." ); + expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("Repository Purge By Days Older Than needs to be larger than 0."); - expectedFieldErrors.put("repository.daysOlder", expectedErrorMessages); + expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." ); + expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages ); - ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); + ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors ); } - public void testStruts2ValidationFrameworkWithValidInputs() throws Exception + public void testStruts2ValidationFrameworkWithValidInputs() + throws Exception { // 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); - action.setRepository(managedRepositoryConfiguration); + 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 ); + action.setRepository( managedRepositoryConfiguration ); // test - actionValidatorManager.validate(action, EMPTY_STRING); + actionValidatorManager.validate( action, EMPTY_STRING ); // verify - assertFalse(action.hasFieldErrors()); + assertFalse( action.hasFieldErrors() ); } - // TODO: test errors during add, other actions } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java index 07e91b84d..ea795ad75 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java @@ -26,7 +26,6 @@ import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.web.action.AbstractActionTestCase; import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionException; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; import java.util.Collections; @@ -52,7 +51,8 @@ public class AddRemoteRepositoryActionTest { 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 ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index 6e813e38b..b19570724 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -24,7 +24,6 @@ import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditListener; import org.apache.archiva.metadata.repository.MetadataRepository; 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.stats.RepositoryStatisticsManager; 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.RoleManagerException; 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.SecureActionException; import org.easymock.MockControl; @@ -90,6 +88,7 @@ public class DeleteManagedRepositoryActionTest { super.setUp(); + // TODO use getAction .?? action = new DeleteManagedRepositoryAction(); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); @@ -99,7 +98,7 @@ public class DeleteManagedRepositoryActionTest roleManagerControl = MockControl.createControl( RoleManager.class ); roleManager = (RoleManager) roleManagerControl.getMock(); action.setRoleManager( roleManager ); - location = getTestFile( "target/test/location" ); + location = new File( "target/test/location" ); repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class ); repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock(); @@ -111,7 +110,8 @@ public class DeleteManagedRepositoryActionTest respositorySession = mock( RepositorySession.class ); when( respositorySession.getRepository() ).thenReturn( metadataRepository ); - TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); + //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); + TestRepositorySessionFactory factory = new TestRepositorySessionFactory(); factory.setRepositorySession( respositorySession ); action.setRepositorySessionFactory( factory ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java index 30a5b01ed..1bcc749d3 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.action.admin.repositories; import com.opensymphony.xwork2.Action; import org.apache.archiva.metadata.repository.MetadataRepository; 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.stats.RepositoryStatisticsManager; 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.ManagedRepositoryConfiguration; 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.codehaus.plexus.redback.role.RoleManager; 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.SecureActionException; import org.easymock.MockControl; @@ -71,7 +68,7 @@ public class EditManagedRepositoryActionTest private Registry registry; private MockControl registryControl; - + private MetadataRepository metadataRepository; @Override @@ -94,12 +91,13 @@ public class EditManagedRepositoryActionTest registry = (Registry) registryControl.getMock(); action.setRegistry( registry ); - location = getTestFile( "target/test/location" ); + location = new File( "target/test/location" ); metadataRepository = mock( MetadataRepository.class ); RepositorySession repositorySession = mock( RepositorySession.class ); 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 ); action.setRepositorySessionFactory( factory ); } @@ -279,7 +277,7 @@ public class EditManagedRepositoryActionTest ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration(); populateRepository( repository ); - File testFile = getTestFile( "target/test/location/new" ); + File testFile = new File( "target/test/location/new" ); FileUtils.deleteDirectory( testFile ); repository.setLocation( "${appserver.base}/location/new" ); action.setRepository( repository ); @@ -294,18 +292,20 @@ public class EditManagedRepositoryActionTest registryControl.verify(); } - public void testStruts2ValidationFrameworkWithNullInputs() throws Exception + public void testStruts2ValidationFrameworkWithNullInputs() + throws Exception { // prep // 0 is the default value for primitive int; null for objects - ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(null, null, null, null); - action.setRepository(managedRepositoryConfiguration); + ManagedRepositoryConfiguration managedRepositoryConfiguration = + createManagedRepositoryConfiguration( null, null, null, null ); + action.setRepository( managedRepositoryConfiguration ); // test - actionValidatorManager.validate(action, EMPTY_STRING); + actionValidatorManager.validate( action, EMPTY_STRING ); // verify - assertTrue(action.hasFieldErrors()); + assertTrue( action.hasFieldErrors() ); Map> fieldErrors = action.getFieldErrors(); @@ -314,32 +314,34 @@ public class EditManagedRepositoryActionTest // populate List expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a repository identifier."); - expectedFieldErrors.put("repository.id", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a repository identifier." ); + expectedFieldErrors.put( "repository.id", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a directory."); - expectedFieldErrors.put("repository.location", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a directory." ); + expectedFieldErrors.put( "repository.location", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a repository name."); - expectedFieldErrors.put("repository.name", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a repository name." ); + expectedFieldErrors.put( "repository.name", expectedErrorMessages ); - ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); + ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors ); } - public void testStruts2ValidationFrameworkWithBlankInputs() throws Exception + public void testStruts2ValidationFrameworkWithBlankInputs() + throws Exception { // prep // 0 is the default value for primitive int - ManagedRepositoryConfiguration managedRepositoryConfiguration = createManagedRepositoryConfiguration(EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING); - action.setRepository(managedRepositoryConfiguration); + ManagedRepositoryConfiguration managedRepositoryConfiguration = + createManagedRepositoryConfiguration( EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING ); + action.setRepository( managedRepositoryConfiguration ); // test - actionValidatorManager.validate(action, EMPTY_STRING); + actionValidatorManager.validate( action, EMPTY_STRING ); // verify - assertTrue(action.hasFieldErrors()); + assertTrue( action.hasFieldErrors() ); Map> fieldErrors = action.getFieldErrors(); @@ -348,31 +350,36 @@ public class EditManagedRepositoryActionTest // populate List expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a repository identifier."); - expectedFieldErrors.put("repository.id", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a repository identifier." ); + expectedFieldErrors.put( "repository.id", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a directory."); - expectedFieldErrors.put("repository.location", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a directory." ); + expectedFieldErrors.put( "repository.location", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("You must enter a repository name."); - expectedFieldErrors.put("repository.name", expectedErrorMessages); + expectedErrorMessages.add( "You must enter a repository name." ); + expectedFieldErrors.put( "repository.name", expectedErrorMessages ); - ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); + ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors ); } - public void testStruts2ValidationFrameworkWithInvalidInputs() throws Exception + public void testStruts2ValidationFrameworkWithInvalidInputs() + throws Exception { // 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); - action.setRepository(managedRepositoryConfiguration); + 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 ); + action.setRepository( managedRepositoryConfiguration ); // test - actionValidatorManager.validate(action, EMPTY_STRING); + actionValidatorManager.validate( action, EMPTY_STRING ); // verify - assertTrue(action.hasFieldErrors()); + assertTrue( action.hasFieldErrors() ); Map> fieldErrors = action.getFieldErrors(); @@ -381,43 +388,52 @@ public class EditManagedRepositoryActionTest // populate List expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)."); - expectedFieldErrors.put("repository.id", expectedErrorMessages); + expectedErrorMessages.add( + "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." ); + expectedFieldErrors.put( "repository.id", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("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.add( + "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(); - expectedErrorMessages.add("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.add( + "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(); - 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(-)."); - expectedFieldErrors.put("repository.indexDir", expectedErrorMessages); + 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(-)." ); + expectedFieldErrors.put( "repository.indexDir", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("Repository Purge By Retention Count needs to be between 1 and 100."); - expectedFieldErrors.put("repository.retentionCount", expectedErrorMessages); + expectedErrorMessages.add( "Repository Purge By Retention Count needs to be between 1 and 100." ); + expectedFieldErrors.put( "repository.retentionCount", expectedErrorMessages ); expectedErrorMessages = new ArrayList(); - expectedErrorMessages.add("Repository Purge By Days Older Than needs to be larger than 0."); - expectedFieldErrors.put("repository.daysOlder", expectedErrorMessages); + expectedErrorMessages.add( "Repository Purge By Days Older Than needs to be larger than 0." ); + expectedFieldErrors.put( "repository.daysOlder", expectedErrorMessages ); - ValidatorUtil.assertFieldErrors(expectedFieldErrors, fieldErrors); + ValidatorUtil.assertFieldErrors( expectedFieldErrors, fieldErrors ); } - public void testStruts2ValidationFrameworkWithValidInputs() throws Exception + public void testStruts2ValidationFrameworkWithValidInputs() + throws Exception { // 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); - action.setRepository(managedRepositoryConfiguration); + 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 ); + action.setRepository( managedRepositoryConfiguration ); // test - actionValidatorManager.validate(action, EMPTY_STRING); + actionValidatorManager.validate( action, EMPTY_STRING ); // verify - assertFalse(action.hasFieldErrors()); + assertFalse( action.hasFieldErrors() ); } private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository, diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java index f8e2f0b33..54a4932a2 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java @@ -24,10 +24,9 @@ import com.meterware.servletunit.ServletUnitClient; import com.opensymphony.xwork2.Action; import org.apache.archiva.metadata.repository.MetadataRepository; 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.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.SecureActionException; import org.easymock.MockControl; @@ -41,7 +40,7 @@ import static org.mockito.Mockito.when; * Test the repositories action returns the correct data. */ public class RepositoriesActionTest - extends PlexusInSpringTestCase + extends StrutsSpringTestCase { private RepositoriesAction action; @@ -50,16 +49,15 @@ public class RepositoriesActionTest { super.setUp(); - try - { - action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" ); - } - catch ( Exception e ) - { - // clean up cache - TODO: move handling to plexus-spring - applicationContext.close(); - throw e; - } + //action = (RepositoriesAction) lookup( Action.class.getName(), "repositoriesAction" ); + action = (RepositoriesAction) getActionProxy( "/admin/index" ).getAction(); + + } + + @Override + protected String[] getContextLocations() + { + return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" }; } public void testGetRepositories() @@ -81,7 +79,8 @@ public class RepositoriesActionTest RepositorySession session = mock( RepositorySession.class ); when( session.getRepository() ).thenReturn( metadataRepository ); - TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); + //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); + TestRepositorySessionFactory factory = new TestRepositorySessionFactory(); factory.setRepositorySession( session ); ServletRunner sr = new ServletRunner(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/tags/DependencyTreeTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/tags/DependencyTreeTest.java index 2283ab63a..8f8bdaae0 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/tags/DependencyTreeTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/tags/DependencyTreeTest.java @@ -38,6 +38,7 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; @@ -123,6 +124,7 @@ public class DependencyTreeTest repositorySessionFactory.setRepositorySession( repositorySession ); } + @Test public void testTree() throws ArchivaException {