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 2016/01/20 14:09:16 UTC
svn commit: r1725712 - in /sling/trunk/bundles/resourceresolver: ./
src/test/java/org/apache/sling/resourceresolver/impl/providers/
src/test/java/org/apache/sling/resourceresolver/impl/providers/tree/
Author: rombert
Date: Wed Jan 20 13:09:16 2016
New Revision: 1725712
URL: http://svn.apache.org/viewvc?rev=1725712&view=rev
Log:
SLING-5206 - Create tests for all new features/handling
Add unit tests for PathTree
Added:
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/tree/
sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/tree/PathTreeTest.java
Modified:
sling/trunk/bundles/resourceresolver/pom.xml
Modified: sling/trunk/bundles/resourceresolver/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/pom.xml?rev=1725712&r1=1725711&r2=1725712&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/pom.xml (original)
+++ sling/trunk/bundles/resourceresolver/pom.xml Wed Jan 20 13:09:16 2016
@@ -161,6 +161,12 @@
<!-- Testing -->
<dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
Added: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/tree/PathTreeTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/tree/PathTreeTest.java?rev=1725712&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/tree/PathTreeTest.java (added)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/tree/PathTreeTest.java Wed Jan 20 13:09:16 2016
@@ -0,0 +1,110 @@
+/*
+ * 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.providers.tree;
+
+import static java.util.Arrays.asList;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import org.hamcrest.Matchers;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PathTreeTest {
+
+ private PathTree<Pathable> tree;
+
+ @Before
+ public void createTree() {
+
+ Pathable root = new StringPath("/");
+ Pathable libs = new StringPath("/libs");
+ Pathable libsSling = new StringPath("/libs/sling");
+ Pathable apps = new StringPath("/apps");
+
+ tree = new PathTree<Pathable>(asList(root, libs, libsSling, apps));
+ }
+
+ @Test
+ public void bestMatchForChildNode() {
+
+ assertPathHasBestMatch("/libs", "/libs");
+ assertPathHasExactMatch("/libs");
+ }
+
+ private void assertPathHasBestMatch(String path, String expectedNode) {
+
+ assertThat(tree.getBestMatchingNode(path).getValue().getPath(), equalTo(expectedNode));
+ }
+
+ private void assertPathHasExactMatch(String path) {
+
+ assertThat(tree.getNode(path).getValue().getPath(), equalTo(path));
+ }
+
+ private void assertPathDoesNotHaveExactMatch(String path) {
+
+ assertThat(tree.getNode(path), nullValue());
+ }
+
+ @Test
+ public void bestMatchForChildNodeNested() {
+
+ assertPathHasBestMatch("/apps/sling", "/apps");
+ assertPathDoesNotHaveExactMatch("/apps/sling");
+ }
+
+ @Test
+ public void bestMatchForChildNodeDeeplyNested() {
+
+ assertPathHasBestMatch("/libs/sling/base/install", "/libs/sling");
+ assertPathDoesNotHaveExactMatch("/libs/sling/base/install");
+ }
+
+ @Test
+ public void bestMatchRootNodeFallback() {
+
+ assertPathHasBestMatch("/system", "/");
+ assertPathDoesNotHaveExactMatch("/system");
+ }
+
+ @Test
+ public void bestMatchForInvalidPaths() {
+
+ for ( String invalid : new String[] { null, "", "not/absolute/path"} ) {
+ assertThat("getBestMatchingNode(" + invalid + ")", tree.getBestMatchingNode(invalid), Matchers.nullValue());
+ assertThat("getNode(" + invalid + ")", tree.getNode(invalid), Matchers.nullValue());
+ }
+ }
+
+ static class StringPath implements Pathable {
+
+ private final String path;
+
+ public StringPath(String path) {
+ this.path = path;
+ }
+
+ @Override
+ public String getPath() {
+ return path;
+ }
+ }
+}
\ No newline at end of file