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 2020/08/18 12:17:02 UTC
[sling-org-apache-sling-resourceresolver] branch master updated
(e4dc1f3 -> 6565453)
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git.
from e4dc1f3 Revert "SLING-8946 implement consistent shadowing of observation"
new 7d283fb SLING-9620 - ResourceMapperImpl.getAllMappings does not respect multi-valued sling:alias
new 6565453 SLING-9620 - ResourceMapperImpl.getAllMappings does not respect multi-valued sling:alias
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:
.../impl/mapping/InMemoryResourceProvider.java | 45 +++++++++++++++++++++-
.../impl/mapping/ResourceMapperImplTest.java | 42 +++++++++++++++++++-
2 files changed, 85 insertions(+), 2 deletions(-)
[sling-org-apache-sling-resourceresolver] 01/02: SLING-9620 -
ResourceMapperImpl.getAllMappings does not respect multi-valued sling:alias
Posted by ro...@apache.org.
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-resourceresolver.git
commit 7d283fb4f0cffa9389f86c8da50815e3eafeb699
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Aug 7 18:12:12 2020 +0200
SLING-9620 - ResourceMapperImpl.getAllMappings does not respect multi-valued sling:alias
Run tests with optimised alias resolution enabled as well.
---
.../impl/mapping/InMemoryResourceProvider.java | 45 +++++++++++++++++++++-
.../impl/mapping/ResourceMapperImplTest.java | 17 +++++++-
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/InMemoryResourceProvider.java b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/InMemoryResourceProvider.java
index 956a25d..52f1fad 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/InMemoryResourceProvider.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/InMemoryResourceProvider.java
@@ -22,17 +22,22 @@ package org.apache.sling.resourceresolver.impl.mapping;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.spi.resource.provider.QueryLanguageProvider;
import org.apache.sling.spi.resource.provider.ResolveContext;
import org.apache.sling.spi.resource.provider.ResourceContext;
import org.apache.sling.spi.resource.provider.ResourceProvider;
+import org.jetbrains.annotations.NotNull;
import org.osgi.service.component.annotations.Component;
@Component(service = ResourceProvider.class)
-public class InMemoryResourceProvider extends ResourceProvider<Void> {
+public class InMemoryResourceProvider extends ResourceProvider<Void>{
private final Map<String, Map<String, Object>> resources = new HashMap<>();
@@ -76,4 +81,42 @@ public class InMemoryResourceProvider extends ResourceProvider<Void> {
resources.put(path, props);
}
+ @Override
+ public QueryLanguageProvider<Void> getQueryLanguageProvider() {
+ return new QueryLanguageProvider<Void>() {
+
+ @Override
+ public String[] getSupportedLanguages(@NotNull ResolveContext<Void> ctx) {
+ return new String[] { "sql" };
+ }
+
+ @Override
+ public Iterator<Resource> findResources(@NotNull ResolveContext<Void> ctx, String query, String language) {
+
+ if ( "SELECT sling:alias FROM nt:base WHERE sling:alias IS NOT NULL".equals(query) ) {
+ return resourcesWithProperty(ctx, "sling:alias")
+ .iterator();
+ }
+
+ if ( "SELECT sling:vanityPath, sling:redirect, sling:redirectStatus FROM nt:base WHERE sling:vanityPath IS NOT NULL".equals(query) ) {
+ return resourcesWithProperty(ctx, "sling:vanityPath")
+ .iterator();
+ }
+
+ throw new UnsupportedOperationException("Unsupported query: '" + query + "'");
+ }
+
+ private List<Resource> resourcesWithProperty(ResolveContext<Void> ctx, String propertyName) {
+ return resources.entrySet().stream()
+ .filter( e -> e.getValue().containsKey(propertyName) )
+ .map( e -> getResource(ctx, e.getKey(), null, null))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Iterator<ValueMap> queryResources(@NotNull ResolveContext<Void> ctx, String query, String language) {
+ throw new UnsupportedOperationException("stub");
+ }
+ };
+ }
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
index 479ff0e..e08cff5 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
@@ -49,6 +49,9 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
/**
* Validates that the {@link ResourceMapperImpl} correctly queries all sources of mappings
@@ -68,14 +71,26 @@ import org.junit.Test;
* module and the Sling ITs cover that.</p>
*
*/
+@RunWith(Parameterized.class)
public class ResourceMapperImplTest {
+ @Parameters(name="optimized alias resolution → {0}")
+ public static Object[] data() {
+ return new Object[] { false, true};
+ }
+
+
@Rule
public final OsgiContext ctx = new OsgiContext();
+ private final boolean optimiseAliasResolution;
private HttpServletRequest req;
private ResourceResolver resolver;
+ public ResourceMapperImplTest(boolean optimiseAliasResolution) {
+ this.optimiseAliasResolution = optimiseAliasResolution;
+ }
+
@Before
public void prepare() throws LoginException {
@@ -102,7 +117,7 @@ public class ResourceMapperImplTest {
ctx.registerService(ResourceProvider.class, resourceProvider, PROPERTY_ROOT, "/", PROPERTY_NAME, "JCR");
// disable optimised alias resolution as it relies on JCR queries
ctx.registerInjectActivateService(new ResourceResolverFactoryActivator(),
- "resource.resolver.optimize.alias.resolution", false);
+ "resource.resolver.optimize.alias.resolution", optimiseAliasResolution);
ResourceResolverFactory factory = ctx.getService(ResourceResolverFactory.class);
[sling-org-apache-sling-resourceresolver] 02/02: SLING-9620 -
ResourceMapperImpl.getAllMappings does not respect multi-valued sling:alias
Posted by ro...@apache.org.
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-resourceresolver.git
commit 656545397fbf62789f5ca0fd225df1a700b13575
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Aug 7 17:09:52 2020 +0200
SLING-9620 - ResourceMapperImpl.getAllMappings does not respect multi-valued sling:alias
Increase coverage - add test for vhost mapping taking priority.
---
.../impl/mapping/ResourceMapperImplTest.java | 25 ++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
index e08cff5..67a00f6 100644
--- a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
+++ b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImplTest.java
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -45,6 +46,7 @@ import org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator;
import org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl;
import org.apache.sling.spi.resource.provider.ResourceProvider;
import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -104,6 +106,9 @@ public class ResourceMapperImplTest {
resourceProvider.putResource("/there", PROP_ALIAS, "alias-value"); // with alias
resourceProvider.putResource("/somewhere", PROP_ALIAS, "alias-value-2"); // with alias and also /etc/map
resourceProvider.putResource("/there/that"); // parent has alias
+ resourceProvider.putResource("/content");
+ resourceProvider.putResource("/content/virtual");
+ resourceProvider.putResource("/content/virtual/foo"); // matches virtual.host.com.80 mapping entry
// build /etc/map structure
resourceProvider.putResource("/etc");
@@ -112,6 +117,8 @@ public class ResourceMapperImplTest {
resourceProvider.putResource("/etc/map/http/localhost_any",
"sling:internalRedirect", "/somewhere",
"sling:match", "localhost.8080/everywhere");
+ resourceProvider.putResource("/etc/map/http/virtual.host.com.80",
+ "sling:internalRedirect", "/content/virtual");
// we fake the fact that we are the JCR resource provider since it's the required one
ctx.registerService(ResourceProvider.class, resourceProvider, PROPERTY_ROOT, "/", PROPERTY_NAME, "JCR");
@@ -219,6 +226,24 @@ public class ResourceMapperImplTest {
.verify(resolver, req);
}
+ @Test
+ public void priorityForVHostMappings() {
+ // override the default request
+ req = mock(HttpServletRequest.class);
+ when(req.getScheme()).thenReturn("http");
+ when(req.getServerName()).thenReturn("virtual.host.com");
+ when(req.getServerPort()).thenReturn(-1);
+ when(req.getContextPath()).thenReturn("");
+ when(req.getPathInfo()).thenReturn(null);
+
+ ExpectedMappings.existingResource("/content/virtual/foo")
+ .singleMapping("http://virtual.host.com/foo")
+ .singleMappingWithRequest("/foo")
+ .allMappings("http://virtual.host.com/foo", "/content/virtual/foo")
+ .allMappingsWithRequest("/foo", "/content/virtual/foo")
+ .verify(resolver, req);
+
+ }
static class ExpectedMappings {
public static ExpectedMappings existingResource(String path) {