This is an automated email from the ASF dual-hosted git repository. yasserzamani pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/master by this push: new fa90e01 introduce integration tests with minimum needed changes (#301) fa90e01 is described below commit fa90e01ba508990849f7fd94b9c5fb530084ecb8 Author: Yasser Zamani <yasser.zam...@live.com> AuthorDate: Mon Dec 31 19:21:49 2018 +0330 introduce integration tests with minimum needed changes (#301) * introduce integration tests with minimum needed changes * report coverage for integration tests as well References: https://stackoverflow.com/a/41364462 http://www.mojohaus.org/cobertura-maven-plugin/usage.html#reports * switch to JaCoCo as test coverage library Cobertura latest release is old, 2015, has issues with java and an old weird issue with integration tests [1]. [1] https://github.com/cobertura/cobertura/issues/230 * Use HtmlUnit instead of JWebUnit --- .travis.yml | 31 +++--- apps/showcase/pom.xml | 72 ++++++++++---- .../struts2/showcase/chat/DateConverter.java | 12 ++- ...on-submitFieldValidatorsExamples-validation.xml | 2 +- apps/showcase/src/main/webapp/async/index.html | 1 + .../struts2/showcase/ActionChainingTest.java | 23 +++-- .../struts2/showcase/ActionTagExampleTest.java | 20 +++- .../it/org/apache/struts2/showcase/AsyncTest.java | 38 ++++++-- .../it/org/apache/struts2/showcase/CRUDTest.java | 35 +++++-- .../struts2/showcase/ComponentTagExampleTest.java | 26 ++++-- .../apache/struts2/showcase/ConversionTest.java | 104 ++++++++++++++------- .../apache/struts2/showcase/ExecAndWaitTest.java | 37 ++++++-- .../apache/struts2/showcase/FileDownloadTest.java | 49 ++++++++-- .../struts2/showcase/FreeMarkerManagerTest.java | 45 ++++++--- .../it/org/apache/struts2/showcase/ITBaseTest.java | 30 ------ .../{staticcontent => }/StaticContentTest.java | 39 ++++---- .../apache/struts2/showcase/UITagExampleTest.java | 82 ++++++++++------ .../apache/struts2/showcase/ValidationTest.java | 55 +++++++---- core/pom.xml | 1 - pom.xml | 51 ++++++++-- 20 files changed, 507 insertions(+), 246 deletions(-) diff --git a/.travis.yml b/.travis.yml index ae39403..3d9332f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,28 +3,29 @@ sudo: false jdk: - openjdk7 - - oraclejdk8 - oraclejdk9 - oraclejdk11 install: true + +env: +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 [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - ./mvnw test -DskipAssembly -B; + - 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 - ./mvnw test -DskipAssembly -Dupdate-impact -B; + if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then + ./mvnw test -DskipAssembly -B; + else + ./mvnw test -DskipAssembly -Dupdate-impact -B; + fi; 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= cache: directories: diff --git a/apps/showcase/pom.xml b/apps/showcase/pom.xml index 894a80c..787d045 100644 --- a/apps/showcase/pom.xml +++ b/apps/showcase/pom.xml @@ -142,30 +142,23 @@ </dependency> <dependency> - <groupId>net.sourceforge.jwebunit</groupId> - <artifactId>jwebunit-core</artifactId> - <version>1.4.1</version> - <scope>test</scope> - </dependency> - - <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> <scope>test</scope> </dependency> - <dependency> - <groupId>net.sourceforge.jwebunit</groupId> - <artifactId>jwebunit-htmlunit-plugin</artifactId> - <version>1.4.1</version> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>net.sourceforge.htmlunit</groupId> + <artifactId>htmlunit</artifactId> + <version>2.33</version> <scope>test</scope> - <exclusions> - <exclusion> - <groupId>xom</groupId> - <artifactId>xom</artifactId> - </exclusion> - </exclusions> </dependency> <!-- BeanValidation Example --> @@ -189,6 +182,30 @@ <build> <plugins> <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>2.22.1</version> + <configuration> + <includes> + <include>it.org.apache.struts2.showcase.*Test</include> + </includes> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <goals> + <goal>integration-test</goal> + </goals> + </execution> + <execution> + <id>verify</id> + <goals> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.16.v20140903</version> @@ -212,6 +229,27 @@ <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor> </webAppConfig> </configuration> + <executions> + <execution> + <id>start-jetty</id> + <phase>pre-integration-test</phase> + <goals> + <!-- stop any previous instance to free up the port --> + <goal>stop</goal> + <goal>run-forked</goal> + </goals> + <configuration> + <waitForChild>false</waitForChild> + </configuration> + </execution> + <execution> + <id>stop-jetty</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> + </executions> </plugin> <plugin> 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 5debf9d..eb784b6 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 e7ee3a5..5d23023 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 @@ </field> <field name="regexValidatorField"> <field-validator type="regex"> - <param name="regex"><![CDATA[ [^<>]+ ]]></param> + <param name="regex"><![CDATA[ .*\.txt ]]></param> <message><![CDATA[ regexValidatorField must match a regexp (.*\.txt) if specified ]]></message> </field-validator> </field> diff --git a/apps/showcase/src/main/webapp/async/index.html b/apps/showcase/src/main/webapp/async/index.html index 3726eb7..3d1d74b 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 8299be2..4889193 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 5379cfb..c2d2601 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 dc93ba5..d23064e 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"); - - setTextField("msg", "hello"); - submit(); - Thread.sleep(4000); - assertTextInElement("msgs", "hello"); +import org.junit.Assert; +import org.junit.Test; + +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 880f4aa..37f185e 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 9bf0523..d318824 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 b212646..ff6b0bd 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"); - - submit(); - - 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"); +import org.junit.Assert; +import org.junit.Test; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; + +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"); + + final HtmlForm form = page.getForms().get(0); - submit(); + form.getInputByValue("ADD").setChecked(true); + form.getInputByValue("MINUS").setChecked(true); - assertTextPresent("ADD"); - assertTextPresent("MINUS"); + 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 fce922b..445b340 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 1e7aa41..333bf42 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( + "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())); + } + } - URL url = new URL("http://svn.apache.org/repos/asf/struts/struts2/trunk/apps/showcase/src/main/webapp/images/struts-gif.zip"); - assertDownloadedFileEquals(url); + 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 e0006a6..61c0ddd 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 0aa35f1..0000000 --- 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 ca88fa9..8e274dd 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 0f50e81..03bf74e 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"); - - // set fields - setTextField("name", "name"); - setTextField("bio", "bio"); - selectOption("favouriteColor", "Red"); - checkCheckbox("friends", "Patrick"); - checkCheckbox("friends", "Jason"); - checkCheckbox("legalAge"); - - submit(); - - assertTextInElement("name", "name"); - assertTextInElement("bio", "bio"); - assertTextInElement("favouriteColor", "Red"); - assertTextInElement("friends", "[Patrick, Jason]"); - assertTextInElement("legalAge", "true"); +import org.junit.Assert; +import org.junit.Test; + +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; + +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"); + + 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 86a3fb2..3e7940a 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 f5e0dac..f74a3fe 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -41,7 +41,6 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> - <argLine>-Duser.language=en -Duser.region=US</argLine> <properties> <property> <name>maven.testng.output.dir</name> diff --git a/pom.xml b/pom.xml index 15bce62..bdde241 100644 --- a/pom.xml +++ b/pom.xml @@ -191,17 +191,50 @@ <profile> <id>travis-coveralls</id> <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>${argLine}</argLine> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <configuration> + <argLine>${argLine}</argLine> + </configuration> + </plugin> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <configuration> + <jvmArgs>${argLine}</jvmArgs> + </configuration> + </plugin> + </plugins> + </pluginManagement> <plugins> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>cobertura-maven-plugin</artifactId> - <version>2.7</version> - <configuration> - <format>xml</format> - <maxmem>256m</maxmem> - <!-- aggregated reports for multi-module projects --> - <aggregate>true</aggregate> - </configuration> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.8.2</version> + <executions> + <execution> + <id>prepare-agent</id> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>prepare-agent-integration</id> + <goals> + <goal>prepare-agent-integration</goal> + </goals> + </execution> + </executions> </plugin> <plugin> <groupId>org.eluder.coveralls</groupId>