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
This commit is contained in:
Olivier Lamy 2011-06-11 12:16:27 +00:00
parent 040d582980
commit 90eed34339
8 changed files with 111 additions and 55 deletions

View File

@ -353,6 +353,12 @@
<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>

View 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";
@ -99,9 +99,17 @@ public abstract class AbstractActionTestCase
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 );
}

View 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.

View 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 );
}
}

View 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 );
}
}

View 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";
@ -51,13 +51,20 @@ public class SortRepositoriesActionTest
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 );

View 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";

View 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()));
ValueStack stack = container.getInstance( ValueStackFactory.class ).createValueStack();
stack.getContext().put( ActionContext.CONTAINER, container );
ActionContext.setContext( new ActionContext( stack.getContext() ) );
assertNotNull(ActionContext.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 );
TestMetadataResolver metadataResolver = (TestMetadataResolver) lookup( MetadataResolver.class );
artifactFactory = plexusSisuBridge.lookup( ArtifactFactory.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 );
}