From 608096032573febc11896e6113993c4703e1cf37 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 14 Jun 2011 17:24:30 +0000 Subject: [PATCH] fix junit BrowseActionTest git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1135711 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/action/AbstractActionTestCase.java | 28 +++++----- .../archiva/web/action/BrowseActionTest.java | 52 +++++++++---------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java index 8c6934ee6..c5c2da070 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java @@ -19,11 +19,6 @@ package org.apache.maven.archiva.web.action; * under the License. */ -import java.io.File; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationManager; @@ -41,10 +36,14 @@ import org.apache.archiva.metadata.model.Scm; import org.apache.archiva.metadata.repository.memory.TestMetadataResolver; import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent; -import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositoriesStub; import org.apache.struts2.StrutsSpringTestCase; +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public abstract class AbstractActionTestCase extends StrutsSpringTestCase { @@ -95,12 +94,10 @@ public abstract class AbstractActionTestCase protected static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection"; protected static final String TEST_SCM_URL = "scmUrl"; - + protected static final String TEST_GENERIC_METADATA_PROPERTY_NAME = "rating"; - - protected static final String TEST_GENERIC_METADATA_PROPERTY_VALUE = "5 stars"; - UserRepositoriesStub repos = new UserRepositoriesStub(); + protected static final String TEST_GENERIC_METADATA_PROPERTY_VALUE = "5 stars"; @Override protected String[] getContextLocations() @@ -111,6 +108,7 @@ public abstract class AbstractActionTestCase protected void setObservableRepos( List repoIds ) { //(UserRepositoriesStub) lookup( UserRepositories.class ); + UserRepositoriesStub repos = applicationContext.getBean( "userRepositories#test", UserRepositoriesStub.class ); repos.setObservableRepositoryIds( repoIds ); } @@ -199,13 +197,13 @@ public abstract class AbstractActionTestCase parent.setVersion( TEST_PARENT_VERSION ); mavenProjectFacet.setParent( parent ); model.addFacet( mavenProjectFacet ); - + GenericMetadataFacet genericMetadataFacet = new GenericMetadataFacet(); - Map props = new HashMap(); - props.put( TEST_GENERIC_METADATA_PROPERTY_NAME, TEST_GENERIC_METADATA_PROPERTY_VALUE ); + Map props = new HashMap(); + props.put( TEST_GENERIC_METADATA_PROPERTY_NAME, TEST_GENERIC_METADATA_PROPERTY_VALUE ); genericMetadataFacet.setAdditionalProperties( props ); model.addFacet( genericMetadataFacet ); - + return model; } @@ -227,7 +225,7 @@ public abstract class AbstractActionTestCase public static String getBasedir() { - String basedir = System.getProperty( "basedir" ); + String basedir = System.getProperty( "basedir" ); if ( basedir == null ) { basedir = new File( "" ).getAbsolutePath(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java index 3008a68f1..394d04e77 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java @@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.action; import com.opensymphony.xwork2.Action; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.memory.TestMetadataResolver; import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory; @@ -40,14 +39,15 @@ public class BrowseActionTest private BrowseAction action; - private static final List GROUPS = Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", - "com.sun", "com.oracle", "repeat.repeat" ); + private static final List GROUPS = + Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", "com.sun", "com.oracle", + "repeat.repeat" ); private static final String OTHER_TEST_REPO = "other-repo"; public void testInstantiation() { - assertFalse( action == (BrowseAction) getActionProxy( "browse.action" ).getAction() ); + assertFalse( action == (BrowseAction) getActionProxy( "/browse.action" ).getAction() ); } public void testBrowse() @@ -286,14 +286,14 @@ public class BrowseActionTest String selectedArtifactId = "apache"; List versions = Arrays.asList( "1", "2", "3", "4" ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "1" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "2" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "3" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "4" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "1" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "2" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "3" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "4" ) ); action.setGroupId( selectedGroupId ); action.setArtifactId( selectedArtifactId ); @@ -320,18 +320,18 @@ public class BrowseActionTest String selectedArtifactId = "apache"; List versions = Arrays.asList( "1", "2", "3", "4-SNAPSHOT", "4", "5-SNAPSHOT" ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "1" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "2" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "3" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "4-SNAPSHOT" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "4" ) ); - metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, createProjectModel( - selectedGroupId, selectedArtifactId, "5-SNAPSHOT" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "1" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "2" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "3" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "4-SNAPSHOT" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "4" ) ); + metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId, + createProjectModel( selectedGroupId, selectedArtifactId, "5-SNAPSHOT" ) ); action.setGroupId( selectedGroupId ); action.setArtifactId( selectedArtifactId ); @@ -395,8 +395,8 @@ public class BrowseActionTest metadataResolver = new TestMetadataResolver(); RepositorySession repositorySession = mock( RepositorySession.class ); when( repositorySession.getResolver() ).thenReturn( metadataResolver ); - TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class ); - //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); + TestRepositorySessionFactory factory = + applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class ); factory.setRepositorySession( repositorySession ); } } \ No newline at end of file -- 2.39.5