]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1490] REST services : more unit test for LegacyArtifactPath and LegacyArtifactPath
authorOlivier Lamy <olamy@apache.org>
Fri, 9 Sep 2011 14:40:15 +0000 (14:40 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 9 Sep 2011 14:40:15 +0000 (14:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1167223 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ArchivaAdministrationServiceTest.java

index 968b9120eb6a0f6e42f8f1dd35af4db4707d889f..f4aba4cfb58585009ada4a9d39c08b6ad7166d5e 100644 (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 )
index 880e2d918db64fa904ec487124ae93eb6022fc59..6aa60ea1995661014dc2b470a80ae997b67e2688 100644 (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 )
         {
index ea7c91c16fedee4ec7018ec214f2afc5878de522..183f9fbf867a581f90f384fa5420b7b0636d315f 100644 (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() );
+    }
 }