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

[sling-org-apache-sling-dynamic-include] branch master updated: SLING-8377 : including fixes for UrlBuilder and unit tests

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

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-dynamic-include.git


The following commit(s) were added to refs/heads/master by this push:
     new 7de1b2c  SLING-8377 : including fixes for UrlBuilder and unit tests
7de1b2c is described below

commit 7de1b2cc8dc27cbd628eaf171cff8ce2234646ca
Author: briankasingli <br...@gmail.com>
AuthorDate: Fri May 10 10:20:22 2019 +0100

    SLING-8377 : including fixes for UrlBuilder and unit tests
    
    Closes #10
---
 .../sling/dynamicinclude/impl/UrlBuilder.java      |  3 ++
 .../sling/dynamicinclude/impl/UrlBuilderTest.java  | 35 +++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/dynamicinclude/impl/UrlBuilder.java b/src/main/java/org/apache/sling/dynamicinclude/impl/UrlBuilder.java
index 1905866..1182a63 100644
--- a/src/main/java/org/apache/sling/dynamicinclude/impl/UrlBuilder.java
+++ b/src/main/java/org/apache/sling/dynamicinclude/impl/UrlBuilder.java
@@ -55,6 +55,9 @@ public final class UrlBuilder {
     }
 
     private static boolean includeSelectorNotAlreadyPresent(String[] currentSelectors, String includeSelector) {
+        if (includeSelector.isEmpty()) {
+            return false;
+        }
         return !Arrays.asList(currentSelectors).contains(includeSelector);
     }
 }
diff --git a/src/test/java/org/apache/sling/dynamicinclude/impl/UrlBuilderTest.java b/src/test/java/org/apache/sling/dynamicinclude/impl/UrlBuilderTest.java
index c84e7b1..e477efe 100644
--- a/src/test/java/org/apache/sling/dynamicinclude/impl/UrlBuilderTest.java
+++ b/src/test/java/org/apache/sling/dynamicinclude/impl/UrlBuilderTest.java
@@ -53,6 +53,39 @@ public class UrlBuilderTest {
     }
 
     @Test
+    public void shouldNotAppendTheIncludeSelectorToUrlWhenNotSetAndAppendRequestPathInfoSelectorWhenNotSet() {
+        givenAnHtmlRequestForResource("/resource/path");
+        withSelectorString(null);
+        boolean isSyntheticResource = false;
+
+        String actualResult = UrlBuilder.buildUrl("", "apps/example/resource/type", isSyntheticResource, config, requestPathInfo);
+
+        assertThat(actualResult, is("/resource/path.html"));
+    }
+
+    @Test
+    public void shouldNotAppendTheIncludeSelectorToUrlWhenNotSetAndAppendRequestPathInfoSelectorWhenSet() {
+        givenAnHtmlRequestForResource("/resource/path");
+        withSelectorString("foo.bar.baz");
+        boolean isSyntheticResource = false;
+
+        String actualResult = UrlBuilder.buildUrl("", "apps/example/resource/type", isSyntheticResource, config, requestPathInfo);
+
+        assertThat(actualResult, is("/resource/path.foo.bar.baz.html"));
+    }
+
+    @Test
+    public void shouldAppendTheIncludeSelectorToUrlWhenSetAndNotAppendRequestPathInfoSelectorWhenNotSet() {
+        givenAnHtmlRequestForResource("/resource/path");
+        withSelectorString(null);
+        boolean isSyntheticResource = false;
+
+        String actualResult = UrlBuilder.buildUrl("include", "apps/example/resource/type", isSyntheticResource, config, requestPathInfo);
+
+        assertThat(actualResult, is("/resource/path.include.html"));
+    }
+
+    @Test
     public void shouldAppendTheIncludeSelectorToUrlThatAlreadyContainsOtherSelectors() {
         givenAnHtmlRequestForResource("/resource/path");
         withSelectorString("foo.bar.baz");
@@ -135,7 +168,7 @@ public class UrlBuilderTest {
         verify(requestPathInfo,times(0)).getSuffix();
         assertThat(actualResult, is("/resource/path.foo.include.html"));
     }
-    
+
     @Test
     public void shouldAppendExtensionForSyntheticResources() {
         givenAnHtmlRequestForResource("/resource/path");