]> 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:27 +0000 (12:16 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 11 Jun 2011 12:16:27 +0000 (12:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1134581 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/pom.xml
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractWebworkTestCase.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/AddProxyConnectorActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/tags/DependencyTreeTest.java

index 8c42cfc91f0846aea18c2e91f7ac23fc1bc83fd9..a98f18d0203618f2c637517e2171638eee1e0e62 100644 (file)
       <artifactId>mockito-all</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.struts</groupId>
+      <artifactId>struts2-junit-plugin</artifactId>
+      <scope>test</scope>
+      <version>${struts.version}</version>
+    </dependency>
   </dependencies>
   <build>
     <resources>
index 12f9698358b39ec4bd318de9a2fc4f89ec6e5958..d4115e7cd33e708ff97903e8ebaf1e523a1b1433 100644 (file)
@@ -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<String> repoIds )
     {
-        UserRepositoriesStub repos = (UserRepositoriesStub) lookup( UserRepositories.class );
+        //(UserRepositoriesStub) lookup( UserRepositories.class );
         repos.setObservableRepositoryIds( repoIds );
     }
 
index 9d4eb3782535aed280b2d8a4eb687f43072d38f6..3a38d11ec0806677410de16fbb86e9c45289ff2d 100644 (file)
@@ -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.
index 3b46ee8cf54ca52f6e5158be95a73399e4e65837..4e0da510ece80c83ab053414d99b90aedba17433 100644 (file)
@@ -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
index cc7d51889d31f500e596dd0b61702673389ed207..879e4a4d2e540e18989fb1b23f31d72cb35251a8 100644 (file)
@@ -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 );
-    }
 }
index 7bd440e30039abb979db5480912decf50f257232..1024673c4380c37aeabc296ab6be57ccc5cb8dbd 100644 (file)
@@ -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 );
index 92027dacaa4eb1fced9c149b88f416de647327e5..46bbd8a97bf1d98d4fc5b0d49f1b50eb2d78323a 100644 (file)
@@ -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";
index 5c005d688e931c76bed47aad9235e0772dbe2a06..2283ab63a9b3429765d97f9dc71f28fb856fdee7 100644 (file)
@@ -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 );
     }