From: Olivier Lamy Date: Fri, 9 Sep 2011 14:40:15 +0000 (+0000) Subject: [MRM-1490] REST services : more unit test for LegacyArtifactPath and LegacyArtifactPath X-Git-Tag: archiva-1.4-M1~338 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=97de6d311871bf0576c083c2228175ef14268bea;p=archiva.git [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 --- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java index 968b9120e..f4aba4cfb 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java @@ -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 ) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java index 880e2d918..6aa60ea19 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java @@ -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 createToInstance( Object from, Class 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 ) { diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java index ea7c91c16..183f9fbf8 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java @@ -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() ); + } }