You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2020/08/10 13:18:31 UTC

[GitHub] [sling-org-apache-sling-resourceresolver] jsedding commented on a change in pull request #18: SLING-9620 ResourceMapperImpl.getAllMappings does not respect multi-valued sling:alias

jsedding commented on a change in pull request #18:
URL: https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/18#discussion_r467896090



##########
File path: src/test/java/org/apache/sling/resourceresolver/impl/mapping/PathGeneratorTest.java
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.resourceresolver.impl.mapping;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+public class PathGeneratorTest {
+
+    @Test
+    public void rootPath() {
+        
+        List<String> paths = new PathGenerator().generatePaths();
+        
+        assertThat(paths, Matchers.hasSize(1));
+        assertThat(paths, Matchers.hasItem("/"));
+    }
+
+    @Test
+    public void subPathWithMissingAliases() {
+        
+        PathGenerator builder = new PathGenerator();
+        builder.insertSegment(singletonList(null), "bar");
+        builder.insertSegment(singletonList(""), "foo");
+        List<String> paths = builder.generatePaths();
+        
+        assertThat(paths, Matchers.hasSize(1));
+        assertThat(paths, Matchers.hasItem("/foo/bar"));
+    }
+
+    @Test
+    public void subPathWithMixedAliases() {
+        
+        PathGenerator builder = new PathGenerator();
+        builder.insertSegment(emptyList(), "bar");
+        builder.insertSegment(singletonList("super"), "foo");
+        List<String> paths = builder.generatePaths();
+        
+        assertThat(paths, Matchers.hasSize(1));
+        assertThat(paths, Matchers.hasItem("/super/bar"));
+    }
+    
+    @Test
+    public void subPathWithResolutionInfo() {
+        
+        PathGenerator builder = new PathGenerator();
+        builder.insertSegment(emptyList(), "bar");
+        builder.insertSegment(emptyList(), "foo");
+        builder.setResolutionPathInfo("/baz");
+        
+        List<String> paths = builder.generatePaths();
+        
+        assertThat(paths, Matchers.hasSize(1));
+        assertThat(paths, Matchers.hasItem("/foo/bar/baz"));        
+    }
+    
+    @Test
+    public void subPathWithMultipleAliases() {
+        
+        PathGenerator builder = new PathGenerator();
+        builder.insertSegment(emptyList(), "bar");
+        builder.insertSegment(asList("alias1", "alias2"), "foo");
+        
+        List<String> paths = builder.generatePaths();
+        
+        assertThat(paths, Matchers.hasSize(2));
+        assertThat(paths, Matchers.hasItems("/alias1/bar", "/alias2/bar"));

Review comment:
       @rombert What is the reason that `PathGenerator` does not generate permutations of the path including the node-name? I.e. I'd expect `Matchers.hasItems("/alias1/bar", "/alias2/bar", "/foo/bar")` (probably in this order, if the first entry is what should happen when mapping a resource path to a URL path).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org