diff --git a/.travis.yml b/.travis.yml
index ae3940347..3d9332f9d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,28 +3,29 @@ sudo: false
jdk:
- openjdk7
- - oraclejdk8
- oraclejdk9
- oraclejdk11
install: true
-script:
- - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
- ./mvnw test -DskipAssembly -B;
- else
- ./mvnw test -DskipAssembly -Dupdate-impact -B;
- fi;
-after_success:
- # TODO delete following if statement after fix of https://github.com/cobertura/cobertura/issues/271
- - if [ "$TRAVIS_JDK_VERSION" == "openjdk8" ] || [ "$TRAVIS_JDK_VERSION" == "oraclejdk8" ]; then
- mvn cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report -Ptravis-coveralls -DskipAssembly -B;
- else
- echo "Not reporting coverage for $TRAVIS_JDK_VERSION due to incompatibility or to save performance";
- fi;
env:
- global:
- - secure: iI7IpfDtS+LUyS2yNuRCR3KelNyvBHuoMQ3gb1UNmR5SSL7jO/p3olQWrQROs28FJ+dpE3lHyIjoHrebKQGJHHAgTG2XWxn+G3fDsf+wSSFSLoDGj0o2SgGXooBbR2dccnNZHCyQaOyE2cIPWaOxrQZFE4No70LQB4mrP/gdkoc=
+global:
+ - secure: iI7IpfDtS+LUyS2yNuRCR3KelNyvBHuoMQ3gb1UNmR5SSL7jO/p3olQWrQROs28FJ+dpE3lHyIjoHrebKQGJHHAgTG2XWxn+G3fDsf+wSSFSLoDGj0o2SgGXooBbR2dccnNZHCyQaOyE2cIPWaOxrQZFE4No70LQB4mrP/gdkoc=
+matrix:
+ include:
+ - jdk: oraclejdk8
+ env: STRUTS_IT=true # do integration tests and coverage reports when jdk7,9 and 11 tests prospered
+
+script:
+ - if [ "$STRUTS_IT" == "true" ]; then
+ ./mvnw clean verify org.jacoco:jacoco-maven-plugin:report org.jacoco:jacoco-maven-plugin:report-integration org.eluder.coveralls:coveralls-maven-plugin:report -Ptravis-coveralls -DskipAssembly -B;
+ else
+ if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
+ ./mvnw test -DskipAssembly -B;
+ else
+ ./mvnw test -DskipAssembly -Dupdate-impact -B;
+ fi;
+ fi;
cache:
directories:
diff --git a/apps/showcase/pom.xml b/apps/showcase/pom.xml
index 894a80c77..787d04555 100644
--- a/apps/showcase/pom.xml
+++ b/apps/showcase/pom.xml
@@ -141,13 +141,6 @@
commons-fileupload
-
- net.sourceforge.jwebunit
- jwebunit-core
- 1.4.1
- test
-
-
commons-httpclient
commons-httpclient
@@ -155,17 +148,17 @@
test
-
- net.sourceforge.jwebunit
- jwebunit-htmlunit-plugin
- 1.4.1
+
+ junit
+ junit
+ test
+
+
+
+ net.sourceforge.htmlunit
+ htmlunit
+ 2.33
test
-
-
- xom
- xom
-
-
@@ -188,6 +181,30 @@
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+ 2.22.1
+
+
+ it.org.apache.struts2.showcase.*Test
+
+
+
+
+ integration-test
+
+ integration-test
+
+
+
+ verify
+
+ verify
+
+
+
+
org.mortbay.jetty
jetty-maven-plugin
@@ -212,6 +229,27 @@
${basedir}/src/main/webapp/WEB-INF/web.xml
+
+
+ start-jetty
+ pre-integration-test
+
+
+ stop
+ run-forked
+
+
+ false
+
+
+
+ stop-jetty
+ post-integration-test
+
+ stop
+
+
+
diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/DateConverter.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/DateConverter.java
index 5debf9dfb..eb784b62d 100644
--- a/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/DateConverter.java
+++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/chat/DateConverter.java
@@ -20,6 +20,8 @@
*/
package org.apache.struts2.showcase.chat;
+import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
+import com.opensymphony.xwork2.inject.Inject;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.struts2.util.StrutsTypeConverter;
@@ -33,6 +35,13 @@ public class DateConverter extends StrutsTypeConverter {
private static final Logger LOG = LogManager.getLogger(DateConverter.class);
+ private XWorkConverter fallbackConverter;
+
+ @Inject
+ public void setXWorkConverter(XWorkConverter fallbackConverter) {
+ this.fallbackConverter = fallbackConverter;
+ }
+
public Object convertFromString(Map context, String[] values, Class toClass) {
if (values.length > 0 && values[0] != null && values[0].trim().length() > 0) {
@@ -40,7 +49,8 @@ public class DateConverter extends StrutsTypeConverter {
try {
return sdf.parse(values[0]);
} catch (ParseException e) {
- LOG.error("error converting value [" + values[0] + "] to Date ", e);
+ LOG.warn("error converting value [" + values[0] + "] to Date. Trying fallback converter.");
+ return this.fallbackConverter.convertValue(context, values[0], toClass);
}
}
return null;
diff --git a/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml b/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml
index e7ee3a5a3..5d23023bb 100644
--- a/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml
+++ b/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml
@@ -71,7 +71,7 @@
- ]+ ]]>
+
diff --git a/apps/showcase/src/main/webapp/async/index.html b/apps/showcase/src/main/webapp/async/index.html
index 3726eb7f8..3d1d74b1a 100644
--- a/apps/showcase/src/main/webapp/async/index.html
+++ b/apps/showcase/src/main/webapp/async/index.html
@@ -26,6 +26,7 @@
this.lastIndex = 0;
this.sendMessage = function(message) {
$.ajax({
+ async: false,
url: "sendMessage",
data: {
message: message
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ActionChainingTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ActionChainingTest.java
index 8299be2fd..4889193cc 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ActionChainingTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ActionChainingTest.java
@@ -20,11 +20,22 @@
*/
package it.org.apache.struts2.showcase;
-public class ActionChainingTest extends ITBaseTest {
- public void test() {
- beginAt("/actionchaining/actionChain1!input");
- assertTextPresent("Action Chain 1 Property 1: Property Set In Action Chain 1");
- assertTextPresent("Action Chain 2 Property 1: Property Set in Action Chain 2");
- assertTextPresent("Action Chain 3 Property 1: Property set in Action Chain 3");
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+public class ActionChainingTest {
+ @Test
+ public void test() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/actionchaining/actionChain1!input");
+
+ final String pageAsText = page.asText();
+ Assert.assertTrue(pageAsText.contains("Action Chain 1 Property 1: Property Set In Action Chain 1"));
+ Assert.assertTrue(pageAsText.contains("Action Chain 2 Property 1: Property Set in Action Chain 2"));
+ Assert.assertTrue(pageAsText.contains("Action Chain 3 Property 1: Property set in Action Chain 3"));
+ }
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ActionTagExampleTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ActionTagExampleTest.java
index 5379cfb72..c2d260136 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ActionTagExampleTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ActionTagExampleTest.java
@@ -20,10 +20,20 @@
*/
package it.org.apache.struts2.showcase;
-public class ActionTagExampleTest extends ITBaseTest {
- public void test() {
- beginAt("/tags/ui/actionTagExample!input.action");
- assertTextPresent("This text is from the called class");
- }
+import org.junit.Assert;
+import org.junit.Test;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+public class ActionTagExampleTest {
+ @Test
+ public void test() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/tags/ui/actionTagExample!input.action");
+
+ final String pageAsText = page.asText();
+ Assert.assertTrue(pageAsText.contains("This text is from the called class"));
+ }
+ }
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/AsyncTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/AsyncTest.java
index dc93ba5cf..d23064ed5 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/AsyncTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/AsyncTest.java
@@ -18,13 +18,35 @@
*/
package it.org.apache.struts2.showcase;
-public class AsyncTest extends ITBaseTest {
- public void testChatRoom() throws InterruptedException {
- beginAt("/async/index.html");
+import org.junit.Assert;
+import org.junit.Test;
- setTextField("msg", "hello");
- submit();
- Thread.sleep(4000);
- assertTextInElement("msgs", "hello");
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.DomElement;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+
+public class AsyncTest {
+ @Test
+ public void testChatRoom() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/async/index.html");
+
+ final HtmlForm form = page.getForms().get(0);
+
+ final HtmlTextInput textField = form.getInputByName("msg");
+ textField.type("hello");
+
+ final HtmlSubmitInput button = form.getInputByValue("Send");
+ final HtmlPage page2 = button.click();
+
+ Thread.sleep(4000);
+
+ final DomElement msgs = page2.getElementById("msgs");
+
+ Assert.assertEquals("hello", msgs.asText());
+ }
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/CRUDTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/CRUDTest.java
index 880f4aa1d..37f185eca 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/CRUDTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/CRUDTest.java
@@ -20,17 +20,34 @@
*/
package it.org.apache.struts2.showcase;
-public class CRUDTest extends ITBaseTest {
- public void testCreate() {
- beginAt("/skill/edit.action");
+import org.junit.Assert;
+import org.junit.Test;
- setTextField("currentSkill.name", "somename1");
- setTextField("currentSkill.description", "somedescription1");
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
- submit();
+public class CRUDTest {
+ @Test
+ public void testCreate() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/skill/edit.action");
- beginAt("/skill/list.action");
- assertTextPresent("somename1");
- assertTextPresent("somedescription1");
+ final HtmlForm form = page.getForms().get(0);
+
+ final HtmlTextInput textField = form.getInputByName("currentSkill.name");
+ textField.type("somename1");
+ final HtmlTextInput textField2 = form.getInputByName("currentSkill.description");
+ textField2.type("somedescription1");
+
+ final HtmlSubmitInput button = form.getInputByValue("Save");
+ final HtmlPage page2 = button.click();
+ final String page2Text = page2.asText();
+
+ Assert.assertTrue(page2Text.contains("somename1"));
+ Assert.assertTrue(page2Text.contains("somedescription1"));
+ }
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ComponentTagExampleTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ComponentTagExampleTest.java
index 9bf052387..d31882423 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ComponentTagExampleTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ComponentTagExampleTest.java
@@ -20,12 +20,24 @@
*/
package it.org.apache.struts2.showcase;
-public class ComponentTagExampleTest extends ITBaseTest {
- public void test() {
- beginAt("/tags/ui/componentTagExample.jsp");
- assertTextPresent("Freemarker Custom Template - parameter 'paramName' - paramValue1");
- assertTextPresent("Freemarker Custom Template - parameter 'paramName' - paramValue4");
- assertTextPresent("JSP Custom Template - parameter 'paramName' - paramValue2");
- assertTextPresent("JSP Custom Template - parameter 'paramName' - paramValue3");
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+public class ComponentTagExampleTest {
+ @Test
+ public void test() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient
+ .getPage(ParameterUtils.getBaseUrl() + "/tags/ui/componentTagExample.action");
+
+ final String pageAsText = page.asText();
+ Assert.assertTrue(pageAsText.contains("Freemarker Custom Template - parameter 'paramName' - paramValue1"));
+ Assert.assertTrue(pageAsText.contains("Freemarker Custom Template - parameter 'paramName' - paramValue4"));
+ Assert.assertTrue(pageAsText.contains("JSP Custom Template - parameter 'paramName' - paramValue2"));
+ Assert.assertTrue(pageAsText.contains("JSP Custom Template - parameter 'paramName' - paramValue3"));
+ }
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ConversionTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ConversionTest.java
index b21264691..ff6b0bdcc 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ConversionTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ConversionTest.java
@@ -20,48 +20,82 @@
*/
package it.org.apache.struts2.showcase;
-public class ConversionTest extends ITBaseTest {
- public void testList() {
- beginAt("/conversion/enterPersonsInfo.action");
- setTextField("persons[0].name", "name0");
- setTextField("persons[0].age", "0");
- setTextField("persons[1].name", "name1");
- setTextField("persons[1].age", "1");
- setTextField("persons[2].name", "name2");
- setTextField("persons[2].age", "2");
+import org.junit.Assert;
+import org.junit.Test;
- submit();
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
- assertTextPresent("SET 0 Name: name0");
- assertTextPresent("SET 0 Age: 0");
- assertTextPresent("SET 1 Name: name1");
- assertTextPresent("SET 1 Age: 1");
- assertTextPresent("SET 2 Name: name2");
- assertTextPresent("SET 2 Age: 2");
+public class ConversionTest {
+ @Test
+ public void testList() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient
+ .getPage(ParameterUtils.getBaseUrl() + "/conversion/enterPersonsInfo.action");
+
+ final HtmlForm form = page.getForms().get(0);
+
+ form.getInputByName("persons[0].name").type("name0");
+ form.getInputByName("persons[0].age").type("0");
+ form.getInputByName("persons[1].name").type("name1");
+ form.getInputByName("persons[1].age").type("1");
+ form.getInputByName("persons[2].name").type("name2");
+ form.getInputByName("persons[2].age").type("2");
+
+ final HtmlSubmitInput button = form.getInputByValue("Submit");
+ final HtmlPage page2 = button.click();
+ final String page2Text = page2.asText();
+
+ Assert.assertTrue(page2Text.contains("SET 0 Name: name0"));
+ Assert.assertTrue(page2Text.contains("SET 0 Age: 0"));
+ Assert.assertTrue(page2Text.contains("SET 1 Name: name1"));
+ Assert.assertTrue(page2Text.contains("SET 1 Age: 1"));
+ Assert.assertTrue(page2Text.contains("SET 2 Name: name2"));
+ Assert.assertTrue(page2Text.contains("SET 2 Age: 2"));
+ }
}
- public void testSet() {
- beginAt("/conversion/enterAddressesInfo.action");
- setTextField("addresses('id0').address", "address0");
- setTextField("addresses('id1').address", "address1");
- setTextField("addresses('id2').address", "address2");
+ @Test
+ public void testSet() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient
+ .getPage(ParameterUtils.getBaseUrl() + "/conversion/enterAddressesInfo.action");
- submit();
+ final HtmlForm form = page.getForms().get(0);
- assertTextPresent("id0 -> address0");
- assertTextPresent("id1 -> address1");
- assertTextPresent("id2 -> address2");
+ form.getInputByName("addresses('id0').address").type("address0");
+ form.getInputByName("addresses('id1').address").type("address1");
+ form.getInputByName("addresses('id2').address").type("address2");
+
+ final HtmlSubmitInput button = form.getInputByValue("Submit");
+ final HtmlPage page2 = button.click();
+ final String page2Text = page2.asText();
+
+ Assert.assertTrue(page2Text.contains("id0 -> address0"));
+ Assert.assertTrue(page2Text.contains("id1 -> address1"));
+ Assert.assertTrue(page2Text.contains("id2 -> address2"));
+ }
}
- public void testEnum() {
- beginAt("/conversion/enterOperationEnumInfo.action");
- checkCheckbox("selectedOperations", "ADD");
- checkCheckbox("selectedOperations", "MINUS");
+ @Test
+ public void testEnum() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient
+ .getPage(ParameterUtils.getBaseUrl() + "/conversion/enterOperationEnumInfo.action");
- submit();
+ final HtmlForm form = page.getForms().get(0);
- assertTextPresent("ADD");
- assertTextPresent("MINUS");
+ form.getInputByValue("ADD").setChecked(true);
+ form.getInputByValue("MINUS").setChecked(true);
+
+ final HtmlSubmitInput button = form.getInputByValue("Submit");
+ final HtmlPage page2 = button.click();
+ final String page2Text = page2.asText();
+
+ Assert.assertTrue(page2Text.contains("ADD"));
+ Assert.assertTrue(page2Text.contains("MINUS"));
+ }
}
}
-
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ExecAndWaitTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ExecAndWaitTest.java
index fce922bf9..445b34027 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ExecAndWaitTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ExecAndWaitTest.java
@@ -20,16 +20,35 @@
*/
package it.org.apache.struts2.showcase;
-public class ExecAndWaitTest extends ITBaseTest {
- public void testNodelay() throws InterruptedException {
- beginAt("/wait/example1.jsp");
+import org.junit.Assert;
+import org.junit.Test;
- setTextField("time", "7000");
- submit();
- assertTextPresent("We are processing your request. Please wait.");
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
- //hit it again
- beginAt("/wait/longProcess1.action?time=1000");
- assertTextPresent("We are processing your request. Please wait.");
+public class ExecAndWaitTest {
+ @Test
+ public void testNodelay() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/wait/example1.action");
+
+ final HtmlForm form = page.getForms().get(0);
+
+ final HtmlTextInput textField = form.getInputByName("time");
+ textField.type("7000");
+
+ final HtmlSubmitInput button = form.getInputByValue("submit");
+ final HtmlPage page2 = button.click();
+
+ Assert.assertTrue(page2.asText().contains("We are processing your request. Please wait."));
+
+ // hit it again
+ final HtmlPage page3 = webClient
+ .getPage(ParameterUtils.getBaseUrl() + "/wait/longProcess1.action?time=1000");
+ Assert.assertTrue(page3.asText().contains("We are processing your request. Please wait."));
+ }
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FileDownloadTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FileDownloadTest.java
index 1e7aa4150..333bf4218 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FileDownloadTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FileDownloadTest.java
@@ -20,21 +20,50 @@
*/
package it.org.apache.struts2.showcase;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
-import java.net.MalformedURLException;
-public class FileDownloadTest extends ITBaseTest {
- public void testImage() throws InterruptedException, MalformedURLException {
- beginAt("/filedownload/download.action");
+import org.junit.Assert;
+import org.junit.Test;
- URL url = new URL("http://svn.apache.org/repos/asf/struts/struts2/trunk/apps/showcase/src/main/webapp/images/struts.gif");
- assertDownloadedFileEquals(url);
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.WebClient;
+
+public class FileDownloadTest {
+ @Test
+ public void testImage() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final Page page = webClient.getPage(ParameterUtils.getBaseUrl() + "/filedownload/download.action");
+
+ URL url = new URL(
+ "https://gitbox.apache.org/repos/asf?p=struts.git;a=blob_plain;f=apps/showcase/src/main/webapp/images/struts.gif;hb=HEAD");
+
+ Assert.assertTrue(areFilesEqual(url.openStream(), page.getWebResponse().getContentAsStream()));
+ }
}
- public void testZip() throws InterruptedException, MalformedURLException {
- beginAt("/filedownload/download2.action");
+ public void testZip() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final Page page = webClient.getPage(ParameterUtils.getBaseUrl() + "/filedownload/download2.action");
- URL url = new URL("http://svn.apache.org/repos/asf/struts/struts2/trunk/apps/showcase/src/main/webapp/images/struts-gif.zip");
- assertDownloadedFileEquals(url);
+ URL url = new URL(
+ "https://gitbox.apache.org/repos/asf?p=struts.git;a=blob_plain;f=apps/showcase/src/main/webapp/images/struts-gif.zip;hb=HEAD");
+
+ Assert.assertTrue(areFilesEqual(url.openStream(), page.getWebResponse().getContentAsStream()));
+ }
+ }
+
+ private boolean areFilesEqual(InputStream i1, InputStream i2) throws IOException {
+ // read and compare bytes pair-wise
+ int b1, b2;
+ do {
+ b1 = i1.read();
+ b2 = i2.read();
+ } while (b1 == b2 && b1 != -1 && b2 != -1);
+ i1.close();
+ i2.close();
+ // true only if end of file is reached for both
+ return (b1 == -1) && (b2 == -1);
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FreeMarkerManagerTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FreeMarkerManagerTest.java
index e0006a641..61c0dddce 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FreeMarkerManagerTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/FreeMarkerManagerTest.java
@@ -20,25 +20,40 @@
*/
package it.org.apache.struts2.showcase;
-import java.net.MalformedURLException;
-import java.net.URL;
+import org.junit.Assert;
+import org.junit.Test;
-public class FreeMarkerManagerTest extends ITBaseTest {
- public void testCustomManager() {
- beginAt("/freemarker/customFreemarkerManagerDemo.action");
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.DomElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
- String date = getElementTextByXPath("//*[@id='todaysDate']");
- assertNotNull(date);
- assertTrue(date.length() > 0);
+public class FreeMarkerManagerTest {
+ @Test
+ public void testCustomManager() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient
+ .getPage(ParameterUtils.getBaseUrl() + "/freemarker/customFreemarkerManagerDemo.action");
- String time = getElementTextByXPath("//*[@id='timeNow']");
- assertNotNull(time);
- assertTrue(time.length() > 0);
+ final DomElement date = page.getElementById("todaysDate");
+ Assert.assertNotNull(date);
+ Assert.assertTrue(date.asText().length() > 0);
+
+ final DomElement time = page.getElementById("timeNow");
+ Assert.assertNotNull(time);
+ Assert.assertTrue(time.asText().length() > 0);
+ }
}
- public void testTags() {
- beginAt("/freemarker/standardTags.action");
- assertElementPresent("test_name");
- assertElementPresent("test_");
+ @Test
+ public void testTags() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/freemarker/standardTags.action");
+
+ final DomElement date = page.getElementById("test_name");
+ Assert.assertNotNull(date);
+
+ final DomElement time = page.getElementById("test");
+ Assert.assertNotNull(time);
+ }
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ITBaseTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ITBaseTest.java
deleted file mode 100644
index 0aa35f1fe..000000000
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ITBaseTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * $Id$
- *
- * 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.
- */
-package it.org.apache.struts2.showcase;
-
-import net.sourceforge.jwebunit.junit.WebTestCase;
-
-public abstract class ITBaseTest extends WebTestCase {
-
- public void setUp() throws Exception {
- getTestContext().setBaseUrl(ParameterUtils.getBaseUrl());
- }
-}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/staticcontent/StaticContentTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/StaticContentTest.java
similarity index 55%
rename from apps/showcase/src/test/java/it/org/apache/struts2/showcase/staticcontent/StaticContentTest.java
rename to apps/showcase/src/test/java/it/org/apache/struts2/showcase/StaticContentTest.java
index ca88fa9c2..8e274dd08 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/staticcontent/StaticContentTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/StaticContentTest.java
@@ -16,31 +16,34 @@
* specific language governing permissions and limitations
* under the License.
*/
-package it.org.apache.struts2.showcase.staticcontent;
+package it.org.apache.struts2.showcase;
-import it.org.apache.struts2.showcase.ITBaseTest;
+import org.junit.Assert;
+import org.junit.Test;
-import java.io.IOException;
+import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
+import com.gargoylesoftware.htmlunit.WebClient;
-import net.sourceforge.jwebunit.exception.TestingEngineResponseException;
+public class StaticContentTest {
-public class StaticContentTest extends ITBaseTest {
-
- public void testInvalidRersources1() throws IOException {
- try {
- beginAt("/struts..");
- fail("Previous request should have failed");
- } catch (TestingEngineResponseException ex) {
- // ok
+ @Test
+ public void testInvalidRersources1() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ try {
+ webClient.getPage(ParameterUtils.getBaseUrl() + "/struts..");
+ Assert.fail("Previous request should have failed");
+ } catch (FailingHttpStatusCodeException e) {
+ }
}
}
- public void testInvalidRersources2() throws IOException {
- try {
- beginAt("/struts/..%252f");
- fail("Previous request should have failed");
- } catch (TestingEngineResponseException ex) {
- // ok
+ public void testInvalidRersources2() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ try {
+ webClient.getPage(ParameterUtils.getBaseUrl() + "/struts/..%252f");
+ Assert.fail("Previous request should have failed");
+ } catch (FailingHttpStatusCodeException e) {
+ }
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/UITagExampleTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/UITagExampleTest.java
index 0f50e8173..03bf74e80 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/UITagExampleTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/UITagExampleTest.java
@@ -20,36 +20,56 @@
*/
package it.org.apache.struts2.showcase;
-public class UITagExampleTest extends ITBaseTest {
- public void testInputForm() {
- setScriptingEnabled(false);
- beginAt("/tags/ui/example!input.action");
- assertFormPresent("exampleSubmit");
- // text box
- assertFormElementPresent("name");
- // textarea
- assertFormElementPresent("bio");
- // select
- assertFormElementPresent("favouriteColor");
- // checkbox list
- assertFormElementPresent("friends");
- // checkbox
- assertFormElementPresent("legalAge");
+import org.junit.Assert;
+import org.junit.Test;
- // set fields
- setTextField("name", "name");
- setTextField("bio", "bio");
- selectOption("favouriteColor", "Red");
- checkCheckbox("friends", "Patrick");
- checkCheckbox("friends", "Jason");
- checkCheckbox("legalAge");
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSelect;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
+import com.gargoylesoftware.htmlunit.html.HtmlTextArea;
+import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
- submit();
+public class UITagExampleTest {
+ @Test
+ public void testInputForm() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient.getPage(ParameterUtils.getBaseUrl() + "/tags/ui/example!input.action");
- assertTextInElement("name", "name");
- assertTextInElement("bio", "bio");
- assertTextInElement("favouriteColor", "Red");
- assertTextInElement("friends", "[Patrick, Jason]");
- assertTextInElement("legalAge", "true");
+ final HtmlForm form = page.getFormByName("exampleSubmit");
+ Assert.assertNotNull(form);
+
+ final HtmlTextInput textField = form.getInputByName("name");
+ final HtmlTextArea textField2 = form.getTextAreaByName("bio");
+ final HtmlSelect textField3 = form.getSelectByName("favouriteColor");
+ final HtmlCheckBoxInput textField4 = form.getInputByValue("Patrick");
+ final HtmlCheckBoxInput textField41 = form.getInputByValue("Jason");
+ final HtmlCheckBoxInput textField5 = form.getInputByName("legalAge");
+
+ Assert.assertNotNull(textField);
+ Assert.assertNotNull(textField2);
+ Assert.assertNotNull(textField3);
+ Assert.assertNotNull(textField4);
+ Assert.assertNotNull(textField41);
+ Assert.assertNotNull(textField5);
+
+ textField.type("name");
+ textField2.type("bio");
+ textField3.setSelectedAttribute("Red", true);
+ textField4.setChecked(true);
+ textField41.setChecked(true);
+ textField5.setChecked(true);
+
+ final HtmlSubmitInput button = form.getInputByValue("Submit");
+ final HtmlPage page2 = button.click();
+
+ Assert.assertEquals("name", page2.getElementById("name").asText());
+ Assert.assertEquals("bio", page2.getElementById("bio").asText());
+ Assert.assertEquals("Red", page2.getElementById("favouriteColor").asText());
+ Assert.assertEquals("[Patrick, Jason]", page2.getElementById("friends").asText());
+ Assert.assertEquals("true", page2.getElementById("legalAge").asText());
+ }
}
}
diff --git a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ValidationTest.java b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ValidationTest.java
index 86a3fb27f..3e7940a11 100644
--- a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ValidationTest.java
+++ b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/ValidationTest.java
@@ -20,27 +20,44 @@
*/
package it.org.apache.struts2.showcase;
-public class ValidationTest extends ITBaseTest {
- public void testFieldValidators() {
- beginAt("/validation/showFieldValidatorsExamples.action");
+import org.junit.Assert;
+import org.junit.Test;
- setTextField("integerValidatorField", "nonint");
- setTextField("dateValidatorField", "nondate");
- setTextField("emailValidatorField", "!@@#%");
- setTextField("urlValidatorField", "!@@#%");
- setTextField("stringLengthValidatorField", "a");
- setTextField("regexValidatorField", "abc");
- setTextField("fieldExpressionValidatorField", "abc");
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
- submit();
+public class ValidationTest {
+ @Test
+ public void testFieldValidators() throws Exception {
+ try (final WebClient webClient = new WebClient()) {
+ final HtmlPage page = webClient
+ .getPage(ParameterUtils.getBaseUrl() + "/validation/showFieldValidatorsExamples.action");
- assertTextPresent("Invalid field value for field \"dateValidatorField\"");
- assertTextPresent("Invalid field value for field \"integerValidatorField\"");
- assertTextPresent("required and must be string");
- assertTextPresent("must be a valid email if supplied");
- assertTextPresent("must be a valid url if supplied ");
- assertTextPresent("must be a String of a specific greater than 1 less than 5 if specified ");
- assertTextPresent("regexValidatorField must match a regexp (.*\\.txt) if specified ");
- assertTextPresent("must be the same as the Required Validator Field if specified ");
+ final HtmlForm form = page.getForms().get(0);
+
+ form.getInputByName("integerValidatorField").type("nonint");
+ form.getInputByName("dateValidatorField").type("nondate");
+ form.getInputByName("emailValidatorField").type("!@@#%");
+ form.getInputByName("urlValidatorField").type("!@@#%");
+ form.getInputByName("stringLengthValidatorField").type("a");
+ form.getInputByName("regexValidatorField").type("abc");
+ form.getInputByName("fieldExpressionValidatorField").type("abc");
+
+ final HtmlSubmitInput button = form.getInputByValue("Submit");
+ final HtmlPage page2 = button.click();
+ final String page2Text = page2.asText();
+
+ Assert.assertTrue(page2Text.contains("Invalid field value for field \"dateValidatorField\""));
+ Assert.assertTrue(page2Text.contains("Invalid field value for field \"integerValidatorField\""));
+ Assert.assertTrue(page2Text.contains("required and must be string"));
+ Assert.assertTrue(page2Text.contains("must be a valid email if supplied"));
+ Assert.assertTrue(page2Text.contains("must be a valid url if supplied"));
+ Assert.assertTrue(
+ page2Text.contains("must be a String of a specific greater than 1 less than 5 if specified"));
+ Assert.assertTrue(page2Text.contains("regexValidatorField must match a regexp (.*\\.txt) if specified"));
+ Assert.assertTrue(page2Text.contains("must be the same as the Required Validator Field if specified"));
+ }
}
}
diff --git a/core/pom.xml b/core/pom.xml
index f5e0dac0a..f74a3fef7 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -41,7 +41,6 @@
org.apache.maven.plugins
maven-surefire-plugin
- -Duser.language=en -Duser.region=US
maven.testng.output.dir
diff --git a/pom.xml b/pom.xml
index 15bce6232..bdde241d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -191,17 +191,50 @@
travis-coveralls
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ ${argLine}
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+
+ ${argLine}
+
+
+
+ org.mortbay.jetty
+ jetty-maven-plugin
+
+ ${argLine}
+
+
+
+
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
- xml
- 256m
-
- true
-
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.2
+
+
+ prepare-agent
+
+ prepare-agent
+
+
+
+ prepare-agent-integration
+
+ prepare-agent-integration
+
+
+
org.eluder.coveralls