portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asfgr...@apache.org
Subject [03/22] portals-pluto git commit: PLUTO-733 Author Selenium-based tests for the Pluto V3 demos (create test utilities and add test for the Portlet Hub Demo)
Date Thu, 25 Oct 2018 20:19:35 GMT
PLUTO-733 Author Selenium-based tests for the Pluto V3 demos (create test utilities and add
test for the Portlet Hub Demo)


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/5ea95519
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/5ea95519
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/5ea95519

Branch: refs/heads/master
Commit: 5ea955196d6cda5be1cc715ecf31d5fd8b08a5bd
Parents: fc7000d
Author: Kyle Stiemann <stiemannkj1@gmail.com>
Authored: Tue Oct 9 16:34:06 2018 -0400
Committer: Neil Griffin <neil.griffin.scm@gmail.com>
Committed: Thu Oct 25 15:47:28 2018 -0400

----------------------------------------------------------------------
 demo-integration-tests/pom.xml                  |  342 ++++
 .../demo/integration/test/DemoTestDriver.java   |   35 +
 .../demo/integration/test/ElementEnabled.java   |   57 +
 .../demo/integration/test/PortletHubDemoIT.java |  301 ++++
 .../pluto/demo/integration/test/Util.java       |  140 ++
 .../demo/integration/test/WaitingAsserter.java  |   49 +
 pom.xml                                         | 1558 +++++++++---------
 portlet-tck_3.0/driver/pom.xml                  |    5 +
 .../tck/driver/TCKLiferayTestDriver.java        |   22 +-
 .../portlet/tck/driver/TCKSimpleTestDriver.java |  619 -------
 .../javax/portlet/tck/driver/TCKTestDriver.java |  450 +++++
 portlet-tck_3.0/pom.xml                         |   40 +-
 test-base/pom.xml                               |   33 +
 .../pluto/test/utilities/SimpleTestDriver.java  |  216 +++
 14 files changed, 2422 insertions(+), 1445 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/5ea95519/demo-integration-tests/pom.xml
----------------------------------------------------------------------
diff --git a/demo-integration-tests/pom.xml b/demo-integration-tests/pom.xml
new file mode 100644
index 0000000..9cee29a
--- /dev/null
+++ b/demo-integration-tests/pom.xml
@@ -0,0 +1,342 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+    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.
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+   <parent>
+      <groupId>org.apache.portals.pluto</groupId>
+      <artifactId>pluto</artifactId>
+      <version>3.0.2-SNAPSHOT</version>
+   </parent>
+
+   <modelVersion>4.0.0</modelVersion>
+
+   <groupId>javax.portlet</groupId>
+   <artifactId>demo-integration-tests</artifactId>
+   <description>Integration Tests for the Pluto Demos</description>
+   <packaging>jar</packaging>
+
+   <licenses>
+      <license>
+         <name>apache_v2</name>
+         <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
+      </license>
+   </licenses>
+
+   <scm>
+      <connection>scm:git:https://git-wip-us.apache.org/repos/asf/portals-pluto.git</connection>
+      <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/portals-pluto.git</developerConnection>
+      <url>https://github.com/apache/portals-pluto</url>
+      <tag>HEAD</tag>
+   </scm>
+
+   <properties>
+      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+      <!-- test.context.base context string used when addressing test pages. Used by module
stylesheet -->
+      <test.context.base>pluto/portal/</test.context.base>
+
+      <!-- This variable is used by the test driver to determine how test
+      page links are to be found. Values: generateURLs the driver generates URLs
+      based on config information. followLinks the driver looks for links containing
+      the page name and clicks them in order to access the test pages. In this
+      case, the portal must produce navigation links to each of the test pages.
+      If configured to generate URLs, the driver generates URLs of the form: http://<test.server.host>:<test.server.port>/<test.context.base><test.page.name>
+      where <test.page.name> is the name of the test page generated by the individual
+      modules -->
+      <test.url.strategy>followLinks</test.url.strategy>
+
+      <!-- Configuration of portlet container under test for generated URLs -->
+      <!-- (only needed if test.url.strategy=generateURLs) -->
+      <test.server.host>localhost</test.server.host>
+      <test.server.port>8080</test.server.port>
+
+      <!-- Configuration of URL to login page -->
+      <test.server.login.url>http://${test.server.host}:${test.server.port}/pluto/portal/About
Apache Pluto</test.server.login.url>
+
+      <!-- HTML field IDs and values for username & password to enable automatic 
login -->
+      <!-- User specified must be in 'tckuser' role. Please configure 'tckuser' role for
the specified user in tomcat-users.xml -->
+      <test.server.username.id>j_username</test.server.username.id>
+      <test.server.username>pluto</test.server.username>
+      <test.server.password.id>j_password</test.server.password.id>
+      <test.server.password>pluto</test.server.password>
+
+      <!-- Specifies the browser to be used by selenium WebDriver for running the tests.
-->
+      <!-- Can be used with firefox or HTMLUnit without setting the test.browser.webDriver
property. -->
+      <!-- Use of Chrome or IE requires the webDriver to be downloaded and available.
Set the -->
+      <!-- test.browser.webDriver property to point to the appropriate WebDriver server.
-->
+      <test.browser>firefox</test.browser>
+      <test.browser>HTMLUnit</test.browser>
+
+      <!-- Lines commented out below illustrate how the chromedriver web driver can be
configured -->
+      <test.browser>chrome</test.browser>
+      <test.browser.webDriver>c:/ntutil/chromedriver.exe</test.browser.webDriver>
+
+      <!-- commented outline below shows configuration for the Internet Explorer driver
-->
+      <!-- test.browser.webDriver>C:\ntutil\IEDriverServer_x64_2.42.0\IEDriverServer.exe</test.browser.webDriver
-->
+
+      <!-- Configuration for phantomJS driver -->
+      <!-- To use phantomJS, remove the comment marks around the following two lines.
+      <test.browser>phantomjs</test.browser>
+      <test.browser.webDriver>${phantomjs.binary}</test.browser.webDriver>
+      -->
+
+      <!-- Specify timeout in seconds for the driver to wait for page load. must be an
integer. -->
+      <test.timeout>3</test.timeout>
+   </properties>
+
+   <dependencies>
+
+      <!-- For creating and executing tests -->
+      <dependency>
+         <groupId>junit</groupId>
+         <artifactId>junit</artifactId>
+      </dependency>
+      <dependency>
+         <groupId>org.apache.portals.pluto</groupId>
+         <artifactId>test-base</artifactId>
+         <version>${project.version}</version>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
+         <groupId>org.seleniumhq.selenium</groupId>
+         <artifactId>selenium-api</artifactId>
+      </dependency>
+      <dependency>
+         <groupId>org.seleniumhq.selenium</groupId>
+         <artifactId>selenium-java</artifactId>
+      </dependency>
+      <dependency>
+         <groupId>org.seleniumhq.selenium</groupId>
+         <artifactId>htmlunit-driver</artifactId>
+      </dependency>
+      <dependency>
+         <groupId>com.codeborne</groupId>
+         <artifactId>phantomjsdriver</artifactId>
+      </dependency>
+   </dependencies>
+
+   <build>
+      <finalName>${project.artifactId}</finalName>
+
+      <plugins>
+
+         <!-- skip legal file checking for now -->
+         <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>ianal-maven-plugin</artifactId>
+            <executions>
+               <execution>
+                  <goals>
+                     <goal>verify-legal-files</goal>
+                  </goals>
+                  <configuration>
+                     <skip>true</skip>
+                  </configuration>
+               </execution>
+            </executions>
+         </plugin>
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-jar-plugin</artifactId>
+            <configuration>
+               <skipIfEmpty>true</skipIfEmpty>
+            </configuration>
+         </plugin>
+
+         <!-- Don't attach source or javadoc archive (for release plugin)-->
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-source-plugin</artifactId>
+            <configuration>
+               <attach>false</attach>
+            </configuration>
+         </plugin>
+
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-javadoc-plugin</artifactId>
+            <configuration>
+               <skip>true</skip>
+            </configuration>
+         </plugin>
+
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-deploy-plugin</artifactId>
+            <configuration>
+               <skip>true</skip>
+            </configuration>
+         </plugin>
+
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-gpg-plugin</artifactId>
+            <configuration>
+               <skip>true</skip>
+            </configuration>
+         </plugin>
+
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-install-plugin</artifactId>
+            <configuration>
+               <skip>true</skip>
+            </configuration>
+         </plugin>
+
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-release-plugin</artifactId>
+            <configuration>
+               <skip>true</skip>
+            </configuration>
+         </plugin>
+
+      </plugins>
+   </build>
+
+   <reporting>
+      <plugins>
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-report-plugin</artifactId>
+            <version>2.17</version>
+            <configuration>
+               <aggregate>true</aggregate>
+               <reportsDirectories>
+                  <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
+                  <reportsDirectory>${project.build.directory}/jasmine</reportsDirectory>
+               </reportsDirectories>
+            </configuration>
+         </plugin>
+      </plugins>
+   </reporting>
+
+
+   <!-- To build the tests, use "mvn clean install" from the parent directory. -->
+   <!-- To run all of the tests, use "mvn verify -Prun-demo-tests" from the demo-integration-tests
directory. -->
+
+   <!-- To run a subset of the tests, use "mvn verify -Prun-demo-tests -Dit.test=\*<match
string>\*" from the -->
+   <!-- demo-integration-tests directory. The driver will then execute all tests whose
test case name contains the -->
+   <!-- specified string. -->
+   <!-- Example: "mvn verify -Prun-demo-tests -Dit.test=\*PortleHubDemo\*" will execute
all PortletHubDemo tests. -->
+
+   <profiles>
+      <profile>
+         <id>liferay</id>
+         <properties>
+            <test.server.login.url>http://${test.server.host}:${test.server.port}/group/pluto-demos</test.server.login.url>
+         </properties>
+      </profile>
+      <profile>
+         <id>run-demo-tests</id>
+         <build>
+            <plugins>
+               <!-- For running the tests. -->
+               <plugin>
+                  <groupId>org.apache.maven.plugins</groupId>
+                  <artifactId>maven-failsafe-plugin</artifactId>
+                  <version>2.22.0</version>
+                  <executions>
+                     <execution>
+                        <goals>
+                           <goal>integration-test</goal>
+                        </goals>
+                        <configuration>
+                           <useFile>true</useFile>
+                           <argLine>-Xms512m -Xmx512m</argLine>
+                           <trimStackTrace>false</trimStackTrace>
+                           <systemProperties>
+                              <property>
+                                 <name>test.server.login.url</name>
+                                 <value>${test.server.login.url}</value>
+                              </property>
+                              <property>
+                                 <name>test.context.base</name>
+                                 <value>${test.context.base}</value>
+                              </property>
+                              <property>
+                                 <name>test.url.strategy</name>
+                                 <value>${test.url.strategy}</value>
+                              </property>
+                              <property>
+                                 <name>test.server.host</name>
+                                 <value>${test.server.host}</value>
+                              </property>
+                              <property>
+                                 <name>test.server.port</name>
+                                 <value>${test.server.port}</value>
+                              </property>
+                              <property>
+                                 <name>test.server.username.id</name>
+                                 <value>${test.server.username.id}</value>
+                              </property>
+                              <property>
+                                 <name>test.server.username</name>
+                                 <value>${test.server.username}</value>
+                              </property>
+                              <property>
+                                 <name>test.server.password.id</name>
+                                 <value>${test.server.password.id}</value>
+                              </property>
+                              <property>
+                                 <name>test.server.password</name>
+                                 <value>${test.server.password}</value>
+                              </property>
+                              <property>
+                                 <name>test.browser</name>
+                                 <value>${test.browser}</value>
+                              </property>
+                              <property>
+                                 <name>test.browser.webDriver</name>
+                                 <value>${test.browser.webDriver}</value>
+                              </property>
+                              <property>
+                                 <name>test.browser.binary</name>
+                                 <value>${test.browser.binary}</value>
+                              </property>
+                              <property>
+                                 <name>test.browser.headless</name>
+                                 <value>${test.browser.headless}</value>
+                              </property>
+                              <property>
+                                 <name>test.browser.maximized</name>
+                                 <value>true</value>
+                              </property>
+                              <property>
+                                 <name>test.module</name>
+                                 <value>${test.module}</value>
+                              </property>
+                              <property>
+                                 <name>test.debug</name>
+                                 <value>false</value>
+                              </property>
+                              <property>
+                                 <name>test.timeout</name>
+                                 <value>${test.timeout}</value>
+                              </property>
+                           </systemProperties>
+                        </configuration>
+                     </execution>
+                  </executions>
+               </plugin>
+            </plugins>
+         </build>
+      </profile>
+   </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/5ea95519/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
new file mode 100644
index 0000000..e0b87a9
--- /dev/null
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DemoTestDriver.java
@@ -0,0 +1,35 @@
+/*  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 org.apache.portals.pluto.demo.integration.test;
+
+import org.apache.portals.pluto.test.utilities.SimpleTestDriver;
+import org.junit.BeforeClass;
+
+/**
+ *
+ * @author Kyle Stiemann
+ */
+public class DemoTestDriver extends SimpleTestDriver {
+
+   protected static WaitingAsserter waitingAsserter;
+
+   @BeforeClass
+   public static void setUpBeforeDemoSimpleTestDriverClass() {
+      waitingAsserter = new WaitingAsserter(driver, timeout);
+   }
+}

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/5ea95519/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ElementEnabled.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ElementEnabled.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ElementEnabled.java
new file mode 100644
index 0000000..95f4019
--- /dev/null
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ElementEnabled.java
@@ -0,0 +1,57 @@
+/*  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 org.apache.portals.pluto.demo.integration.test;
+
+import java.util.List;
+import org.openqa.selenium.By;
+import org.openqa.selenium.StaleElementReferenceException;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+/**
+ *
+ * @author Kyle Stiemann
+ */
+public class ElementEnabled implements ExpectedCondition<WebElement> {
+
+   private final By locator;
+
+   public ElementEnabled(By locator) {
+      this.locator = locator;
+   }
+
+   @Override
+   public WebElement apply(WebDriver webDriver) {
+
+      WebElement webElement = null;
+
+      try {
+
+         List<WebElement> webElements = webDriver.findElements(locator);
+
+         if (!webElements.isEmpty() && webElements.get(0).isEnabled()) {
+            webElement = webElements.get(0);
+         }
+      } catch (StaleElementReferenceException e) {
+         // Do nothing.
+      }
+
+      return webElement;
+   }
+}

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/5ea95519/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/PortletHubDemoIT.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/PortletHubDemoIT.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/PortletHubDemoIT.java
new file mode 100644
index 0000000..1d1119c
--- /dev/null
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/PortletHubDemoIT.java
@@ -0,0 +1,301 @@
+/*  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 org.apache.portals.pluto.demo.integration.test;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.NoSuchElementException;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+import org.openqa.selenium.support.ui.Select;
+
+import static org.apache.portals.pluto.demo.integration.test.Util.*;
+import static org.openqa.selenium.support.ui.ExpectedConditions.*;
+
+/**
+ *
+ * @author Kyle Stiemann
+ */
+public class PortletHubDemoIT extends DemoTestDriver {
+
+   private static final int COLOR_HEX_STRING_LENGTH = 2;
+   private static final String COLOR_SELECTION_PORTLET_NAMESPACE = "Pluto_PortletHubDemo_PH_ColorSelPortlet";
+   private static final String IMAGE_SELECTION_PORTLET_NAMESPACE = "Pluto_PortletHubDemo_ImageSelPortlet";
+   private static final List<String> IMAGE_OPTIONS = Util.unmodifiableList("golfball",
"baseball", "fussball");
+   private static final String MESSAGE_BOX_PORTLET_NAMESPACE = "Pluto_PortletHubDemo_MessageBoxPortlet";
+   private static final String PARTIAL_ACTION_PORTLET_NAMESPACE = "Pluto_PortletHubDemo_PartialActionPortlet";
+   private static final String RESOURCE_PORTLET_NAMESPACE = "Pluto_PortletHubDemo_PH_ResourcePortlet_PRP";
+   private static final String TOKEN = "{0}";
+   private static final String IMAGE_XPATH_TEMPLATE =
+         "//img[@src='/PortletHubDemo/resources/images/" + TOKEN + ".gif']";
+
+   @Test
+   public void testPortletHubDemo() throws UnsupportedEncodingException {
+      driver.get(baseUrl + Util.encodeURL("V3.0 Portlet Hub Demo"));
+
+      // Verify that all the different images appear when clicking each radio button.
+      By imageByXpath = By.xpath(IMAGE_XPATH_TEMPLATE.replace(TOKEN, "FullMoon"));
+      waitingAsserter.assertTrue(visibilityOfElementLocated(imageByXpath));
+
+      for (String imageName : IMAGE_OPTIONS) {
+
+         clickElement(driver, waitingAsserter,
+               getXpath("div", IMAGE_SELECTION_PORTLET_NAMESPACE) + "/input[@value='" + imageName
+ "']");
+         waitingAsserter.assertTrue(elementNotPresentOrNotVisible(imageByXpath));
+         imageByXpath = By.xpath(IMAGE_XPATH_TEMPLATE.replace(TOKEN, imageName + "-trans"));
+         waitingAsserter.assertTrue(visibilityOfElementLocated(imageByXpath));
+      }
+
+      // Verify that all the different images appear when clicking each dropdown option.
+      clickElement(driver, waitingAsserter, "input", IMAGE_SELECTION_PORTLET_NAMESPACE, "dropdown");
+      By imageSelectByXpath = By.xpath(getXpath("select", IMAGE_SELECTION_PORTLET_NAMESPACE)
+ "[@name='imgName']");
+      waitingAsserter.waitFor(elementToBeClickable(imageSelectByXpath));
+      Select select = new Select(driver.findElement(imageSelectByXpath));
+      select.selectByValue("default");
+      imageByXpath = By.xpath(IMAGE_XPATH_TEMPLATE.replace(TOKEN, "FullMoon"));
+      waitingAsserter.assertTrue(visibilityOfElementLocated(imageByXpath));
+
+      for (String imageName : IMAGE_OPTIONS) {
+
+         select = new Select(driver.findElement(imageSelectByXpath));
+         select.selectByValue(imageName);
+         waitingAsserter.assertTrue(elementNotPresentOrNotVisible(imageByXpath));
+         imageByXpath = By.xpath(IMAGE_XPATH_TEMPLATE.replace(TOKEN, imageName + "-trans"));
+         waitingAsserter.assertTrue(visibilityOfElementLocated(imageByXpath));
+      }
+
+      // Verify that the border checkbox shows and hides the border on the image.
+      waitingAsserter.assertTrue(and(visibilityOfElementLocated(imageByXpath), attributeEmpty(imageByXpath,
"style")));
+      clickElement(driver, waitingAsserter, "input", RESOURCE_PORTLET_NAMESPACE, "border");
+      waitingAsserter.assertTrue(and(visibilityOfElementLocated(imageByXpath),
+            attributeContains(imageByXpath, "style", "border:")));
+
+      // Verify that the different cacheability radion buttons change the visible cacheability
text.
+      String cacheabilityRadioButtonXpathTemplate =
+            getXpath("input", RESOURCE_PORTLET_NAMESPACE) + "[@value='" + TOKEN + "']";
+      String resourcePortletDivXpath = getXpath("div", RESOURCE_PORTLET_NAMESPACE);
+      By actionButtonByXpath = By.xpath(resourcePortletDivXpath + "//input[@value='Action']");
+
+      for (String cacheability : Util.unmodifiableList("Portlet", "Full", "Page")) {
+
+         String cacheabilityResultXpath = resourcePortletDivXpath + "//p[contains(text(),'Cacheability')]";
+         waitingAsserter.assertTrue(elementNotPresentOrNotVisible(By.xpath(cacheabilityResultXpath
+
+               "[contains(text(),'" + cacheability + "')]")));
+         String cacheabilityRadioButtonXpath = cacheabilityRadioButtonXpathTemplate.replace(TOKEN,
+               cacheability.toUpperCase(Locale.ENGLISH));
+         clickElement(driver, waitingAsserter, cacheabilityRadioButtonXpath);
+         By cacheabilityResultByXpath = By.xpath(cacheabilityResultXpath);
+         waitingAsserter.assertTrue(and(visibilityOfElementLocated(cacheabilityResultByXpath),
+               textToBePresentInElementLocated(cacheabilityResultByXpath, cacheability)));
+
+         if ("Page".equalsIgnoreCase(cacheability)) {
+            waitingAsserter.assertTrue(visibilityOfElementLocated(actionButtonByXpath));
+         } else {
+            waitingAsserter.assertTrue(visibilityOfElementLocated(By.xpath(resourcePortletDivXpath
+
+               "[contains(.,'Action URL could not be created.')]")));
+         }
+      }
+
+      // Click the Action button.
+      clickElement(driver, waitingAsserter, actionButtonByXpath);
+      waitingAsserter.assertTrue(visibilityOfElementLocated(actionButtonByXpath));
+
+      // Verify the background color changes.
+      By coloredTableByXpath =
+            By.xpath(getXpath("div", RESOURCE_PORTLET_NAMESPACE, "putResourceHere") + "//table[@style]");
+      waitingAsserter.assertTrue(and(visibilityOfElementLocated(coloredTableByXpath),
+            backgroundColor(coloredTableByXpath, 0xFF, 0xFF, 0xFF)));
+      String colorInputXpath = getXpath("input", COLOR_SELECTION_PORTLET_NAMESPACE, "color");
+      sendKeysToElement(driver, waitingAsserter, colorInputXpath, "#FF0000", Keys.ENTER);
+      waitingAsserter.assertTrue(and(visibilityOfElementLocated(coloredTableByXpath),
+            backgroundColor(coloredTableByXpath, 0xFF, 0, 0)));
+
+      // Verify that messages can be sent in different colors by different methods.
+      for (String formSubmissionMethod : Util.unmodifiableList("URL", "form")) {
+
+         for (ColorCombo colorCombo : ColorCombo.getAllPossibleCombos()) {
+
+            String lowerCaseFormSubmissionMethod = formSubmissionMethod.toLowerCase(Locale.ENGLISH);
+            clickElement(driver, waitingAsserter, "input", COLOR_SELECTION_PORTLET_NAMESPACE,
+                  lowerCaseFormSubmissionMethod);
+            testMessageSent(colorCombo);
+         }
+
+         clickElement(driver, waitingAsserter, "input", MESSAGE_BOX_PORTLET_NAMESPACE, "clear");
+      }
+
+      // Click the Do Partial Action button and check that the reponse text appears.
+      By responseDivByXpath = By.xpath(getXpath("div", PARTIAL_ACTION_PORTLET_NAMESPACE,
"responseDiv"));
+      waitingAsserter.assertTrue(textEmpty(responseDivByXpath));
+
+      for (int i = 1; i <= 10; i++) {
+
+         clickElement(driver, waitingAsserter, "input", PARTIAL_ACTION_PORTLET_NAMESPACE,
"doPA");
+         waitingAsserter.assertTrue(and(visibilityOfElementLocated(responseDivByXpath),
+               textToBePresentInElementLocated(responseDivByXpath,
+                     "Partial Action has been executed " + i + " times.")));
+      }
+   }
+
+   private void testMessageSent(ColorCombo colorCombo) {
+
+      handleColorCheckbox("red", colorCombo.isRedSelected());
+      handleColorCheckbox("green", colorCombo.isGreenSelected());
+      handleColorCheckbox("blue", colorCombo.isBlueSelected());
+
+      String messageInputXpath = getXpath("input", COLOR_SELECTION_PORTLET_NAMESPACE, "msg");
+      String message = colorCombo.getHexString();
+      sendKeysToElement(driver, waitingAsserter, messageInputXpath, message);
+      clickElement(driver, waitingAsserter, "input", COLOR_SELECTION_PORTLET_NAMESPACE, "send");
+
+      By messageOutputByXpath =
+            By.xpath(getXpath("div", MESSAGE_BOX_PORTLET_NAMESPACE, "responseDiv") +
+                  "/p[contains(text(),'" + colorCombo.getIndex() + ": " + message + "')]");
+      waitingAsserter.assertTrue(and(visibilityOfElementLocated(messageOutputByXpath),
+            or(attributeContains(messageOutputByXpath, "style", "color:#" + message + ";"),
+                  attributeContains(messageOutputByXpath, "style", "color: " + colorCombo.getCSS_RGBString()
+ ";"))));
+   }
+
+   private static ExpectedCondition<Boolean> backgroundColor(By locator, int red, int
green, int blue) {
+
+      String colorCode = "#" +
+            getHexString(red, COLOR_HEX_STRING_LENGTH) +
+            getHexString(green, COLOR_HEX_STRING_LENGTH) +
+            getHexString(blue, COLOR_HEX_STRING_LENGTH);
+
+      return and(visibilityOfElementLocated(locator),
+            or(attributeContains(locator, "style", "background-color:" + colorCode + ";"),
+                  attributeContains(locator, "style",
+                        "background-color: rgb(" + red + ", " + green + ", " + blue + ");")));
+   }
+
+   private static String getHexString(int toHexValue, int stringLength) {
+      return getZeroPaddedString(Integer.toHexString(toHexValue), stringLength);
+   }
+
+   private static String getZeroPaddedString(String string, int stringLength) {
+      return String.format("%" + stringLength + "s", string).replace(" ", "0");
+   }
+
+   private void handleColorCheckbox(String colorName, boolean colorSelected) {
+
+      WebElement colorCheckbox =
+            driver.findElement(By.xpath(getXpath("input", COLOR_SELECTION_PORTLET_NAMESPACE,
colorName)));
+
+      if ((colorSelected && !colorCheckbox.isSelected()) || (!colorSelected &&
colorCheckbox.isSelected())) {
+         colorCheckbox.click();
+      }
+   }
+
+   private static final class ColorCombo {
+
+      // Constants
+      private static final byte BLUE_BIT_POSITION = 0;
+      private static final byte GREEN_BIT_POSITION = BLUE_BIT_POSITION + 1;
+      private static final byte RED_BIT_POSITION = GREEN_BIT_POSITION + 1;
+      private static final byte BINARY_STRING_LENGTH = RED_BIT_POSITION + 1;
+
+      // Data
+      private final byte selectedColorsInBinary;
+
+      public ColorCombo(byte selectedColorsInBinary) {
+         this.selectedColorsInBinary = selectedColorsInBinary;
+      }
+
+      public boolean isRedSelected() {
+         return isColorSelected(selectedColorsInBinary, RED_BIT_POSITION);
+      }
+
+      public boolean isGreenSelected() {
+         return isColorSelected(selectedColorsInBinary, GREEN_BIT_POSITION);
+      }
+
+      public boolean isBlueSelected() {
+         return isColorSelected(selectedColorsInBinary, BLUE_BIT_POSITION);
+      }
+
+      public String getCSS_RGBString() {
+         return "rgb(" +
+               getBinaryString()
+               .replace("", " ").trim().replace(" ", ", ")
+               .replace("1", Integer.toString(0xFF)) +
+               ")";
+      }
+
+      public String getHexString() {
+         return "#" + getBinaryString().replace("1", "F");
+      }
+
+      public String getIndex() {
+         return Integer.toString(selectedColorsInBinary + 1);
+      }
+
+      private String getBinaryString() {
+         return getZeroPaddedString(Integer.toBinaryString(selectedColorsInBinary), BINARY_STRING_LENGTH);
+      }
+
+      private static boolean isColorSelected(byte selectedColors, byte colorBitPosition)
{
+         return ((selectedColors >> colorBitPosition) & 1) == 1;
+      }
+
+      public static Iterable<ColorCombo> getAllPossibleCombos() {
+         return new AllPossibleCombosIterable();
+      }
+
+      private static final class AllPossibleCombosIterator implements Iterator<ColorCombo>
{
+
+         // Constants
+         private static final byte ALL_COLORS = 0b111;
+         private static final byte NO_COLORS = 0b000;
+
+         // Data
+         private byte selectedColorsInBinary = NO_COLORS;
+
+         @Override
+         public boolean hasNext() {
+            return selectedColorsInBinary <= ALL_COLORS;
+         }
+
+         @Override
+         public ColorCombo next() {
+
+            if (!hasNext()) {
+               throw new NoSuchElementException();
+            }
+
+            ColorCombo colorCombo = new ColorCombo(selectedColorsInBinary);
+            selectedColorsInBinary++;
+
+            return colorCombo;
+         }
+      }
+
+      private static final class AllPossibleCombosIterable implements Iterable<ColorCombo>
{
+
+         @Override
+         public Iterator<ColorCombo> iterator() {
+            return new AllPossibleCombosIterator();
+         }
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/5ea95519/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/Util.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/Util.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/Util.java
new file mode 100644
index 0000000..f569f0b
--- /dev/null
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/Util.java
@@ -0,0 +1,140 @@
+/*  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 org.apache.portals.pluto.demo.integration.test;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+import static org.openqa.selenium.support.ui.ExpectedConditions.*;
+
+/**
+ *
+ * @author Kyle Stiemann
+ */
+public final class Util {
+
+   private Util() {
+      throw new AssertionError();
+   }
+
+   public static String encodeURL(String url) throws UnsupportedEncodingException {
+	   return URLEncoder.encode(url, StandardCharsets.UTF_8.toString());
+   }
+
+   public static <T> List<T> unmodifiableList(T... items) {
+      return Collections.unmodifiableList(Arrays.asList(items));
+   }
+
+   // Expected Conditions
+   public static ExpectedCondition<Boolean> attributeEmpty(By locator, String attributeName)
{
+      return or(attributeToBe(locator, attributeName, null), attributeToBe(locator, attributeName,
""));
+   }
+
+   public static ExpectedCondition<Boolean> elementNotPresentOrNotVisible(By locator)
{
+      return or(not(presenceOfAllElementsLocatedBy(locator)), invisibilityOfElementLocated(locator));
+   }
+
+   public static ExpectedCondition<Boolean> textEmpty(By locator) {
+      return or(elementNotPresentOrNotVisible(locator), textToBe(locator, ""));
+   }
+
+   // Element Methods
+   public static void clearElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
By locator) {
+
+      waitingAsserter.waitFor(and(visibilityOfElementLocated(locator), new ElementEnabled(locator)));
+      locator.findElement(webDriver).clear();
+   }
+
+   public static void clearElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
String elementTagName,
+         String... elementIdFragments) {
+      clearElement(webDriver, waitingAsserter, getXpath(elementTagName, elementIdFragments));
+   }
+
+   public static void clearElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
String elementXpath) {
+      clearElement(webDriver, waitingAsserter, By.xpath(elementXpath));
+   }
+
+   public static void clickElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
By locator) {
+
+      waitingAsserter.waitFor(and(visibilityOfElementLocated(locator),
+            elementToBeClickable(locator)));
+      locator.findElement(webDriver).click();
+   }
+
+   public static void clickElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
String elementTagName,
+         String... elementIdFragments) {
+      clickElement(webDriver, waitingAsserter, getXpath(elementTagName, elementIdFragments));
+   }
+
+   public static void clickElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
String elementXpath) {
+      clickElement(webDriver, waitingAsserter, By.xpath(elementXpath));
+   }
+
+   public static WebElement findElement(WebDriver webDriver, String elementXpath) {
+      return webDriver.findElement(By.xpath(elementXpath));
+   }
+
+   public static String getXpath(String elementTagName, String... elementIdFragments) {
+      StringBuilder stringBuilder = new StringBuilder();
+      stringBuilder.append("//");
+      stringBuilder.append(elementTagName);
+
+      for (String idFragment : elementIdFragments) {
+         stringBuilder.append("[");
+         stringBuilder.append("contains(@id,'");
+         stringBuilder.append(idFragment);
+         stringBuilder.append("')]");
+      }
+
+      return stringBuilder.toString();
+   }
+
+   public static void sendKeysToElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
By locator,
+         CharSequence... keys) {
+      sendKeysToElement(webDriver, waitingAsserter, true, locator, keys);
+   }
+
+   public static void sendKeysToElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
String elementXpath,
+         CharSequence... keys) {
+      sendKeysToElement(webDriver, waitingAsserter, true, By.xpath(elementXpath), keys);
+   }
+
+   public static void sendKeysToElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
+         boolean clearBeforeSendingKeys, By locator, CharSequence... keys) {
+
+      waitingAsserter.waitFor(and(visibilityOfElementLocated(locator), new ElementEnabled(locator)));
+
+     if (clearBeforeSendingKeys) {
+        clearElement(webDriver, waitingAsserter, locator);
+     }
+
+      locator.findElement(webDriver).sendKeys(keys);
+   }
+
+   public static void sendKeysToElement(WebDriver webDriver, WaitingAsserter waitingAsserter,
+         boolean clearBeforeSendingKeys, String elementXpath, CharSequence... keys) {
+      sendKeysToElement(webDriver, waitingAsserter, clearBeforeSendingKeys, By.xpath(elementXpath),
keys);
+   }
+}

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/5ea95519/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/WaitingAsserter.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/WaitingAsserter.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/WaitingAsserter.java
new file mode 100644
index 0000000..68a27d5
--- /dev/null
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/WaitingAsserter.java
@@ -0,0 +1,49 @@
+/*  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 org.apache.portals.pluto.demo.integration.test;
+
+import org.openqa.selenium.TimeoutException;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+/**
+ *
+ * @author Kyle Stiemann
+ */
+public final class WaitingAsserter {
+
+   private final WebDriverWait webDriverWait;
+
+   public WaitingAsserter(WebDriver driver, long timeOutInSeconds) {
+      this.webDriverWait = new WebDriverWait(driver, timeOutInSeconds);
+   }
+
+   public void assertTrue(ExpectedCondition expectedCondition) {
+
+      try {
+         waitFor(expectedCondition);
+      } catch (TimeoutException e) {
+         throw new AssertionError(e);
+      }
+   }
+
+   public void waitFor(ExpectedCondition expectedCondition) {
+      webDriverWait.until(expectedCondition);
+   }
+}


Mime
View raw message