[MRM-1490] REST services : more unit test for LegacyArtifactPath and LegacyArtifactPath

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1167223 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-09 14:40:15 +00:00
parent 102fd6f531
commit 97de6d3118
3 changed files with 62 additions and 4 deletions

View File

@ -92,8 +92,12 @@ public class DefaultArchivaAdministration
public RepositoryScanning getRepositoryScanning()
throws RepositoryAdminException
{
return new BeanReplicator().replicateBean( getArchivaConfiguration().getConfiguration().getRepositoryScanning(),
RepositoryScanning.class );
RepositoryScanning repositoryScanning =
new BeanReplicator().replicateBean( getArchivaConfiguration().getConfiguration().getRepositoryScanning(),
RepositoryScanning.class )
return repositoryScanning;
}
public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )

View File

@ -18,6 +18,7 @@ package org.apache.archiva.rest.services;
* under the License.
*/
import net.sf.beanlib.provider.BeanTransformer;
import net.sf.beanlib.provider.replicator.BeanReplicator;
import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.archiva.admin.repository.admin.ArchivaAdministration;
@ -97,8 +98,25 @@ public class DefaultArchivaAdministrationService
{
try
{
return new BeanReplicator().replicateBean( archivaAdministration.getRepositoryScanning(),
RepositoryScanning.class );
BeanTransformer beanTransformer = new BeanTransformer()
{
@Override
protected <T> T createToInstance( Object from, Class<T> toClass )
throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException
{
if ( from.getClass().equals( org.apache.maven.archiva.configuration.FileType.class ) )
{
return (T) new FileType();
}
return super.createToInstance( from, toClass );
}
};
BeanReplicator beanReplicator = new BeanReplicator( beanTransformer );
RepositoryScanning repositoryScanning =
beanReplicator.replicateBean( archivaAdministration.getRepositoryScanning(), RepositoryScanning.class );
return repositoryScanning;
}
catch ( RepositoryAdminException e )
{

View File

@ -18,8 +18,12 @@ package org.apache.archiva.rest.services;
* under the License.
*/
import org.apache.archiva.rest.api.model.FileType;
import org.apache.archiva.rest.api.model.LegacyArtifactPath;
import org.junit.Test;
import java.util.Arrays;
/**
* @author Olivier Lamy
*/
@ -33,4 +37,36 @@ public class ArchivaAdministrationServiceTest
assertNotNull( getArchivaAdministrationService().getLegacyArtifactPaths() );
assertFalse( getArchivaAdministrationService().getLegacyArtifactPaths().isEmpty() );
}
@Test
public void addAndDeleteLegacyPath()
throws Exception
{
int initialSize = getArchivaAdministrationService().getLegacyArtifactPaths().size();
LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath();
legacyArtifactPath.setArtifact( "foo" );
legacyArtifactPath.setPath( "bar" );
getArchivaAdministrationService().addLegacyArtifactPath( legacyArtifactPath );
assertEquals( initialSize + 1, getArchivaAdministrationService().getLegacyArtifactPaths().size() );
getArchivaAdministrationService().deleteLegacyArtifactPath( "bar" );
assertEquals( initialSize, getArchivaAdministrationService().getLegacyArtifactPaths().size() );
}
@Test
public void addAndDeleteFileType()
throws Exception
{
int initialSize = getArchivaAdministrationService().getRepositoryScanning().getFileTypes().size();
FileType fileType = new FileType();
fileType.setId( "foo" );
fileType.setPatterns( Arrays.asList( "foo", "bar" ) );
getArchivaAdministrationService().addFileType( fileType );
assertEquals( initialSize + 1,
getArchivaAdministrationService().getRepositoryScanning().getFileTypes().size() );
assertNotNull( getArchivaAdministrationService().getFileType( "foo" ) );
assertEquals( Arrays.asList( "foo", "bar" ),
getArchivaAdministrationService().getFileType( "foo" ).getPatterns() );
}
}