From 4c4294ffc263e05d071737a0a9b89b3ca8587eeb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 5 May 2018 10:03:56 +1000 Subject: [PATCH] Issue #2496 - Add Integration Tests for jetty-maven-plugin skip behavior (#2507) * Add Integration Tests for jetty-maven-plugin skip behavior #2496 Signed-off-by: olivier lamy * add missing license headers Signed-off-by: olivier lamy * add missing license headers Signed-off-by: olivier lamy * add missing license headers Signed-off-by: olivier lamy * add missing license headers Signed-off-by: olivier lamy --- .../src/it/jetty-deploy-war-mojo-it/pom.xml | 32 +--- .../it/run-mojo-gwt-it/beer-client/pom.xml | 48 +++++ .../src/main/java/org/olamy/App.java | 176 ++++++++++++++++++ .../beer-client/src/main/module.gwt.xml | 12 ++ .../it/run-mojo-gwt-it/beer-server/pom.xml | 161 ++++++++++++++++ .../beer-server/src/config/jetty.xml | 40 ++++ .../java/org/olamy/GreetingServiceImpl.java | 48 +++++ .../src/main/jettyconf/context.xml | 6 + .../src/main/webapp/WEB-INF/web.xml | 22 +++ .../beer-server/src/main/webapp/beer.css | 34 ++++ .../beer-server/src/main/webapp/favicon.ico | Bin 0 -> 1082 bytes .../beer-server/src/main/webapp/index.html | 59 ++++++ .../test/java/org/olamy/TestGetContent.java | 92 +++++++++ .../it/run-mojo-gwt-it/beer-shared/pom.xml | 28 +++ .../main/java/org/olamy/FieldVerifier.java | 60 ++++++ .../main/java/org/olamy/GreetingResponse.java | 52 ++++++ .../main/java/org/olamy/GreetingService.java | 30 +++ .../java/org/olamy/GreetingServiceAsync.java | 29 +++ .../src/it/run-mojo-gwt-it/invoker.properties | 1 + .../src/it/run-mojo-gwt-it/pom.xml | 91 +++++++++ .../src/it/run-mojo-gwt-it/verify.groovy | 21 +++ 21 files changed, 1013 insertions(+), 29 deletions(-) create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/pom.xml create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/src/main/java/org/olamy/App.java create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/src/main/module.gwt.xml create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/pom.xml create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/config/jetty.xml create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/java/org/olamy/GreetingServiceImpl.java create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/jettyconf/context.xml create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/WEB-INF/web.xml create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/beer.css create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/favicon.ico create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/index.html create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/test/java/org/olamy/TestGetContent.java create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/pom.xml create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/FieldVerifier.java create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingResponse.java create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingService.java create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingServiceAsync.java create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/invoker.properties create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/pom.xml create mode 100644 jetty-maven-plugin/src/it/run-mojo-gwt-it/verify.groovy diff --git a/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/pom.xml b/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/pom.xml index c048789de8d..a76571e21e1 100644 --- a/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-deploy-war-mojo-it/pom.xml @@ -6,13 +6,13 @@ org.eclipse.jetty.its.jetty-deploy-war-mojo-it jetty-simple-project 0.0.1-SNAPSHOT - jar + pom Jetty :: Simple deploy war mojo test @project.version@ - ${project.build.directory}/jetty-run-war-port.txt + ${project.build.directory}/jetty-deploy-war-port.txt @@ -53,33 +53,6 @@ - - org.apache.maven.plugins - maven-failsafe-plugin - @surefireVersion@ - - - ${jetty.port.file} - - - **/*TestGetContent* - - - - - integration-test - - integration-test - - - - verify - - verify - - - - org.eclipse.jetty jetty-maven-plugin @@ -92,6 +65,7 @@ deploy-war + @jetty.runPort@ pom diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/pom.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/pom.xml new file mode 100644 index 00000000000..d1602c95c72 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + + + org.olamy + beer + 1.0-SNAPSHOT + + + beer-client + gwt-app + + + + ${project.groupId} + beer-shared + ${project.version} + + + ${project.groupId} + beer-shared + ${project.version} + sources + + + com.google.gwt + gwt-user + + + com.google.gwt + gwt-dev + + + + + + + net.ltgt.gwt.maven + gwt-maven-plugin + + org.olamy.App + app + + + + + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/src/main/java/org/olamy/App.java b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/src/main/java/org/olamy/App.java new file mode 100644 index 00000000000..862044d77f4 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/src/main/java/org/olamy/App.java @@ -0,0 +1,176 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.olamy; + +import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.KeyCodes; +import com.google.gwt.event.dom.client.KeyUpEvent; +import com.google.gwt.event.dom.client.KeyUpHandler; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.TextBox; +import com.google.gwt.user.client.ui.VerticalPanel; + +/** + * Entry point classes define onModuleLoad(). + */ +public class App implements EntryPoint { + /** + * The message displayed to the user when the server cannot be reached or + * returns an error. + */ + private static final String SERVER_ERROR = "An error occurred while " + + "attempting to contact the server. Please check your network " + + "connection and try again."; + + /** + * Create a remote service proxy to talk to the server-side Greeting service. + */ + private final GreetingServiceAsync greetingService = GWT + .create(GreetingService.class); + + /** + * This is the entry point method. + */ + public void onModuleLoad() { + final Button sendButton = new Button("Send"); + final TextBox nameField = new TextBox(); + nameField.setText("GWT User"); + final Label errorLabel = new Label(); + + // We can add style names to widgets + sendButton.addStyleName("sendButton"); + + // Add the nameField and sendButton to the RootPanel + // Use RootPanel.get() to get the entire body element + RootPanel.get("nameFieldContainer").add(nameField); + RootPanel.get("sendButtonContainer").add(sendButton); + RootPanel.get("errorLabelContainer").add(errorLabel); + + // Focus the cursor on the name field when the app loads + nameField.setFocus(true); + nameField.selectAll(); + + // Create the popup dialog box + final DialogBox dialogBox = new DialogBox(); + dialogBox.setText("Remote Procedure Call"); + dialogBox.setAnimationEnabled(true); + final Button closeButton = new Button("Close"); + // We can set the id of a widget by accessing its Element + closeButton.getElement().setId("closeButton"); + final Label textToServerLabel = new Label(); + final HTML serverResponseLabel = new HTML(); + VerticalPanel dialogVPanel = new VerticalPanel(); + dialogVPanel.addStyleName("dialogVPanel"); + dialogVPanel.add(new HTML("Sending name to the server:")); + dialogVPanel.add(textToServerLabel); + dialogVPanel.add(new HTML("
Server replies:")); + dialogVPanel.add(serverResponseLabel); + dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); + dialogVPanel.add(closeButton); + dialogBox.setWidget(dialogVPanel); + + // Add a handler to close the DialogBox + closeButton.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + dialogBox.hide(); + sendButton.setEnabled(true); + sendButton.setFocus(true); + } + }); + + // Create a handler for the sendButton and nameField + class MyHandler implements ClickHandler, KeyUpHandler { + /** + * Fired when the user clicks on the sendButton. + */ + public void onClick(ClickEvent event) { + sendNameToServer(); + } + + /** + * Fired when the user types in the nameField. + */ + public void onKeyUp(KeyUpEvent event) { + if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { + sendNameToServer(); + } + } + + /** + * Send the name from the nameField to the server and wait for a response. + */ + private void sendNameToServer() { + // First, we validate the input. + errorLabel.setText(""); + String textToServer = nameField.getText(); + if (!FieldVerifier.isValidName(textToServer)) { + errorLabel.setText("Please enter at least four characters"); + return; + } + + // Then, we send the input to the server. + sendButton.setEnabled(false); + textToServerLabel.setText(textToServer); + serverResponseLabel.setText(""); + greetingService.greetServer(textToServer, + new AsyncCallback() { + public void onFailure(Throwable caught) { + // Show the RPC error message to the user + dialogBox + .setText("Remote Procedure Call - Failure"); + serverResponseLabel + .addStyleName("serverResponseLabelError"); + serverResponseLabel.setHTML(SERVER_ERROR); + dialogBox.center(); + closeButton.setFocus(true); + } + + public void onSuccess(GreetingResponse result) { + dialogBox.setText("Remote Procedure Call"); + serverResponseLabel + .removeStyleName("serverResponseLabelError"); + serverResponseLabel.setHTML(new SafeHtmlBuilder() + .appendEscaped(result.getGreeting()) + .appendHtmlConstant("

I am running ") + .appendEscaped(result.getServerInfo()) + .appendHtmlConstant(".

It looks like you are using:
") + .appendEscaped(result.getUserAgent()) + .toSafeHtml()); + dialogBox.center(); + closeButton.setFocus(true); + } + }); + } + } + + // Add a handler to send the name to the server + MyHandler handler = new MyHandler(); + sendButton.addClickHandler(handler); + nameField.addKeyUpHandler(handler); + } +} diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/src/main/module.gwt.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/src/main/module.gwt.xml new file mode 100644 index 00000000000..6cda0e54be6 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-client/src/main/module.gwt.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/pom.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/pom.xml new file mode 100644 index 00000000000..ba0ea68de2f --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/pom.xml @@ -0,0 +1,161 @@ + + + 4.0.0 + + + org.olamy + beer + 1.0-SNAPSHOT + + + beer-server + war + + + ${project.build.directory}/jetty-run-mojo.txt + + + + + ${project.groupId} + beer-shared + ${project.version} + + + com.google.gwt + gwt-servlet + + + javax.servlet + javax.servlet-api + provided + + + + org.eclipse.jetty + jetty-client + ${jetty.version} + test + + + org.eclipse.jetty + jetty-util + ${jetty.version} + test + + + org.eclipse.jetty + jetty-http + ${jetty.version} + test + + + org.eclipse.jetty + jetty-io + ${jetty.version} + test + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + @surefireVersion@ + + + ${jetty.port.file} + + + + + org.eclipse.jetty + jetty-maven-plugin + + + run + test-compile + + run + + + + + jetty.port.file + ${jetty.port.file} + + + true + 1 + + ${basedir}/../beer-shared/target/classes/ + + ${basedir}/src/main/jettyconf/context.xml + ${basedir}/src/config/jetty.xml + + + + + + + + + + + env-prod + + true + + + + ${project.groupId} + beer-client + ${project.version} + war + runtime + + + + + env-dev + + + env + dev + + + + + + + org.eclipse.jetty + jetty-maven-plugin + + + + ${basedir}/src/main/webapp + ${basedir}/../target/gwt/launcherDir/ + + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + + ${basedir}/src/main/tomcatconf/context.xml + + + + + + + + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/config/jetty.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/config/jetty.xml new file mode 100644 index 00000000000..c38bcced0e1 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/config/jetty.xml @@ -0,0 +1,40 @@ + + + + + + https + + 32768 + 8192 + 8192 + 512 + + + + + + + + + + + + + + + + + + + + + + + + 0 + 30000 + + + + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/java/org/olamy/GreetingServiceImpl.java b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/java/org/olamy/GreetingServiceImpl.java new file mode 100644 index 00000000000..1fedbbbeea1 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/java/org/olamy/GreetingServiceImpl.java @@ -0,0 +1,48 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.olamy; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; + +/** + * The server side implementation of the RPC service. + */ +@SuppressWarnings("serial") +public class GreetingServiceImpl extends RemoteServiceServlet implements + GreetingService { + + public GreetingResponse greetServer(String input) throws IllegalArgumentException { + // Verify that the input is valid. + if (!FieldVerifier.isValidName(input)) { + // If the input is not valid, throw an IllegalArgumentException back to + // the client. + throw new IllegalArgumentException( + "Name must be at least 4 characters long"); + } + + GreetingResponse response = new GreetingResponse(); + + response.setServerInfo(getServletContext().getServerInfo()); + response.setUserAgent(getThreadLocalRequest().getHeader("User-Agent")); + + response.setGreeting("Hello, " + input + "!"); + + return response; + } +} diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/jettyconf/context.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/jettyconf/context.xml new file mode 100644 index 00000000000..eaea86d15cf --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/jettyconf/context.xml @@ -0,0 +1,6 @@ + + + org.eclipse.jetty.servlet.Default.useFileMappedBuffer + false + + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/WEB-INF/web.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..4ece79123db --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,22 @@ + + + + + + greetServlet + org.olamy.GreetingServiceImpl + + + + greetServlet + /app/greet + + + + + index.html + + + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/beer.css b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/beer.css new file mode 100644 index 00000000000..7aca7ac7b65 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/beer.css @@ -0,0 +1,34 @@ +/** Add css rules here for your application. */ + + +/** Example rules used by the template application (remove for your app) */ +h1 { + font-size: 2em; + font-weight: bold; + color: #777777; + margin: 40px 0px 70px; + text-align: center; +} + +.sendButton { + display: block; + font-size: 16pt; +} + +/** Most GWT widgets already have a style name defined */ +.gwt-DialogBox { + width: 400px; +} + +.dialogVPanel { + margin: 5px; +} + +.serverResponseLabelError { + color: red; +} + +/** Set ids using widget.getElement().setId("idOfElement") */ +#closeButton { + margin: 15px 6px 6px; +} diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/favicon.ico b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..858a707523f540b16b6bd2cd79d8e870e5be524e GIT binary patch literal 1082 zcmZ`%ZETZO6uxD(Y;;{a>DsOByS{zfwcXaP?KZm7ZL*C*$bz2`oQXsMV+;XBQWYWr zYPJc6iP}IxBVpqQ{7{GsCSoK&zqdJ}*@R%GfJNp6J26{7Sl7o}lPdi1+&uT3oR8<6 zb8`vd(IXKPdb32wCqzaFF;Ykmn-B47&A#g@=I{@kviGeTm7B8>BFG2x znvr(r&4;vx+4o87i{n`_doHasp1I3#$0pRw!NdB>cUIZNPvu5=NEoSyFw&lXd~E5? zS2&j+jhmBLP#(r2HUtUx4djL|AuJoXD_G2F>pSGS3Nf=cL+sl+FyDB6W8y76rG3697TyP3Ylpb+NM$PRZ*1cFF~W& z_c>=hF}blXfooG4)OUVI>jEJ15J<^I_#@L;SQ(}}1t4Jj;FSmPh$?_$?GQ>00cg}8 zd~0bwnf@aU3||GLRo_FT8HJF$i~>~{o7_KQ#dBj2RfQp^GpyNkmBykFaUn=+!{Bs> z;--dUzuulo!{bSzu`Y$ymJ}Ks@oaTN3@XzVtl980R&`y&lP~;)Uhgju>LTbjMc8pct~ zjzVrc2X%SR2_D%Z=92?1MXC3-D)sRr?T+plr+GCRYKM}}`q-?)GCNaWoygjZXJO#( zz-FF+$r72@>iZK4;hXjc|01>d&p*@F-`-dewVT(Su^P93Z87*F4$DU~%k7mcFN5b%ULc)s3%Ms*f*gs@bMx qKWr^5TrSP^$>&dkkc&AiBV_MF>di6z%a+gjPv4-iKWScu=Kl?kF{Cg6 literal 0 HcmV?d00001 diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/index.html b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/index.html new file mode 100644 index 00000000000..96cb49b86b1 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/main/webapp/index.html @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + Web Application Starter Project + + + + + + + + + + + + + + + + + + + +

Web Application Starter Project

+ + + + + + + + + + + + +
Please enter your name:
+ + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/test/java/org/olamy/TestGetContent.java b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/test/java/org/olamy/TestGetContent.java new file mode 100644 index 00000000000..63d2e5d97cd --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-server/src/test/java/org/olamy/TestGetContent.java @@ -0,0 +1,92 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.olamy; + +import org.eclipse.jetty.client.HttpClient; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.FileReader; +import java.io.LineNumberReader; + +/** + * + */ +public class TestGetContent + +{ + @Test + public void get_root_response() + throws Exception + { + + int port = getPort(); + Assert.assertTrue(port > 0); + HttpClient httpClient = new HttpClient(); + try + { + httpClient.start(); + + String response = httpClient.GET( "http://localhost:" + port ).getContentAsString(); + + System.out.println( "response" + response ); + Assert.assertTrue( response.contains( "Please enter your name" ) ); + + } + finally + { + httpClient.stop(); + } + } + + + public int getPort() + throws Exception + { + int attempts = 20; + int port = -1; + String s = System.getProperty("jetty.port.file"); + Assert.assertNotNull(s); + File f = new File(s); + while (true) + { + if (f.exists()) + { + try (FileReader r = new FileReader(f); + LineNumberReader lnr = new LineNumberReader(r); + ) + { + s = lnr.readLine(); + Assert.assertNotNull(s); + port = Integer.parseInt(s.trim()); + } + break; + } + else + { + if (--attempts < 0) + break; + else + Thread.currentThread().sleep(100); + } + } + return port; + } +} diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/pom.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/pom.xml new file mode 100644 index 00000000000..d9e985631b0 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + + org.olamy + beer + 1.0-SNAPSHOT + + + beer-shared + + + + com.google.gwt + gwt-servlet + provided + + + + + + + maven-source-plugin + + + + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/FieldVerifier.java b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/FieldVerifier.java new file mode 100644 index 00000000000..8289d061d3a --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/FieldVerifier.java @@ -0,0 +1,60 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.olamy; + +/** + *

+ * FieldVerifier validates that the name the user enters is valid. + *

+ *

+ * This class is in the shared project because we use it in both + * the client code and on the server. On the client, we verify that the name is + * valid before sending an RPC request so the user doesn't have to wait for a + * network round trip to get feedback. On the server, we verify that the name is + * correct to ensure that the input is correct regardless of where the RPC + * originates. + *

+ *

+ * When creating a class that is used on both the client and the server, be sure + * that all code is translatable and does not use native JavaScript. Code that + * is not translatable (such as code that interacts with a database or the file + * system) cannot be compiled into client side JavaScript. Code that uses native + * JavaScript (such as Widgets) cannot be run on the server. + *

+ */ +public class FieldVerifier { + + /** + * Verifies that the specified name is valid for our service. + * + * In this example, we only require that the name is at least four + * characters. In your application, you can use more complex checks to ensure + * that usernames, passwords, email addresses, URLs, and other fields have the + * proper syntax. + * + * @param name the name to validate + * @return true if valid, false if invalid + */ + public static boolean isValidName(String name) { + if (name == null) { + return false; + } + return name.length() > 3; + } +} diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingResponse.java b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingResponse.java new file mode 100644 index 00000000000..df2d178fee5 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingResponse.java @@ -0,0 +1,52 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.olamy; + +import java.io.Serializable; + +@SuppressWarnings("serial") +public class GreetingResponse implements Serializable { + private String greeting; + private String serverInfo; + private String userAgent; + + public String getGreeting() { + return greeting; + } + + public void setGreeting(String greeting) { + this.greeting = greeting; + } + + public String getServerInfo() { + return serverInfo; + } + + public void setServerInfo(String serverInfo) { + this.serverInfo = serverInfo; + } + + public String getUserAgent() { + return userAgent; + } + + public void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } +} \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingService.java b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingService.java new file mode 100644 index 00000000000..0ee0b16d53c --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingService.java @@ -0,0 +1,30 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.olamy; + +import com.google.gwt.user.client.rpc.RemoteService; +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; + +/** + * The client side stub for the RPC service. + */ +@RemoteServiceRelativePath("greet") +public interface GreetingService extends RemoteService { + GreetingResponse greetServer(String name) throws IllegalArgumentException; +} diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingServiceAsync.java b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingServiceAsync.java new file mode 100644 index 00000000000..1b39c63cc3c --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/beer-shared/src/main/java/org/olamy/GreetingServiceAsync.java @@ -0,0 +1,29 @@ +// +// ======================================================================== +// Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.olamy; + +import com.google.gwt.user.client.rpc.AsyncCallback; + +/** + * The async counterpart of GreetingService. + */ +public interface GreetingServiceAsync { + void greetServer(String input, AsyncCallback callback) + throws IllegalArgumentException; +} diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/invoker.properties b/jetty-maven-plugin/src/it/run-mojo-gwt-it/invoker.properties new file mode 100644 index 00000000000..26652d0273a --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/invoker.properties @@ -0,0 +1 @@ +invoker.goals = verify \ No newline at end of file diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/pom.xml b/jetty-maven-plugin/src/it/run-mojo-gwt-it/pom.xml new file mode 100644 index 00000000000..2481085ced6 --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + org.olamy + beer + 1.0-SNAPSHOT + pom + + + UTF-8 + @project.version@ + + + + + + com.google.gwt + gwt + 2.8.2 + pom + import + + + javax.servlet + javax.servlet-api + 3.1.0 + + + + + + + + net.ltgt.gwt.maven + gwt-maven-plugin + false + + ${project.build.directory}/gwt/launcherDir + + + + + + + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.version} + + + + + net.ltgt.gwt.maven + gwt-maven-plugin + 1.0-rc-9 + true + + 1.8 + true + + + + maven-source-plugin + 3.0.1 + + + attach-sources + package + + jar-no-fork + + + + + + + + + beer-client + beer-shared + beer-server + + diff --git a/jetty-maven-plugin/src/it/run-mojo-gwt-it/verify.groovy b/jetty-maven-plugin/src/it/run-mojo-gwt-it/verify.groovy new file mode 100644 index 00000000000..822aaae276a --- /dev/null +++ b/jetty-maven-plugin/src/it/run-mojo-gwt-it/verify.groovy @@ -0,0 +1,21 @@ +/* + * 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. + */ +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( 'Started Jetty Server' ) +assert buildLog.text.contains( 'Running org.olamy.TestGetContent') \ No newline at end of file