[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
This commit is contained in:
Olivier Lamy 2011-09-07 21:49:33 +00:00
parent 5b3487fe7f
commit 69074d1008
4 changed files with 54 additions and 32 deletions

View 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;
}

View 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;

View 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();

View File

@ -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 );
}
}