From 69074d10084aaa5e06a2cd28460443a12bc8001b Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 7 Sep 2011 21:49:33 +0000 Subject: [PATCH] [MRM-1490] REST services : proxyconnector service : add simple unit test git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166428 13f79535-47bb-0310-9956-ffa450edef68 --- .../api/services/ProxyConnectorService.java | 11 +----- .../DefaultProxyConnectorService.java | 23 ----------- .../services/AbstractArchivaRestTest.java | 13 +++++++ .../services/ProxyConnectorServiceTest.java | 39 +++++++++++++++++++ 4 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ProxyConnectorServiceTest.java diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java index f53ebc94c..be3a168fd 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorService.java @@ -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; /** * No update method for changing source and target here as id is : sourceRepoId and targetRepoId, use delete then add. @@ -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> getProxyConnectorAsMap() - throws RepositoryAdminException; - } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java index ef2699f6a..50cd6b647 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultProxyConnectorService.java @@ -100,29 +100,6 @@ public class DefaultProxyConnectorService getAuditInformation() ); } - public Map> getProxyConnectorAsMap() - throws RepositoryAdminException - { - Map> modelMap = - proxyConnectorAdmin.getProxyConnectorAsMap(); - if ( modelMap == null || modelMap.isEmpty() ) - { - return Collections.emptyMap(); - } - Map> map = new HashMap>( modelMap.size() ); - for ( Map.Entry> entry : modelMap.entrySet() ) - { - List proxyConnectors = new ArrayList( 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; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java index 5f3c7b918..91b3269c1 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/AbstractArchivaRestTest.java @@ -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 index 000000000..be3dcc2eb --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/ProxyConnectorServiceTest.java @@ -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 ); + + } + +} -- 2.39.5