From f427a8dcc7deda451e2ee4e7b0390178fc6f066a Mon Sep 17 00:00:00 2001 From: Peter Lynch Date: Thu, 9 Jun 2011 00:53:13 -0400 Subject: [PATCH] NEXUS-4352 --- .../java/util/GroovyConsoleMessageUtil.java | 20 +++++-------------- .../nexus/integrationtests/RequestFacade.java | 6 ++++++ .../nexus/test/utils/ErrorReportUtil.java | 3 +-- .../nexus/test/utils/SettingsMessageUtil.java | 9 ++++++--- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/nexus/nexus-core-plugins/nexus-groovy-console-plugin/src/test/java/util/GroovyConsoleMessageUtil.java b/nexus/nexus-core-plugins/nexus-groovy-console-plugin/src/test/java/util/GroovyConsoleMessageUtil.java index 1868c4adbc..43aeb4fa12 100644 --- a/nexus/nexus-core-plugins/nexus-groovy-console-plugin/src/test/java/util/GroovyConsoleMessageUtil.java +++ b/nexus/nexus-core-plugins/nexus-groovy-console-plugin/src/test/java/util/GroovyConsoleMessageUtil.java @@ -21,11 +21,7 @@ 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; @@ -33,6 +29,7 @@ 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 { @@ -48,13 +45,9 @@ public class GroovyConsoleMessageUtil public static List 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() ); @@ -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()); } } diff --git a/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/integrationtests/RequestFacade.java b/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/integrationtests/RequestFacade.java index 422facdadd..a60a989e56 100644 --- a/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/integrationtests/RequestFacade.java +++ b/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/integrationtests/RequestFacade.java @@ -260,6 +260,12 @@ public static String doPutForText(final String serviceURIpart, final Representat } } + public static void doPost(final String serviceURIpart, final Representation representation,Matcher 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 responseMatcher) throws IOException { Response response = null; diff --git a/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/ErrorReportUtil.java b/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/ErrorReportUtil.java index 5ad9ca1ef7..551324f95b 100644 --- a/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/ErrorReportUtil.java +++ b/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/ErrorReportUtil.java @@ -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 ) diff --git a/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/SettingsMessageUtil.java b/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/SettingsMessageUtil.java index 323e4faff9..fca4543cc4 100644 --- a/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/SettingsMessageUtil.java +++ b/nexus/nexus-test-harness/nexus-test-harness-launcher/src/main/java/org/sonatype/nexus/test/utils/SettingsMessageUtil.java @@ -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; @@ -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(); }