]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1490] REST services : proxyconnector service : add simple unit test
authorOlivier Lamy <olamy@apache.org>
Wed, 7 Sep 2011 21:49:33 +0000 (21:49 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 7 Sep 2011 21:49:33 +0000 (21:49 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166428 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ProxyConnectorServiceTest.java [new file with mode: 0644]

index f53ebc94c07781dd31bacdd0153487bc0b481f87..be3a168fd19bcaae01a387934a0affcbb364db32 100644 (file)
@@ -31,7 +31,6 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import java.util.List;
-import java.util.Map;
 
 /**
  * <b>No update method for changing source and target here as id is : sourceRepoId and targetRepoId, use delete then add.</b>
@@ -53,7 +52,8 @@ public interface ProxyConnectorService
     @GET
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
     @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
-    ProxyConnector getProxyConnector( @QueryParam( "sourceRepoId" ) String sourceRepoId, @QueryParam( "targetRepoId" ) String targetRepoId )
+    ProxyConnector getProxyConnector( @QueryParam( "sourceRepoId" ) String sourceRepoId,
+                                      @QueryParam( "targetRepoId" ) String targetRepoId )
         throws RepositoryAdminException;
 
     @Path( "addProxyConnector" )
@@ -89,11 +89,4 @@ public interface ProxyConnectorService
         throws RepositoryAdminException;
 
 
-    @Path( "getProxyConnectorAsMap" )
-    @GET
-    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
-    @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
-    Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
-        throws RepositoryAdminException;
-
 }
index ef2699f6aa8e061a35572a36f9ed22417dfbbd95..50cd6b6471f06b8fb618d37553786c20fda1b2ab 100644 (file)
@@ -100,29 +100,6 @@ public class DefaultProxyConnectorService
                                                          getAuditInformation() );
     }
 
-    public Map<String, List<ProxyConnector>> getProxyConnectorAsMap()
-        throws RepositoryAdminException
-    {
-        Map<String, List<org.apache.archiva.admin.repository.proxyconnector.ProxyConnector>> modelMap =
-            proxyConnectorAdmin.getProxyConnectorAsMap();
-        if ( modelMap == null || modelMap.isEmpty() )
-        {
-            return Collections.emptyMap();
-        }
-        Map<String, List<ProxyConnector>> map = new HashMap<String, List<ProxyConnector>>( modelMap.size() );
-        for ( Map.Entry<String, List<org.apache.archiva.admin.repository.proxyconnector.ProxyConnector>> entry : modelMap.entrySet() )
-        {
-            List<ProxyConnector> proxyConnectors = new ArrayList<ProxyConnector>( entry.getValue().size() );
-            for ( org.apache.archiva.admin.repository.proxyconnector.ProxyConnector proxyConnector : entry.getValue() )
-            {
-                proxyConnectors.add( new BeanReplicator().replicateBean( proxyConnector, ProxyConnector.class ) );
-            }
-            map.put( entry.getKey(), proxyConnectors );
-        }
-        return map;
-    }
-
-
     public ProxyConnectorAdmin getProxyConnectorAdmin()
     {
         return proxyConnectorAdmin;
index 5f3c7b918cfd36aed6da085d846f0927540271ee..91b3269c14139e5a059019134fa13091d3fa401e 100644 (file)
@@ -22,10 +22,12 @@ package org.apache.archiva.rest.services;
 import org.apache.archiva.rest.api.model.ManagedRepository;
 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
 import org.apache.archiva.rest.api.services.PingService;
+import org.apache.archiva.rest.api.services.ProxyConnectorService;
 import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
 import org.apache.archiva.rest.api.services.RepositoriesService;
 import org.apache.archiva.rest.api.services.RepositoryGroupService;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.maven.archiva.common.utils.FileUtil;
 import org.codehaus.redback.rest.services.AbstractRestServicesTest;
 
@@ -80,6 +82,17 @@ public abstract class AbstractArchivaRestTest
                                           RepositoryGroupService.class );
     }
 
+    protected ProxyConnectorService getProxyConnectorService()
+    {
+        ProxyConnectorService service =
+            JAXRSClientFactory.create( "http://localhost:" + port + "/services/archivaServices/",
+                                       ProxyConnectorService.class );
+
+        WebClient.client( service ).header( "Authorization", authorizationHeader );
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
+        return service;
+    }
+
     protected ManagedRepository getTestManagedRepository()
     {
         String location = new File( FileUtil.getBasedir(), "target/test-repo" ).getAbsolutePath();
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ProxyConnectorServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ProxyConnectorServiceTest.java
new file mode 100644 (file)
index 0000000..be3dcc2
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.archiva.rest.services;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.junit.Test;
+
+/**
+ * @author Olivier Lamy
+ */
+public class ProxyConnectorServiceTest
+    extends AbstractArchivaRestTest
+{
+
+    @Test
+    public void getAllproxyConnectors()
+        throws Exception
+    {
+        assertTrue( getProxyConnectorService().getProxyConnectors() != null );
+        assertTrue( getProxyConnectorService().getProxyConnectors().size() > 0 );
+
+    }
+
+}