mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 17:35:19 +00:00
[MRM-1504] repository admin module : add unit test for add repository
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1162818 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5528856fb2
commit
6f4e720378
@ -109,4 +109,19 @@
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<appserver.base>${project.build.outputDirectory}</appserver.base>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -107,12 +107,6 @@ public ManagedRepository getManagedRepository( String repositoryId )
|
||||
return null;
|
||||
}
|
||||
|
||||
public Boolean deleteManagedRepository( String repositoryId )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
@ -133,35 +127,41 @@ private ManagedRepositoryConfiguration addManagedRepository( String repoId, Stri
|
||||
|
||||
Configuration config = archivaConfiguration.getConfiguration();
|
||||
|
||||
CronExpressionValidator validator = new CronExpressionValidator();
|
||||
|
||||
if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
|
||||
{
|
||||
throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
|
||||
+ "], that id already exists as a managed repository." );
|
||||
}
|
||||
else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
|
||||
{
|
||||
throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
|
||||
+ "], that id already exists as a remote repository." );
|
||||
}
|
||||
else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
|
||||
{
|
||||
throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
|
||||
+ "], that id already exists as a repository group." );
|
||||
}
|
||||
|
||||
if ( !validator.validate( cronExpression ) )
|
||||
// FIXME : olamy can be empty to avoid scheduled scan ?
|
||||
if ( StringUtils.isNotBlank( cronExpression ) )
|
||||
{
|
||||
throw new RepositoryAdminException( "Invalid cron expression." );
|
||||
CronExpressionValidator validator = new CronExpressionValidator();
|
||||
|
||||
if ( !validator.validate( cronExpression ) )
|
||||
{
|
||||
throw new RepositoryAdminException( "Invalid cron expression." );
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME checKid non empty
|
||||
|
||||
if ( !GenericValidator.matchRegexp( repoId, REPOSITORY_ID_VALID_EXPRESSION ) )
|
||||
{
|
||||
throw new RepositoryAdminException(
|
||||
"Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
|
||||
}
|
||||
|
||||
if ( StringUtils.isBlank( name ) )
|
||||
{
|
||||
throw new RepositoryAdminException( "repository name cannot be empty" );
|
||||
}
|
||||
|
||||
if ( !GenericValidator.matchRegexp( name, REPOSITORY_NAME_VALID_EXPRESSION ) )
|
||||
{
|
||||
throw new RepositoryAdminException(
|
||||
@ -232,6 +232,13 @@ public Boolean updateManagedRepository( ManagedRepository managedRepository, boo
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
public Boolean deleteManagedRepository( String repositoryId )
|
||||
throws RepositoryAdminException
|
||||
{
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
// utils methods
|
||||
//--------------------------
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ -31,5 +33,8 @@
|
||||
public abstract class AbstractRepositoryAdminTest
|
||||
extends TestCase
|
||||
{
|
||||
protected Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
public static final String APPSERVER_BASE_PATH = System.getProperty( "appserver.base" );
|
||||
// no op
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -40,6 +41,13 @@ public void getAllManagedRepos()
|
||||
List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
|
||||
assertNotNull( repos );
|
||||
assertTrue( repos.size() > 0 );
|
||||
log.info( "repos " + repos );
|
||||
|
||||
// check default internal
|
||||
ManagedRepository internal = findManagedRepoById( repos, "internal" );
|
||||
assertNotNull( internal );
|
||||
assertTrue( internal.isReleases() );
|
||||
assertFalse( internal.isSnapshots() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -50,4 +58,38 @@ public void getById()
|
||||
assertNotNull( repo );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addManagedRepo()
|
||||
throws Exception
|
||||
{
|
||||
List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
|
||||
assertNotNull( repos );
|
||||
int initialSize = repos.size();
|
||||
assertTrue( initialSize > 0 );
|
||||
|
||||
ManagedRepository repo = new ManagedRepository();
|
||||
repo.setId( "test-new-one" );
|
||||
repo.setName( "test repo" );
|
||||
repo.setUrl( APPSERVER_BASE_PATH + repo.getId() );
|
||||
managedRepositoryAdmin.addManagedRepository( repo, false );
|
||||
repos = managedRepositoryAdmin.getManagedRepositories();
|
||||
assertNotNull( repos );
|
||||
assertEquals( initialSize + 1, repos.size() );
|
||||
|
||||
assertNotNull( managedRepositoryAdmin.getManagedRepository( "test-new-one" ) );
|
||||
}
|
||||
|
||||
|
||||
private ManagedRepository findManagedRepoById( List<ManagedRepository> repos, String id )
|
||||
{
|
||||
for ( ManagedRepository repo : repos )
|
||||
{
|
||||
if ( StringUtils.equals( id, repo.getId() ) )
|
||||
{
|
||||
return repo;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user