Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
o Fix repo group REST client and util
Browse files Browse the repository at this point in the history
  • Loading branch information
nabcos committed Jan 4, 2012
1 parent 3cba57c commit f846e20
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 76 deletions.
Expand Up @@ -34,7 +34,6 @@
import org.sonatype.nexus.rest.model.RepositoryGroupListResourceResponse;
import org.sonatype.nexus.rest.model.RepositoryGroupMemberRepository;
import org.sonatype.nexus.rest.model.RepositoryGroupResource;
import org.sonatype.nexus.rest.model.RepositoryGroupResourceResponse;
import org.sonatype.plexus.rest.representation.XStreamRepresentation;
import org.testng.Assert;

Expand All @@ -45,13 +44,9 @@ public class GroupMessageUtil
{
public static final String SERVICE_PART = "service/local/repo_groups";

private XStream xstream;

private MediaType mediaType;

private static final Logger LOG = LoggerFactory.getLogger( GroupMessageUtil.class );

private final RepositoryGroupsNexusRestClient groupNRC;
public final RepositoryGroupsNexusRestClient groupNRC;

public GroupMessageUtil( AbstractNexusIntegrationTest test, XStream xstream, MediaType mediaType )
{
Expand Down Expand Up @@ -139,23 +134,6 @@ private List<String> repoListToStringList( List<?> repos )
return repoIdList;
}

public RepositoryGroupResource getGroup( String groupId )
throws IOException
{

String responseText = RequestFacade.doGetForText( SERVICE_PART + "/" + groupId );
LOG.debug( "responseText: \n" + responseText );

// this should use call to: getResourceFromResponse
XStreamRepresentation representation =
new XStreamRepresentation( XStreamFactory.getXmlXStream(), responseText, MediaType.APPLICATION_XML );

RepositoryGroupResourceResponse resourceResponse =
(RepositoryGroupResourceResponse) representation.getPayload( new RepositoryGroupResourceResponse() );

return resourceResponse.getData();
}

public RepositoryGroupResource updateGroup( RepositoryGroupResource group )
throws IOException
{
Expand All @@ -166,71 +144,25 @@ public RepositoryGroupResource updateGroup( RepositoryGroupResource group )
return responseResource;
}

/**
* IMPORTANT: Make sure to release the Response in a finally block when you are done with it.
*/
public Response sendMessage( Method method, RepositoryGroupResource resource )
public List<RepositoryGroupListResource> getList()
throws IOException
{
return this.sendMessage( method, resource, resource.getId() );
return groupNRC.getList();
}

/**
* IMPORTANT: Make sure to release the Response in a finally block when you are done with it.
*/
public Response sendMessage( Method method, RepositoryGroupResource resource, String id )
public Response sendMessage( final Method method, final RepositoryGroupResource resource, final String id )
throws IOException
{
XStreamRepresentation representation = new XStreamRepresentation( xstream, "", mediaType );

String idPart = ( method == Method.POST ) ? "" : "/" + id;
String serviceURI = SERVICE_PART + idPart;

RepositoryGroupResourceResponse repoResponseRequest = new RepositoryGroupResourceResponse();
repoResponseRequest.setData( resource );

// now set the payload
representation.setPayload( repoResponseRequest );

LOG.debug( "sendMessage: " + representation.getText() );

return RequestFacade.sendMessage( serviceURI, method, representation );
return groupNRC.sendMessage( method, resource, id );
}

/**
* This should be replaced with a REST Call, but the REST client does not set the Accept correctly on GET's/
*
* @return
* @throws IOException
* IMPORTANT: Make sure to release the Response in a finally block when you are done with it.
*/
public List<RepositoryGroupListResource> getList()
throws IOException
{

String responseText = RequestFacade.doGetForText( SERVICE_PART);
LOG.debug( "responseText: \n" + responseText );

XStreamRepresentation representation =
new XStreamRepresentation( XStreamFactory.getXmlXStream(), responseText, MediaType.APPLICATION_XML );

RepositoryGroupListResourceResponse resourceResponse =
(RepositoryGroupListResourceResponse) representation.getPayload( new RepositoryGroupListResourceResponse() );

return resourceResponse.getData();

}

public RepositoryGroupResource getResourceFromResponse( Response response )
public Response sendMessage( Method method, RepositoryGroupResource resource )
throws IOException
{
String responseString = response.getEntity().getText();
LOG.debug( " getResourceFromResponse: " + responseString );

XStreamRepresentation representation = new XStreamRepresentation( xstream, responseString, mediaType );
RepositoryGroupResourceResponse resourceResponse =
(RepositoryGroupResourceResponse) representation.getPayload( new RepositoryGroupResourceResponse() );

return resourceResponse.getData();
return groupNRC.sendMessage( method, resource, resource.getId() );
}

private void validateRepoInNexusConfig( RepositoryGroupResource group )
Expand All @@ -247,4 +179,9 @@ private void validateRepoInNexusConfig( RepositoryGroupResource group )
this.validateRepoLists( expectedRepos, actualRepos );
}

public RepositoryGroupResource getGroup( final String groupId )
throws IOException
{
return groupNRC.getGroup( groupId );
}
}
Expand Up @@ -22,12 +22,17 @@
import static org.sonatype.nexus.test.utils.NexusRequestMatchers.isSuccessful;

import java.io.IOException;
import java.util.List;

import com.thoughtworks.xstream.XStream;
import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.nexus.integrationtests.NexusRestClient;
import org.sonatype.nexus.rest.model.RepositoryGroupListResource;
import org.sonatype.nexus.rest.model.RepositoryGroupListResourceResponse;
import org.sonatype.nexus.rest.model.RepositoryGroupResource;
import org.sonatype.nexus.rest.model.RepositoryGroupResourceResponse;
import org.sonatype.plexus.rest.representation.XStreamRepresentation;
Expand Down Expand Up @@ -107,4 +112,57 @@ private XStreamRepresentation representation()
return new XStreamRepresentation( xstream, "", mediaType );
}

public RepositoryGroupResource getGroup( String groupId )
throws IOException
{
String responseText = nexusRestClient.doGetForText( SERVICE_PART + "/" + groupId );
LOG.debug( "responseText: \n" + responseText );

// this should use call to: getResourceFromResponse
XStreamRepresentation representation =
new XStreamRepresentation( XStreamFactory.getXmlXStream(), responseText, MediaType.APPLICATION_XML );

RepositoryGroupResourceResponse resourceResponse =
(RepositoryGroupResourceResponse) representation.getPayload( new RepositoryGroupResourceResponse() );

return resourceResponse.getData();
}

/**
* IMPORTANT: Make sure to release the Response in a finally block when you are done with it.
*/
public Response sendMessage( Method method, RepositoryGroupResource resource, String id )
throws IOException
{
XStreamRepresentation representation = new XStreamRepresentation( xstream, "", mediaType );

String idPart = ( method == Method.POST ) ? "" : "/" + id;
String serviceURI = SERVICE_PART + idPart;

RepositoryGroupResourceResponse repoResponseRequest = new RepositoryGroupResourceResponse();
repoResponseRequest.setData( resource );

// now set the payload
representation.setPayload( repoResponseRequest );

LOG.debug( "sendMessage: " + representation.getText() );

return nexusRestClient.sendMessage( serviceURI, method, representation );
}

public List<RepositoryGroupListResource> getList()
throws IOException
{
String responseText = nexusRestClient.doGetForText( SERVICE_PART );
LOG.debug( "responseText: \n" + responseText );

XStreamRepresentation representation =
new XStreamRepresentation( XStreamFactory.getXmlXStream(), responseText, MediaType.APPLICATION_XML );

RepositoryGroupListResourceResponse resourceResponse =
(RepositoryGroupListResourceResponse) representation.getPayload( new RepositoryGroupListResourceResponse() );

return resourceResponse.getData();

}
}

0 comments on commit f846e20

Please sign in to comment.