portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asfgr...@apache.org
Subject [06/22] portals-pluto git commit: PLUTO-733 Add Multipart Form Portlet Demo test
Date Thu, 25 Oct 2018 20:19:38 GMT
PLUTO-733 Add Multipart Form Portlet Demo test


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

Branch: refs/heads/master
Commit: f821c1659ba891211103b69a837957e1520c6cd3
Parents: 429e011
Author: Kyle Stiemann <stiemannkj1@gmail.com>
Authored: Thu Oct 11 13:04:46 2018 -0400
Committer: Neil Griffin <neil.griffin.scm@gmail.com>
Committed: Thu Oct 25 15:48:30 2018 -0400

----------------------------------------------------------------------
 .../demo/integration/test/ChatRoomDemoIT.java   |  2 +-
 .../demo/integration/test/DemoTestDriver.java   |  4 ++
 .../demo/integration/test/DependencyDemoIT.java |  2 +-
 .../integration/test/MultipartFormDemoIT.java   | 73 ++++++++++++++++++++
 .../demo/integration/test/PortletHubDemoIT.java |  2 +-
 .../pluto/demo/integration/test/Util.java       | 15 +++-
 6 files changed, 93 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f821c165/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
index e3f953c..a2c1d51 100644
--- a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
@@ -45,7 +45,7 @@ public class ChatRoomDemoIT extends DemoTestDriver {
 
       // 2. Open a new window/tab to the same page.
       String originalWindowHandle = driver.getWindowHandle();
-      ((JavascriptExecutor)driver).executeScript("window.open('" + chatDemoURL + "');");
+      executeScript(driver, "window.open('" + chatDemoURL + "');");
 
       // 3. In the current window/tab, add a user named "me".
       // 4. Verify that an image appears for the user.

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f821c165/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
index 6ccd254..3f272a1 100644
--- 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
@@ -35,4 +35,8 @@ public class DemoTestDriver extends SimpleTestDriver {
          waitingAsserter = new WaitingAsserter(driver, timeout);
       }
    }
+
+   protected void navigateToPage(String pageName) {
+      driver.get(baseUrl + Util.encodeURL(pageName));
+   }
 }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f821c165/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DependencyDemoIT.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DependencyDemoIT.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DependencyDemoIT.java
index ac749f5..efa7d43 100644
--- a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DependencyDemoIT.java
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/DependencyDemoIT.java
@@ -32,7 +32,7 @@ public class DependencyDemoIT extends DemoTestDriver{
 
    @Test
    public void testDependencyDemo() {
-      driver.get(baseUrl + "Dependencies");
+      navigateToPage("Dependencies");
       assertBadDependencyStringThrewException("String: Hi there!",
             "Exception: java.lang.IllegalArgumentException:");
       assertBadDependencyStringThrewException("String: <script dffsfssf",

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f821c165/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/MultipartFormDemoIT.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/MultipartFormDemoIT.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/MultipartFormDemoIT.java
new file mode 100644
index 0000000..1782d1a
--- /dev/null
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/MultipartFormDemoIT.java
@@ -0,0 +1,73 @@
+/*  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.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Locale;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import static org.apache.portals.pluto.demo.integration.test.Util.*;
+import static org.openqa.selenium.support.ui.ExpectedConditions.*;
+
+/**
+ *
+ * @author Kyle Stiemann
+ */
+public class MultipartFormDemoIT extends DemoTestDriver {
+
+   @Test
+   public void testMultipartFormDemo() throws IOException {
+      navigateToPage("File Upload");
+      By colorPickerByXpath = By.xpath("//input[@type='color']");
+      waitingAsserter.waitFor(and(visibilityOfElementLocated(colorPickerByXpath),
+            new ElementEnabled(colorPickerByXpath)));
+
+      String color = "#FFFFFF";
+      WebElement colorPicker = driver.findElement(colorPickerByXpath);
+      executeScript(driver, "arguments[0].value = '" + color + "'", colorPicker);
+
+      String fileNamePrefix = "pluto-test-";
+      Path tempFilePath = Files.createTempFile(fileNamePrefix, ".txt");
+      File tempFile = tempFilePath.toFile();
+      tempFile.deleteOnExit();
+
+      String text = "Test text.";
+      try (PrintWriter out = new PrintWriter(tempFile)) {
+         out.println(text);
+      }
+
+      sendKeysToElement(driver, waitingAsserter, "//input[@type='file']", tempFilePath.toString());
+      clickElement(driver, waitingAsserter, "//input[@type='submit'][@value='submit']");
+
+      By fileInfoByXpath = By.xpath("//h5[text()='Info:']/..");
+      waitingAsserter.assertTrue(and(visibilityOfElementLocated(fileInfoByXpath),
+            textToBePresentInElementLocated(fileInfoByXpath, "Color: " + color.toLowerCase(Locale.ENGLISH)),
+            textToBePresentInElementLocated(fileInfoByXpath, "Uploaded file name: " + fileNamePrefix),
+            textToBePresentInElementLocated(fileInfoByXpath, "content-type=[text/plain]")));
+
+      By fileContentsByXpath = By.xpath("//h5[text()='File contents:']/..");
+      waitingAsserter.assertTrue(and(visibilityOfElementLocated(fileContentsByXpath),
+            textToBePresentInElementLocated(fileContentsByXpath, text)));
+   }
+}

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f821c165/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
index 1d1119c..45155bc 100644
--- 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
@@ -51,7 +51,7 @@ public class PortletHubDemoIT extends DemoTestDriver {
 
    @Test
    public void testPortletHubDemo() throws UnsupportedEncodingException {
-      driver.get(baseUrl + Util.encodeURL("V3.0 Portlet Hub Demo"));
+      navigateToPage("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"));

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f821c165/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
index f569f0b..ac14997 100644
--- 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
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.support.ui.ExpectedCondition;
@@ -39,8 +40,18 @@ public final class Util {
       throw new AssertionError();
    }
 
-   public static String encodeURL(String url) throws UnsupportedEncodingException {
-	   return URLEncoder.encode(url, StandardCharsets.UTF_8.toString());
+   public static String encodeURL(String url) {
+
+      try {
+         return URLEncoder.encode(url, StandardCharsets.UTF_8.toString());
+      }
+      catch (UnsupportedEncodingException e) {
+        throw new RuntimeException(e);
+      }
+   }
+
+   public static Object executeScript(WebDriver webDriver, String script, Object... arguments)
{
+      return ((JavascriptExecutor)webDriver).executeScript(script, arguments);
    }
 
    public static <T> List<T> unmodifiableList(T... items) {


Mime
View raw message