From: Olivier Lamy Date: Sat, 11 Jun 2011 12:16:27 +0000 (+0000) Subject: fix some test compilation issues in webapp module : will fix unit later, must compile... X-Git-Tag: archiva-1.4-M1~678 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90eed343397cef8d8c29cdfd66bb13e863d53259;p=archiva.git 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@1134581 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp/pom.xml b/archiva-modules/archiva-web/archiva-webapp/pom.xml index 8c42cfc91..a98f18d02 100644 --- a/archiva-modules/archiva-web/archiva-webapp/pom.xml +++ b/archiva-modules/archiva-web/archiva-webapp/pom.xml @@ -353,6 +353,12 @@ mockito-all test + + org.apache.struts + struts2-junit-plugin + test + ${struts.version} + 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 12f969835..d4115e7cd 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 @@ -42,10 +42,10 @@ 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.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.apache.struts2.StrutsSpringTestCase; public abstract class AbstractActionTestCase - extends PlexusInSpringTestCase + extends StrutsSpringTestCase { protected static final String TEST_REPO = "test-repo"; @@ -98,10 +98,18 @@ public abstract class AbstractActionTestCase 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(); + + @Override + protected String[] getContextLocations() + { + return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" }; + } + protected void setObservableRepos( List repoIds ) { - UserRepositoriesStub repos = (UserRepositoriesStub) lookup( UserRepositories.class ); + //(UserRepositoriesStub) lookup( UserRepositories.class ); repos.setObservableRepositoryIds( repoIds ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractWebworkTestCase.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractWebworkTestCase.java index 9d4eb3782..3a38d11ec 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractWebworkTestCase.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractWebworkTestCase.java @@ -21,7 +21,7 @@ package org.apache.maven.archiva.web.action; import com.opensymphony.xwork2.ActionSupport; import org.apache.commons.lang.StringUtils; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.apache.struts2.StrutsSpringTestCase; import java.lang.reflect.Method; import java.util.Collection; @@ -33,8 +33,16 @@ import java.util.List; * @version $Id$ */ public abstract class AbstractWebworkTestCase - extends PlexusInSpringTestCase + extends StrutsSpringTestCase { + + + @Override + protected String[] getContextLocations() + { + return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" }; + } + /** * This is a conveinence method for mimicking how the webwork interceptors * operate on an action, before the request is processed. 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 3b46ee8cf..4e0da510e 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 @@ -47,7 +47,7 @@ public class BrowseActionTest public void testInstantiation() { - assertFalse( action == lookup( Action.class, ACTION_HINT ) ); + assertFalse( action == (BrowseAction) getActionProxy( "browse" ).getAction() ); } public void testBrowse() @@ -390,11 +390,13 @@ public class BrowseActionTest throws Exception { super.setUp(); - action = (BrowseAction) lookup( Action.class, ACTION_HINT ); + //action = (BrowseAction) lookup( Action.class, ACTION_HINT ); + action = (BrowseAction) getActionProxy( "browse" ).getAction(); metadataResolver = new TestMetadataResolver(); RepositorySession repositorySession = mock( RepositorySession.class ); when( repositorySession.getResolver() ).thenReturn( metadataResolver ); - TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); + TestRepositorySessionFactory factory = applicationContext.getBean( TestRepositorySessionFactory.class ); + //TestRepositorySessionFactory factory = (TestRepositorySessionFactory) lookup( RepositorySessionFactory.class ); factory.setRepositorySession( repositorySession ); } } \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java index cc7d51889..879e4a4d2 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java @@ -54,6 +54,20 @@ public class AddProxyConnectorActionTest private ArchivaConfiguration archivaConfiguration; + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + action = (AddProxyConnectorAction) getActionProxy( "addProxyConnector" ).getAction(); + //action = (AddProxyConnectorAction) lookup( Action.class.getName(), "addProxyConnectorAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + } + public void testAddBlackListPattern() throws Exception { @@ -403,16 +417,5 @@ public class AddProxyConnectorActionTest policies.put( "propagate-errors-on-update", new PropagateErrorsOnUpdateDownloadPolicy().getDefaultOption() ); } - @Override - protected void setUp() - throws Exception - { - super.setUp(); - action = (AddProxyConnectorAction) lookup( Action.class.getName(), "addProxyConnectorAction" ); - - 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/SortRepositoriesActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesActionTest.java index 7bd440e30..1024673c4 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesActionTest.java @@ -22,9 +22,9 @@ package org.apache.maven.archiva.web.action.admin.repositories; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.apache.struts2.StrutsSpringTestCase; 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 com.opensymphony.xwork2.Action; @@ -35,7 +35,7 @@ import com.opensymphony.xwork2.Action; * @version */ public class SortRepositoriesActionTest - extends PlexusInSpringTestCase + extends StrutsSpringTestCase { private static final String REPO_GROUP_ID = "repo-group-ident"; @@ -50,14 +50,21 @@ public class SortRepositoriesActionTest private ArchivaConfiguration archivaConfiguration; private SortRepositoriesAction action; - + + @Override + protected String[] getContextLocations() + { + return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" }; + } + protected void setUp() throws Exception { super.setUp(); - action = (SortRepositoriesAction) lookup( Action.class.getName(), "sortRepositoriesAction" ); - + //action = (SortRepositoriesAction) lookup( Action.class.getName(), "sortRepositoriesAction" ); + + action = (SortRepositoriesAction) getActionProxy( "sortDownRepositoryFromGroup" ).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/rss/RssFeedServletTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java index 92027daca..46bbd8a97 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java @@ -25,15 +25,16 @@ import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.WebResponse; import com.meterware.servletunit.ServletRunner; import com.meterware.servletunit.ServletUnitClient; +import junit.framework.TestCase; import org.apache.commons.codec.Encoder; import org.apache.commons.codec.binary.Base64; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; import sun.misc.BASE64Encoder; import javax.servlet.http.HttpServletResponse; +import java.io.File; public class RssFeedServletTest - extends PlexusInSpringTestCase + extends TestCase { private ServletRunner sr; @@ -42,7 +43,7 @@ public class RssFeedServletTest public void setUp() throws Exception { - sr = new ServletRunner( getTestFile( "src/test/webapp/WEB-INF/feedServletTest-web.xml" ) ); + sr = new ServletRunner( new File( "src/test/webapp/WEB-INF/feedServletTest-web.xml" ) ); client = sr.newClient(); } @@ -165,7 +166,7 @@ public class RssFeedServletTest } } - @Override + //Override protected String getPlexusConfigLocation() { return "org/apache/maven/archiva/web/rss/RssFeedServletTest.xml"; 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 5c005d688..2283ab63a 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 @@ -19,10 +19,16 @@ package org.apache.maven.archiva.web.tags; * under the License. */ +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.config.ConfigurationManager; +import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider; +import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.util.ValueStack; +import com.opensymphony.xwork2.util.ValueStackFactory; +import junit.framework.TestCase; +import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.metadata.model.ProjectVersionMetadata; -import org.apache.archiva.metadata.repository.MetadataResolver; 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; import org.apache.maven.archiva.common.ArchivaException; @@ -31,25 +37,32 @@ import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import javax.inject.Inject; import java.util.List; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.config.ConfigurationManager; -import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider; -import com.opensymphony.xwork2.inject.Container; -import com.opensymphony.xwork2.util.ValueStack; -import com.opensymphony.xwork2.util.ValueStackFactory; - +@RunWith( SpringJUnit4ClassRunner.class ) +@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) public class DependencyTreeTest - extends PlexusInSpringTestCase + extends TestCase { + @Inject private DependencyTree tree; + @Inject + private PlexusSisuBridge plexusSisuBridge; + + @Inject + private ApplicationContext applicationContext; + private ArtifactFactory artifactFactory; private static final String TEST_VERSION = "version"; @@ -60,45 +73,53 @@ public class DependencyTreeTest private static final String TEST_ARTIFACT_ID = "artifactId"; + @Override - protected void setUp() + @Before + public void setUp() throws Exception { super.setUp(); - + ConfigurationManager configurationManager = new ConfigurationManager(); - configurationManager.addContainerProvider(new XWorkConfigurationProvider()); + configurationManager.addContainerProvider( new XWorkConfigurationProvider() ); com.opensymphony.xwork2.config.Configuration config = configurationManager.getConfiguration(); Container container = config.getContainer(); - ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack(); - stack.getContext().put(ActionContext.CONTAINER, container); - ActionContext.setContext(new ActionContext(stack.getContext())); - - assertNotNull(ActionContext.getContext()); + ValueStack stack = container.getInstance( ValueStackFactory.class ).createValueStack(); + stack.getContext().put( ActionContext.CONTAINER, container ); + ActionContext.setContext( new ActionContext( stack.getContext() ) ); + + assertNotNull( ActionContext.getContext() ); Configuration configuration = new Configuration(); ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration(); repoConfig.setId( TEST_REPO_ID ); - repoConfig.setLocation( getTestPath( "src/test/repositories/test" ) ); + repoConfig.setLocation( "src/test/repositories/test" ); configuration.addManagedRepository( repoConfig ); - ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); + //ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class ); + ArchivaConfiguration archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class ); archivaConfiguration.save( configuration ); - tree = (DependencyTree) lookup( DependencyTree.class ); + //tree = (DependencyTree) lookup( DependencyTree.class ); + + //artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class ); - artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class ); + artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.class ); - TestMetadataResolver metadataResolver = (TestMetadataResolver) lookup( MetadataResolver.class ); + //TestMetadataResolver metadataResolver = (TestMetadataResolver) lookup( MetadataResolver.class ); + TestMetadataResolver metadataResolver = applicationContext.getBean( TestMetadataResolver.class ); ProjectVersionMetadata metadata = new ProjectVersionMetadata(); metadata.setId( TEST_VERSION ); metadataResolver.setProjectVersion( TEST_REPO_ID, TEST_GROUP_ID, TEST_ARTIFACT_ID, metadata ); RepositorySession repositorySession = mock( RepositorySession.class ); when( repositorySession.getResolver() ).thenReturn( metadataResolver ); - TestRepositorySessionFactory repositorySessionFactory = (TestRepositorySessionFactory) lookup( - RepositorySessionFactory.class ); + //TestRepositorySessionFactory repositorySessionFactory = (TestRepositorySessionFactory) lookup( + // RepositorySessionFactory.class ); + TestRepositorySessionFactory repositorySessionFactory = + applicationContext.getBean( TestRepositorySessionFactory.class ); repositorySessionFactory.setRepositorySession( repositorySession ); }