]> source.dussan.org Git - archiva.git/commitdiff
fix some test compilation issues in webapp module : will fix unit later, must compile...
authorOlivier Lamy <olamy@apache.org>
Sat, 11 Jun 2011 12:16:55 +0000 (12:16 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 11 Jun 2011 12:16:55 +0000 (12:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1134582 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/DeleteProxyConnectorActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EditProxyConnectorActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/EnableProxyConnectorActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoriesActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/tags/DependencyTreeTest.java

index 89da37e4ef3f905c68c4e78da1b2f149bb1bfdcd..a08d31d9874a900b6dfec416c55ab508d9058944 100644 (file)
@@ -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();
index bfb5e915f41af05a1da1ddf6dd793350c0b998b5..8bc9880804ee909abfbe7d144c6b0af1e0412bb0 100644 (file)
@@ -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();
index 0f6422f2b6310b9d75cfcfd1966abd1025c829c2..c0a3f09081a9d249bd59b8d39672e7fde033a1d8 100644 (file)
@@ -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 );
index 1e24d1b01db993d4ad3e2671f5b3b904c5a05a6e..3fa9d3eaca66ae317332d84aab9a1ecdc4fde5de 100644 (file)
@@ -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
     {
index 2b890c499af32a83f8fb60282bca01e4f1e5c46b..aa09b0379460cd056f56f98bac00688978fee3f4 100644 (file)
@@ -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<String, List<String>> fieldErrors = action.getFieldErrors();
 
@@ -218,32 +220,34 @@ public class AddManagedRepositoryActionTest
 
         // populate
         List<String> expectedErrorMessages = new ArrayList<String>();
-        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<String>();
-        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<String>();
-        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<String, List<String>> fieldErrors = action.getFieldErrors();
 
@@ -252,31 +256,36 @@ public class AddManagedRepositoryActionTest
 
         // populate
         List<String> expectedErrorMessages = new ArrayList<String>();
-        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<String>();
-        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<String>();
-        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<String, List<String>> fieldErrors = action.getFieldErrors();
 
@@ -285,45 +294,53 @@ public class AddManagedRepositoryActionTest
 
         // populate
         List<String> expectedErrorMessages = new ArrayList<String>();
-        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<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(-).");
-        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<String>();
-        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<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(-).");
-        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<String>();
-        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<String>();
-        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
 }
index 07e91b84df96d71b45b05657cdb40b03daba829f..ea795ad75ff52aa00a6e2bda2c3951da9272b4f8 100644 (file)
@@ -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();
index 6e813e38bb9ce9b0a8ba78c7152613a665fa0493..b195707241e6d179a2e3c90fdfc812e74db87de4 100644 (file)
@@ -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 );
 
index 30a5b01edda9c30db687ee7dcf8d3c3d69b69d3d..1bcc749d380098172506318a4876ace95a5ba969 100644 (file)
@@ -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<String, List<String>> fieldErrors = action.getFieldErrors();
 
@@ -314,32 +314,34 @@ public class EditManagedRepositoryActionTest
 
         // populate
         List<String> expectedErrorMessages = new ArrayList<String>();
-        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<String>();
-        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<String>();
-        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<String, List<String>> fieldErrors = action.getFieldErrors();
 
@@ -348,31 +350,36 @@ public class EditManagedRepositoryActionTest
 
         // populate
         List<String> expectedErrorMessages = new ArrayList<String>();
-        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<String>();
-        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<String>();
-        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<String, List<String>> fieldErrors = action.getFieldErrors();
 
@@ -381,43 +388,52 @@ public class EditManagedRepositoryActionTest
 
         // populate
         List<String> expectedErrorMessages = new ArrayList<String>();
-        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<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(-).");
-        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<String>();
-        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<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(-).");
-        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<String>();
-        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<String>();
-        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,
index f8e2f0b33ef0b01f76030451df0ef6e0d9318423..54a4932a2ed399f9f1c9f0aba1c5f3c5bcdcf4fa 100644 (file)
@@ -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();
index 2283ab63a9b3429765d97f9dc71f28fb856fdee7..8f8bdaae0125f987fabc0b4ef425519e9c5fbfd1 100644 (file)
@@ -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
     {