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

rombert pushed a commit to annotated tag 
org.apache.sling.testing.sling-mock-1.3.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 28f1b00d5c2e594cd33161194b3a9d7b8e1438c9
Author: Stefan Seifert <[email protected]>
AuthorDate: Wed May 13 16:52:33 2015 +0000

    SLING-4654 Support ResourceResolver.findResources with JCR_MOCK
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1679239 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../mock/sling/MockJcrResourceResolverFactory.java |  5 ++
 .../sling/jcrmock/resource/FindResourcesTest.java  | 68 ++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git 
a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
 
b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
index 69a8af7..816f9a6 100644
--- 
a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
+++ 
b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
@@ -24,7 +24,10 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 
+import javax.jcr.query.Query;
+
 import org.apache.sling.api.resource.LoginException;
+import org.apache.sling.api.resource.QueriableResourceProvider;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceResolverFactory;
@@ -56,6 +59,7 @@ class MockJcrResourceResolverFactory implements 
ResourceResolverFactory {
         this.bundleContext = bundleContext;
     }
 
+    @SuppressWarnings("deprecation")
     private ResourceResolver getResourceResolverInternal(Map<String, Object> 
authenticationInfo, boolean isAdmin) throws LoginException {
         Dictionary<String, Object> resourceProviderFactoryFactoryProps = new 
Hashtable<String, Object>();
         resourceProviderFactoryFactoryProps.put(Constants.SERVICE_VENDOR, 
"sling-mock");
@@ -85,6 +89,7 @@ class MockJcrResourceResolverFactory implements 
ResourceResolverFactory {
 
         Dictionary<Object, Object> resourceProviderProps = new 
Hashtable<Object, Object>();
         resourceProviderProps.put(ResourceProvider.ROOTS, new String[] { "/" 
});
+        resourceProviderProps.put(QueriableResourceProvider.LANGUAGES, new 
String[] { Query.XPATH, Query.SQL, Query.JCR_SQL2 });
 
         // setup real sling resource resolver implementation for use in mocked 
context
         MockResourceResolverFactoryActivator activator = new 
MockResourceResolverFactoryActivator();
diff --git 
a/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/FindResourcesTest.java
 
b/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/FindResourcesTest.java
new file mode 100644
index 0000000..02099f4
--- /dev/null
+++ 
b/src/test/java/org/apache/sling/testing/mock/sling/jcrmock/resource/FindResourcesTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.testing.mock.sling.jcrmock.resource;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.testing.mock.jcr.MockJcr;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class FindResourcesTest {
+
+       @Rule
+       public SlingContext context = new 
SlingContext(ResourceResolverType.JCR_MOCK);
+
+       @Before
+       public void setUp() {
+               Resource resource = context.create().resource(
+                               "test",
+                               ImmutableMap.<String, Object> 
builder().put("prop1", "value1")
+                                               .put("prop2", 
"value2").build());
+               Node node = resource.adaptTo(Node.class);
+               Session session = 
context.resourceResolver().adaptTo(Session.class);
+               
+               MockJcr.setQueryResult(session, 
Collections.singletonList(node));
+       }
+
+       @Test
+    @SuppressWarnings("deprecation")
+       public void testFindResources() {
+               Resource resource = 
context.resourceResolver().getResource("/test");
+               Assert.assertNotNull("Resource with name 'test' should be 
there", resource);
+               
+        Iterator<Resource> result = 
context.resourceResolver().findResources("/test", Query.XPATH);
+               Assert.assertTrue("At least one result expected", 
result.hasNext());
+               Assert.assertEquals("/test", result.next().getPath());
+               Assert.assertFalse("At most one result expected", 
result.hasNext());
+       }
+
+}

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to