You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by du...@apache.org on 2020/02/14 10:38:08 UTC

[sling-org-apache-sling-testing-clients] branch master updated (470d771 -> f38f391)

This is an automated email from the ASF dual-hosted git repository.

dulvac pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-clients.git.


    from 470d771  Bump jackson-databind from 2.9.4 to 2.9.10.1
     new d742145  SLING-9069 Polling format exception in case of TimeoutException
     new f38f391  trivial: Added a few more test values + fix pom tag

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |  2 +-
 .../sling/testing/clients/AbstractSlingClient.java |  2 +-
 .../sling/testing/clients/util/poller/Polling.java | 13 ++++-
 .../testing/AbstractSlingClientGetPathTest.java    | 14 ++++++
 .../clients/SlingClientConstructorTest.java        | 27 +++++++++-
 .../testing/clients/util/poller/PollingTest.java   | 57 +++++++++++-----------
 6 files changed, 81 insertions(+), 34 deletions(-)


[sling-org-apache-sling-testing-clients] 02/02: trivial: Added a few more test values + fix pom tag

Posted by du...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dulvac pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-clients.git

commit f38f3914a8b665facbdc50267106e35ee9236a9c
Author: Andrei Dulvac <ad...@adobe.com>
AuthorDate: Fri Feb 14 11:37:40 2020 +0100

    trivial: Added a few more test values + fix pom tag
---
 pom.xml                                            |  2 +-
 .../sling/testing/clients/AbstractSlingClient.java |  2 +-
 .../testing/AbstractSlingClientGetPathTest.java    | 14 +++++++++++
 .../clients/SlingClientConstructorTest.java        | 27 +++++++++++++++++++++-
 4 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/pom.xml b/pom.xml
index db4b828..257cb2a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,7 @@
         <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-clients.git</connection>
         <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-clients.git</developerConnection>
         <url>https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-testing-clients.git</url>
-      <tag>org.apache.sling.testing.clients-1.2.4</tag>
+        <tag>HEAD</tag>
   </scm>
     
     <build>
diff --git a/src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java b/src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java
index 3a953ca..117a475 100644
--- a/src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java
+++ b/src/main/java/org/apache/sling/testing/clients/AbstractSlingClient.java
@@ -154,7 +154,7 @@ public class AbstractSlingClient implements HttpClient, Closeable {
         // add server url and path
         URIBuilder uriBuilder = new URIBuilder(getUrl(path));
         // add parameters
-        if(parameters != null) {
+        if (parameters != null) {
             uriBuilder.addParameters(parameters);
         }
 
diff --git a/src/test/java/org/apache/sling/testing/AbstractSlingClientGetPathTest.java b/src/test/java/org/apache/sling/testing/AbstractSlingClientGetPathTest.java
index 64f4c73..69b0d0b 100644
--- a/src/test/java/org/apache/sling/testing/AbstractSlingClientGetPathTest.java
+++ b/src/test/java/org/apache/sling/testing/AbstractSlingClientGetPathTest.java
@@ -113,6 +113,7 @@ public class AbstractSlingClientGetPathTest {
                 {"http://HOST:4502/CTX/",    "http://HOST:4502/CTX/my",           "/my"},
                 {"http://HOST:4502/CTX/",    "http://HOST:4502/CTX/",             "/"},
                 {"http://HOST:4502/CTX/",    "http://HOST:4502/CTX",              "/"},
+
                 {"http://HOST:4502/CTX/",    "/CTX",                              "/"},
                 {"http://HOST:4502/CTX/",    "/CTX/",                             "/"},
                 {"http://HOST:4502/CTX/",    "/CTX/page.html",                    "/page.html"},
@@ -130,6 +131,19 @@ public class AbstractSlingClientGetPathTest {
                 {"http://HOST:4502/CTX/",    "my",                                "/my"},
                 {"http://HOST:4502/CTX/",    "",                                  "/"},
 
+                {"http://HOST:4502/CTX/",    "/CTX/?param=value",                   "/?param=value"},
+                {"http://HOST:4502/CTX/",    "/CTX/page.html?param=value",          "/page.html?param=value"},
+                {"http://HOST:4502/CTX/",    "/page.html?param=value",              "/page.html?param=value"},
+                {"http://HOST:4502/CTX/",    "/my/page.html?param=value",           "/my/page.html?param=value"},
+                {"http://HOST:4502/CTX/",    "/my/?param=value",                    "/my/?param=value"},
+                {"http://HOST:4502/CTX/",    "/my?param=value",                     "/my?param=value"},
+                {"http://HOST:4502/CTX/",    "CTX/?param=value",                    "/?param=value"},
+                {"http://HOST:4502/CTX/",    "CTX/page.html?param=value",           "/page.html?param=value"},
+                {"http://HOST:4502/CTX/",    "page.html?param=value",               "/page.html?param=value"},
+                {"http://HOST:4502/CTX/",    "my/page.html?param=value",            "/my/page.html?param=value"},
+                {"http://HOST:4502/CTX/",    "my/?param=value",                     "/my/?param=value"},
+                {"http://HOST:4502/CTX/",    "my?param=value",                      "/my?param=value"},
+
                 {"http://HOST:4502/CTX/",    "http://www.google.com",             "http://www.google.com"},
         });
     }
diff --git a/src/test/java/org/apache/sling/testing/clients/SlingClientConstructorTest.java b/src/test/java/org/apache/sling/testing/clients/SlingClientConstructorTest.java
index ed4bf08..4ae3caf 100644
--- a/src/test/java/org/apache/sling/testing/clients/SlingClientConstructorTest.java
+++ b/src/test/java/org/apache/sling/testing/clients/SlingClientConstructorTest.java
@@ -35,13 +35,30 @@ public class SlingClientConstructorTest {
 
     @Test
     public void testConstructorUrlHttp() throws Exception {
+        URI url = URI.create("http://example.com");
+        URI expected = URI.create("http://example.com/");
+        SlingClient c = new SlingClient(url, "user", "pass");
+        assertEquals(expected, c.getUrl());
+    }
+
+    @Test
+    public void testConstructorUrlHttpTrailingSlash() throws Exception {
         URI url = URI.create("http://example.com/");
+        URI expected = URI.create("http://example.com/");
         SlingClient c = new SlingClient(url, "user", "pass");
-        assertEquals(url, c.getUrl());
+        assertEquals(expected, c.getUrl());
     }
 
     @Test
     public void testConstructorUrlHttps() throws Exception {
+        URI url = URI.create("https://example.com");
+        URI expected = URI.create("https://example.com/");
+        SlingClient c = new SlingClient(url, "user", "pass");
+        assertEquals(expected, c.getUrl());
+    }
+
+    @Test
+    public void testConstructorUrlHttpsTrailingSlash() throws Exception {
         URI url = URI.create("https://example.com/");
         SlingClient c = new SlingClient(url, "user", "pass");
         assertEquals(url, c.getUrl());
@@ -49,6 +66,14 @@ public class SlingClientConstructorTest {
 
     @Test
     public void testConstructorUrlBasePath() throws Exception {
+        URI url = URI.create("https://example.com/mypath");
+        URI expected = URI.create("https://example.com/mypath/");
+        SlingClient c = new SlingClient(url, "user", "pass");
+        assertEquals(expected, c.getUrl());
+    }
+
+    @Test
+    public void testConstructorUrlBasePathTrailingSlash() throws Exception {
         URI url = URI.create("https://example.com/mypath/");
         SlingClient c = new SlingClient(url, "user", "pass");
         assertEquals(url, c.getUrl());


[sling-org-apache-sling-testing-clients] 01/02: SLING-9069 Polling format exception in case of TimeoutException

Posted by du...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dulvac pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-clients.git

commit d742145cf07315055dfeb6e9b039e725372a8bf4
Author: Andrei Dulvac <ad...@adobe.com>
AuthorDate: Fri Feb 14 11:36:46 2020 +0100

    SLING-9069 Polling format exception in case of TimeoutException
---
 .../sling/testing/clients/util/poller/Polling.java | 13 ++++-
 .../testing/clients/util/poller/PollingTest.java   | 57 +++++++++++-----------
 2 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/clients/util/poller/Polling.java b/src/main/java/org/apache/sling/testing/clients/util/poller/Polling.java
index 60296de..6de95ef 100644
--- a/src/main/java/org/apache/sling/testing/clients/util/poller/Polling.java
+++ b/src/main/java/org/apache/sling/testing/clients/util/poller/Polling.java
@@ -124,7 +124,8 @@ public class Polling implements Callable<Boolean> {
         } while (System.currentTimeMillis() < start + effectiveTimeout);
 
         waited = System.currentTimeMillis() - start;
-        throw new TimeoutException(String.format(message(), effectiveTimeout, delay));
+        throw new TimeoutException(String.format(message(), effectiveTimeout, delay) +
+                " Last exception was: " + lastException);
     }
 
     public long getWaited() {
@@ -139,6 +140,14 @@ public class Polling implements Callable<Boolean> {
      * @return the format string
      */
     protected String message() {
-        return "Call failed to return true in %1$d ms. Last exception was: " + lastException;
+        return "Call failed to return true in %1$d ms.";
+    }
+
+    /**
+     * Return the last exception while polling or {null}
+     * @return
+     */
+    public Exception getLastException() {
+        return lastException;
     }
 }
diff --git a/src/test/java/org/apache/sling/testing/clients/util/poller/PollingTest.java b/src/test/java/org/apache/sling/testing/clients/util/poller/PollingTest.java
index 15994ed..adf75f1 100644
--- a/src/test/java/org/apache/sling/testing/clients/util/poller/PollingTest.java
+++ b/src/test/java/org/apache/sling/testing/clients/util/poller/PollingTest.java
@@ -18,11 +18,9 @@ package org.apache.sling.testing.clients.util.poller;
 
 import org.apache.commons.lang3.mutable.MutableBoolean;
 import org.apache.commons.lang3.mutable.MutableInt;
+import org.junit.Assert;
 import org.junit.Test;
-
-import java.util.concurrent.Callable;
 import java.util.concurrent.TimeoutException;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -106,12 +104,9 @@ public class PollingTest {
     public void testCallableOnce() throws Exception {
         final MutableInt callCount = new MutableInt(0);
         final MutableBoolean called = new MutableBoolean(false);
-        Polling p = new Polling(new Callable<Boolean>() {
-            @Override
-            public Boolean call() throws Exception {
-                callCount.increment();
-                return true;
-            }
+        Polling p = new Polling(() -> {
+            callCount.increment();
+            return true;
         });
         p.poll(500, 10);
 
@@ -122,14 +117,11 @@ public class PollingTest {
     public void testCallableTwice() throws Exception {
         final MutableInt callCount = new MutableInt(0);
         final MutableBoolean called = new MutableBoolean(false);
-        Polling p = new Polling(new Callable<Boolean>() {
-            @Override
-            public Boolean call() throws Exception {
-                callCount.increment();
-                boolean b = called.booleanValue();
-                called.setTrue();
-                return b;
-            }
+        Polling p = new Polling(() -> {
+            callCount.increment();
+            boolean b = called.booleanValue();
+            called.setTrue();
+            return b;
         });
         p.poll(500, 10);
 
@@ -139,12 +131,9 @@ public class PollingTest {
     @Test
     public void testCallableTimeout() throws Exception {
         final MutableInt callCount = new MutableInt(0);
-        Polling p = new Polling(new Callable<Boolean>() {
-            @Override
-            public Boolean call() throws Exception {
-                callCount.increment();
-                return false;
-            }
+        Polling p = new Polling(() -> {
+            callCount.increment();
+            return false;
         });
 
         try {
@@ -161,12 +150,7 @@ public class PollingTest {
 
     @Test
     public void testCallPriority() throws Exception {
-        Polling p = new Polling(new Callable<Boolean>() {
-            @Override
-            public Boolean call() throws Exception {
-                return false;
-            }
-        }) {
+        Polling p = new Polling(() -> false) {
             @Override
             public Boolean call() throws Exception {
                 return true;
@@ -176,4 +160,19 @@ public class PollingTest {
         // Should not reach timeout since overridden call() has priority over Callable param
         p.poll(100, 10);
     }
+
+    @Test
+    public void testCallThrowException() throws Exception {
+        Polling p = new Polling(() -> {
+          throw new RuntimeException("%Failure");
+        });
+        try {
+            p.poll(100, 10);
+        } catch (TimeoutException e) {
+            Assert.assertTrue("Timeout message should contain original message", e.getMessage().contains("%Failure"));
+        }
+
+    }
+
+
 }
\ No newline at end of file