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

Commit

Permalink
NEXUS-4352
Browse files Browse the repository at this point in the history
  • Loading branch information
peterlynch committed Jun 9, 2011
1 parent dff463c commit f427a8d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
Expand Up @@ -21,18 +21,15 @@
import java.io.IOException;
import java.util.List;

import org.hamcrest.MatcherAssert;

import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Response;
import org.sonatype.nexus.integrationtests.RequestFacade;
import org.sonatype.nexus.test.utils.XStreamFactory;
import org.sonatype.plexus.rest.representation.XStreamRepresentation;

import com.sonatype.nexus.plugin.groovyconsole.rest.dto.GroovyScriptDTO;
import com.sonatype.nexus.plugin.groovyconsole.rest.dto.GroovyScriptResponseDTO;
import com.thoughtworks.xstream.XStream;
import static org.sonatype.nexus.test.utils.NexusRequestMatchers.*;

public class GroovyConsoleMessageUtil
{
Expand All @@ -48,13 +45,9 @@ public class GroovyConsoleMessageUtil
public static List<GroovyScriptDTO> getScripts()
throws IOException
{
Response response = RequestFacade.doGetRequest( "service/local/groovy_console" );

String responeText = response.getEntity().getText();
MatcherAssert.assertThat( "Expected sucess: Status was: " + response.getStatus() + "\nResponse:\n" + responeText,
response.getStatus().isSuccess() );
String responseText = RequestFacade.doGetForText("service/local/groovy_console", isSuccessful());

XStreamRepresentation representation = new XStreamRepresentation( xs, responeText, MediaType.APPLICATION_XML );
XStreamRepresentation representation = new XStreamRepresentation( xs, responseText, MediaType.APPLICATION_XML );
GroovyScriptResponseDTO listRepsonse =
(GroovyScriptResponseDTO) representation.getPayload( new GroovyScriptResponseDTO() );

Expand All @@ -67,13 +60,10 @@ public static void addScript( GroovyScriptDTO groovyScriptDTO )
{
XStreamRepresentation representation = new XStreamRepresentation( xs, "", MediaType.APPLICATION_XML );
representation.setPayload( groovyScriptDTO );
// FIXME use logger?
System.out.println( xs.toXML( groovyScriptDTO ) );

Response response = RequestFacade.sendMessage( "service/local/groovy_console", Method.POST, representation );

String responeText = response.getEntity().getText();
MatcherAssert.assertThat( "Expected sucess: Status was: " + response.getStatus() + "\nResponse:\n" + responeText,
response.getStatus().isSuccess() );
RequestFacade.doPost("service/local/groovy_console", representation, isSuccessful());

}
}
Expand Up @@ -260,6 +260,12 @@ public static String doPutForText(final String serviceURIpart, final Representat
}
}

public static void doPost(final String serviceURIpart, final Representation representation,Matcher<Response> responseMatcher)
throws IOException {
RequestFacade.sendMessage( serviceURIpart, Method.POST, representation, responseMatcher );
//return doPostForStatus(serviceURIpart,representation, null);
}

public static String doPostForText(final String serviceURIpart, final Representation representation, Matcher<Response> responseMatcher)
throws IOException {
Response response = null;
Expand Down
Expand Up @@ -102,8 +102,7 @@ public static Response generateProblemResponse( String title, String description
representation.setPayload( request );

String serviceURI = "service/local/error_reporting";
Response response = RequestFacade.sendMessage( serviceURI, Method.PUT, representation );
return response;
return RequestFacade.sendMessage( serviceURI, Method.PUT, representation );
}

public static void cleanErrorBundleDir( String directory )
Expand Down
Expand Up @@ -29,7 +29,9 @@
import org.sonatype.nexus.rest.model.SmtpSettingsResource;
import org.sonatype.nexus.rest.model.SmtpSettingsResourceRequest;
import org.sonatype.plexus.rest.representation.XStreamRepresentation;

import static org.sonatype.nexus.test.utils.NexusRequestMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
public class SettingsMessageUtil
{
private static XStream xstream;
Expand All @@ -49,8 +51,9 @@ public static GlobalConfigurationResource getData(final GlobalConfigurationResou
throws IOException
{
Preconditions.checkNotNull(wrapper);
final XStreamRepresentation xmlRepresentation = RequestFacade.doGetForXStreamRepresentationWithSuccess("service/local/global_settings/current");
final GlobalConfigurationResourceResponse configResponse = (GlobalConfigurationResourceResponse) xmlRepresentation.getPayload( wrapper );
String responseText = RequestFacade.doGetForText("service/local/global_settings/current", isSuccessful());
final XStreamRepresentation rep = new XStreamRepresentation(xstream, responseText, MediaType.APPLICATION_XML);
final GlobalConfigurationResourceResponse configResponse = (GlobalConfigurationResourceResponse) rep.getPayload( wrapper );
return configResponse.getData();
}

Expand Down

0 comments on commit f427a8d

Please sign in to comment.