You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2023/06/10 13:26:04 UTC
[sling-org-apache-sling-servlets-resolver] 01/01: The LocationCollector returns now Resources
This is an automated email from the ASF dual-hosted git repository.
joerghoh pushed a commit to branch SLING-11558-return-resources
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git
commit a48cee796fffce54035048502f229e9bae2197a2
Author: Jörg Hoh <jo...@joerghoh.de>
AuthorDate: Sat Jun 10 15:24:08 2023 +0200
The LocationCollector returns now Resources
* change the signature
* adapt all testcases
contains some minor duplications, which the next commits should address.
---
.../internal/helper/AbstractResourceCollector.java | 14 +-
.../internal/helper/LocationCollector.java | 30 ++-
.../internal/helper/IsSameResourceList.java | 71 ++++++
.../internal/helper/LocationCollectorTest.java | 255 +++++++++++----------
4 files changed, 231 insertions(+), 139 deletions(-)
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java b/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java
index 9a09dbd..76202c6 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/helper/AbstractResourceCollector.java
@@ -96,18 +96,8 @@ public abstract class AbstractResourceCollector {
});
- List<String> locations = LocationCollector.getLocations(resourceType, resourceSuperType, baseResourceType, resolver);
- locations.forEach(location -> {
- // get the location resource, use a synthetic resource if there
- // is no real location. There may still be children at this
- // location
- final String path;
- if ( location.endsWith("/") ) {
- path = location.substring(0, location.length() - 1);
- } else {
- path = location;
- }
- final Resource locationRes = getResource(resolver, path);
+ List<Resource> locations = LocationCollector.getLocations(resourceType, resourceSuperType, baseResourceType, resolver);
+ locations.forEach(locationRes -> {
getWeightedResources(resources, locationRes);
});
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationCollector.java b/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationCollector.java
index 60b3ff3..ebf2478 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationCollector.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/helper/LocationCollector.java
@@ -27,6 +27,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.SyntheticResource;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.LoggerFactory;
@@ -53,10 +54,24 @@ import org.slf4j.LoggerFactory;
class LocationCollector {
- static @NotNull List<String> getLocations(String resourceType, String resourceSuperType, String baseResourceType,
+ static @NotNull List<Resource> getLocations(String resourceType, String resourceSuperType, String baseResourceType,
ResourceResolver resolver) {
LocationCollector collector = new LocationCollector(resourceType, resourceSuperType, baseResourceType, resolver);
- return collector.getResolvedLocations();
+ List<Resource> result = new ArrayList<>();
+ collector.getResolvedLocations().forEach((location) -> {
+ // get the location resource, use a synthetic resource if there
+ // is no real location. There may still be children at this
+ // location
+ final String path;
+ if ( location.endsWith("/") ) {
+ path = location.substring(0, location.length() - 1);
+ } else {
+ path = location;
+ }
+ final Resource locationRes = getResource(resolver, path);
+ result.add(locationRes);
+ });
+ return result;
}
// The search path of the resource resolver
@@ -208,4 +223,15 @@ class LocationCollector {
}
return rst;
}
+
+ protected static @NotNull Resource getResource(final ResourceResolver resolver, String path) {
+ Resource res = resolver.getResource(path);
+
+ if (res == null) {
+ res = new SyntheticResource(resolver, path, "$synthetic$");
+ }
+
+ return res;
+ }
+
}
diff --git a/src/test/java/org/apache/sling/servlets/resolver/internal/helper/IsSameResourceList.java b/src/test/java/org/apache/sling/servlets/resolver/internal/helper/IsSameResourceList.java
new file mode 100644
index 0000000..bc7c503
--- /dev/null
+++ b/src/test/java/org/apache/sling/servlets/resolver/internal/helper/IsSameResourceList.java
@@ -0,0 +1,71 @@
+/*
+ * 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.sling.servlets.resolver.internal.helper;
+
+import java.util.List;
+
+import org.apache.sling.api.resource.Resource;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+
+/**
+ * Custom matcher which compares the list of resources. For matching just the path
+ * of the resource is considered.
+ *
+ */
+public class IsSameResourceList extends TypeSafeMatcher<List<Resource>>{
+
+ List<Resource> baseLine;
+
+ private IsSameResourceList(List<Resource> baseline) {
+ this.baseLine = baseline;
+ }
+
+ @Override
+ public boolean matchesSafely (List<Resource> item) {
+
+ if (item.size() != baseLine.size()) {
+ return false;
+ }
+ for (int i=0; i < item.size(); i++) {
+ if (!sameResourcePath(item.get(i),baseLine.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("isSameListOfResources for");
+
+ }
+
+
+ private boolean sameResourcePath (Resource a, Resource b) {
+ return a.getPath().equals(b.getPath());
+ }
+
+
+ public static Matcher<List<Resource>> isSameResourceList(List<Resource> baseline) {
+ return new IsSameResourceList(baseline);
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationCollectorTest.java b/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationCollectorTest.java
index f640360..0457d1b 100644
--- a/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationCollectorTest.java
+++ b/src/test/java/org/apache/sling/servlets/resolver/internal/helper/LocationCollectorTest.java
@@ -19,28 +19,28 @@
package org.apache.sling.servlets.resolver.internal.helper;
import static org.apache.sling.api.servlets.ServletResolverConstants.DEFAULT_RESOURCE_TYPE;
+import static org.apache.sling.servlets.resolver.internal.helper.IsSameResourceList.isSameResourceList;
+import static org.hamcrest.MatcherAssert.assertThat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.SyntheticResource;
public class LocationCollectorTest extends HelperTestBase {
- List<String> getLocations(final String resourceType,
+ List<Resource> getLocations(final String resourceType,
final String resourceSuperType) {
return getLocations(resourceType, resourceSuperType, DEFAULT_RESOURCE_TYPE);
}
- List<String> getLocations( final String resourceType,
+ List<Resource> getLocations( final String resourceType,
final String resourceSuperType,
final String baseResourceType) {
return LocationCollector.getLocations(resourceType,
@@ -54,13 +54,13 @@ public class LocationCollectorTest extends HelperTestBase {
resourceResolverOptions.setSearchPaths(null);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- "/" + resourceTypePath, // /foo/bar
- "/" + DEFAULT_RESOURCE_TYPE); // /sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r("/" + resourceTypePath), // /foo/bar
+ r("/" + DEFAULT_RESOURCE_TYPE)); // /sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPath1Element() {
@@ -70,13 +70,13 @@ public class LocationCollectorTest extends HelperTestBase {
});
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- root0 + resourceTypePath, // /apps/foo/bar
- root0 + DEFAULT_RESOURCE_TYPE); // /apps/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(root0 + resourceTypePath), // /apps/foo/bar
+ r(root0 + DEFAULT_RESOURCE_TYPE)); // /apps/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPath2Elements() {
@@ -88,15 +88,15 @@ public class LocationCollectorTest extends HelperTestBase {
});
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- root0 + resourceTypePath, // /apps/foo/bar
- root1 + resourceTypePath, // /libs/foo/bar
- root0 + DEFAULT_RESOURCE_TYPE, // /apps/sling/servlet/default
- root1 + DEFAULT_RESOURCE_TYPE); // /libs/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(root0 + resourceTypePath), // /apps/foo/bar
+ r(root1 + resourceTypePath), // /libs/foo/bar
+ r(root0 + DEFAULT_RESOURCE_TYPE), // /apps/sling/servlet/default
+ r(root1 + DEFAULT_RESOURCE_TYPE)); // /libs/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
/**
@@ -130,13 +130,13 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(resourceType, null);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- resourceTypePath, // /foo/bar
- "/" + DEFAULT_RESOURCE_TYPE); // /sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(resourceTypePath), // /foo/bar
+ r("/" + DEFAULT_RESOURCE_TYPE)); // /sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPath1ElementAbsoluteType() {
@@ -151,14 +151,14 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(resourceType, null);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- resourceTypePath, // /foo/bar
- root0 + DEFAULT_RESOURCE_TYPE); // /apps/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(resourceTypePath), // /foo/bar
+ r(root0 + DEFAULT_RESOURCE_TYPE)); // /apps/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPath2ElementsAbsoluteType() {
@@ -175,14 +175,14 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(resourceType, null);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- resourceTypePath, // /foo/bar
- root0 + DEFAULT_RESOURCE_TYPE, // /apps/sling/servlet/default
- root1 + DEFAULT_RESOURCE_TYPE); // /libs/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(resourceTypePath), // /foo/bar
+ r(root0 + DEFAULT_RESOURCE_TYPE), // /apps/sling/servlet/default
+ r(root1 + DEFAULT_RESOURCE_TYPE)); // /libs/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPathEmptyWithSuper() {
@@ -195,14 +195,14 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(null, resourceSuperType);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- "/" + resourceTypePath, // /foo/bar
- "/" + resourceSuperTypePath, // /foo/superBar
- "/" + DEFAULT_RESOURCE_TYPE); // /sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r("/" + resourceTypePath), // /foo/bar
+ r("/" + resourceSuperTypePath), // /foo/superBar
+ r("/" + DEFAULT_RESOURCE_TYPE)); // /sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPath1ElementWithSuper() {
@@ -217,14 +217,14 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(null, resourceSuperType);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- root0 + resourceTypePath, // /apps/foo/bar
- root0 + resourceSuperTypePath, // /apps/foo/superBar
- root0 + DEFAULT_RESOURCE_TYPE); // /apps/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(root0 + resourceTypePath), // /apps/foo/bar
+ r(root0 + resourceSuperTypePath), // /apps/foo/superBar
+ r(root0 + DEFAULT_RESOURCE_TYPE)); // /apps/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPath2ElementsWithSuper() {
@@ -241,17 +241,17 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(null, resourceSuperType);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- root0 + resourceTypePath, // /apps/foo/bar
- root1 + resourceTypePath, // /libs/foo/bar
- root0 + resourceSuperTypePath, // /apps/foo/superBar
- root1 + resourceSuperTypePath, // /libs/foo/superBar
- root0 + DEFAULT_RESOURCE_TYPE, // /apps/sling/servlet/default
- root1 + DEFAULT_RESOURCE_TYPE); // /libs/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(root0 + resourceTypePath), // /apps/foo/bar
+ r(root1 + resourceTypePath), // /libs/foo/bar
+ r(root0 + resourceSuperTypePath), // /apps/foo/superBar
+ r(root1 + resourceSuperTypePath), // /libs/foo/superBar
+ r(root0 + DEFAULT_RESOURCE_TYPE), // /apps/sling/servlet/default
+ r(root1 + DEFAULT_RESOURCE_TYPE)); // /libs/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPathEmptyAbsoluteTypeWithSuper() {
@@ -268,14 +268,14 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(resourceType, resourceSuperType);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- resourceTypePath, // /foo/bar
- "/" + resourceSuperTypePath, // /foo/superBar
- "/" + DEFAULT_RESOURCE_TYPE); // /sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(resourceTypePath), // /foo/bar
+ r("/" + resourceSuperTypePath), // /foo/superBar
+ r("/" + DEFAULT_RESOURCE_TYPE)); // /sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPath1ElementAbsoluteTypeWithSuper() {
@@ -294,14 +294,14 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(resourceType, resourceSuperType);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- resourceTypePath, // /foo/bar
- root0 + resourceSuperTypePath, // /apps/foo/superBar
- root0 + DEFAULT_RESOURCE_TYPE); // /apps/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(resourceTypePath), // /foo/bar
+ r(root0 + resourceSuperTypePath), // /apps/foo/superBar
+ r(root0 + DEFAULT_RESOURCE_TYPE)); // /apps/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testSearchPath2ElementsAbsoluteTypeWithSuper() {
@@ -322,16 +322,16 @@ public class LocationCollectorTest extends HelperTestBase {
replaceResource(resourceType, resourceSuperType);
final Resource r = request.getResource();
- List<String> loc = getLocations(r.getResourceType(),
+ List<Resource> loc = getLocations(r.getResourceType(),
r.getResourceSuperType());
- List<String> expected = Arrays.asList(
- resourceTypePath, // /foo/bar
- root0 + resourceSuperTypePath, // /apps/foo/superBar
- root1 + resourceSuperTypePath, // /libs/foo/superBar
- root0 + DEFAULT_RESOURCE_TYPE, // /apps/sling/servlet/default
- root1 + DEFAULT_RESOURCE_TYPE); // /libs/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(resourceTypePath), // /foo/bar
+ r(root0 + resourceSuperTypePath), // /apps/foo/superBar
+ r(root1 + resourceSuperTypePath), // /libs/foo/superBar
+ r(root0 + DEFAULT_RESOURCE_TYPE), // /apps/sling/servlet/default
+ r(root1 + DEFAULT_RESOURCE_TYPE)); // /libs/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testScriptNameWithoutResourceType() {
@@ -341,11 +341,13 @@ public class LocationCollectorTest extends HelperTestBase {
root0,
root1
});
- List<String> loc = getLocations("",
+ List<Resource> loc = getLocations("",
null,"");
- List<String> expected = Arrays.asList("/apps/","/libs/");
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r("/apps"),
+ r("/libs"));
+ assertThat(loc,isSameResourceList(expected));
}
public void testScriptNameWithResourceType() {
@@ -355,14 +357,14 @@ public class LocationCollectorTest extends HelperTestBase {
root0,
root1
});
- List<String> loc = getLocations("a/b", null);
+ List<Resource> loc = getLocations("a/b", null);
- List<String> expected = Arrays.asList(
- root0 + "a/b",
- root1 + "a/b",
- root0 + DEFAULT_RESOURCE_TYPE,
- root1 + DEFAULT_RESOURCE_TYPE);
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(root0 + "a/b"),
+ r(root1 + "a/b"),
+ r(root0 + DEFAULT_RESOURCE_TYPE),
+ r(root1 + DEFAULT_RESOURCE_TYPE));
+ assertThat(loc,isSameResourceList(expected));
}
public void testScriptNameWithResourceTypeAndSuperType() {
@@ -373,16 +375,16 @@ public class LocationCollectorTest extends HelperTestBase {
root1
});
- List<String> loc = getLocations("a/b", "c/d");
-
- List<String> expected = Arrays.asList(
- root0 + "a/b",
- root1 + "a/b",
- root0 + "c/d",
- root1 + "c/d",
- root0 + DEFAULT_RESOURCE_TYPE,
- root1 + DEFAULT_RESOURCE_TYPE);
- assertThat(loc,is(expected));
+ List<Resource> loc = getLocations("a/b", "c/d");
+
+ List<Resource> expected = Arrays.asList(
+ r(root0 + "a/b"),
+ r(root1 + "a/b"),
+ r(root0 + "c/d"),
+ r(root1 + "c/d"),
+ r(root0 + DEFAULT_RESOURCE_TYPE),
+ r(root1 + DEFAULT_RESOURCE_TYPE));
+ assertThat(loc,isSameResourceList(expected));
}
public void testCircularResourceTypeHierarchy() {
@@ -420,28 +422,27 @@ public class LocationCollectorTest extends HelperTestBase {
fail("Did not expect a persistence exception: " + e.getMessage());
}
- List<String> loc = getLocations(resourceType, resourceSuperType);
+ List<Resource> loc = getLocations(resourceType, resourceSuperType);
- List<String> expected = Arrays.asList(
- root1 + resourceType, // /libs/foo/bar
- root1 + resourceSuperType, // /libs/foo/check1
- root1 + resourceSuperType2, // /libs/foo/check2
- root1 + DEFAULT_RESOURCE_TYPE); // /libs/sling/servlet/default
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r(root1 + resourceType), // /libs/foo/bar
+ r(root1 + resourceSuperType), // /libs/foo/check1
+ r(root1 + resourceSuperType2), // /libs/foo/check2
+ r(root1 + DEFAULT_RESOURCE_TYPE)); // /libs/sling/servlet/default
+ assertThat(loc,isSameResourceList(expected));
}
public void testResolveDefaultResourceType() {
- List<String> loc = getLocations(DEFAULT_RESOURCE_TYPE, resourceSuperType);
+ List<Resource> loc = getLocations(DEFAULT_RESOURCE_TYPE, resourceSuperType);
- List<String> expected = Arrays.asList(
- "/apps/sling/servlet/default",
- "/libs/sling/servlet/default",
- "/apps/sling/servlet/default",
- "/libs/sling/servlet/default"
- );
- assertThat(loc,is(expected));
+ List<Resource> expected = Arrays.asList(
+ r("/apps/sling/servlet/default"),
+ r("/libs/sling/servlet/default"),
+ r("/apps/sling/servlet/default"),
+ r("/libs/sling/servlet/default"));
+ assertThat(loc,isSameResourceList(expected));
}
@@ -467,14 +468,14 @@ public class LocationCollectorTest extends HelperTestBase {
ResourceUtil.getName(resourceSuperTypePath), null);
- List<String> loc = getLocations(resourceType, resourceSuperType);
+ List<Resource> loc = getLocations(resourceType, resourceSuperType);
- List<String> expected = Arrays.asList(
- resourceTypePath, // /apps/a/b
- resourceSuperTypePath, // /apps/c/d
- root + DEFAULT_RESOURCE_TYPE // /apps/sling/servlet/default
+ List<Resource> expected = Arrays.asList(
+ r(resourceTypePath), // /apps/a/b
+ r(resourceSuperTypePath), // /apps/c/d
+ r(root + DEFAULT_RESOURCE_TYPE) // /apps/sling/servlet/default
);
- assertThat(loc,is(expected));
+ assertThat(loc,isSameResourceList(expected));
}
@@ -494,13 +495,17 @@ public class LocationCollectorTest extends HelperTestBase {
ResourceUtil.getName(resourceTypePath), resourceTypeProps);
- List<String> loc = getLocations(resourceType, resourceSuperType);
+ List<Resource> loc = getLocations(resourceType, resourceSuperType);
- List<String> expected = Arrays.asList(
- resourceTypePath, // /apps/a/b
- root + DEFAULT_RESOURCE_TYPE // /apps/sling/servlet/default
+ List<Resource> expected = Arrays.asList(
+ r(resourceTypePath), // /apps/a/b
+ r(root + DEFAULT_RESOURCE_TYPE) // /apps/sling/servlet/default
);
- assertThat(loc,is(expected));
+ assertThat(loc,isSameResourceList(expected));
+ }
+
+ private Resource r (String path) {
+ return new SyntheticResource(resourceResolver, path, "resourcetype");
}
}