mirror of https://github.com/apache/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@1134582 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
90eed34339
commit
75ac09e5b5
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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,6 +32,13 @@ 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
|
||||
*
|
||||
|
@ -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()
|
||||
|
@ -175,7 +175,7 @@ public class AddManagedRepositoryActionTest
|
|||
public void testAddRepositoryExistingLocation()
|
||||
throws Exception
|
||||
{
|
||||
if( !location.exists() )
|
||||
if ( !location.exists() )
|
||||
{
|
||||
location.mkdirs();
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue