You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2022/07/13 12:04:54 UTC

[sling-org-apache-sling-testing-resourceresolver-mock] branch experimental/resource-provider created (now fc72ebe)

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

sseifert pushed a change to branch experimental/resource-provider
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-resourceresolver-mock.git


      at fc72ebe  resource provider impl

This branch includes the following new commits:

     new d4caeed  set version to 1.4.0-SNAPSHOT
     new c276a28  update mockito dependency use compile scope for osgi dependencies
     new fc72ebe  resource provider impl

The 3 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.



[sling-org-apache-sling-testing-resourceresolver-mock] 01/03: set version to 1.4.0-SNAPSHOT

Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch experimental/resource-provider
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-resourceresolver-mock.git

commit d4caeedeb03067c574aa618a3bb84797a02b19c5
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Wed Jul 13 09:55:29 2022 +0200

    set version to 1.4.0-SNAPSHOT
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 6abae28..b163369 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
     </parent>
 
     <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
-    <version>1.3.1-SNAPSHOT</version>
+    <version>1.4.0-SNAPSHOT</version>
 
     <name>Apache Sling Testing Resource Resolver Mock</name>
     <description>


[sling-org-apache-sling-testing-resourceresolver-mock] 03/03: resource provider impl

Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch experimental/resource-provider
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-resourceresolver-mock.git

commit fc72ebe5d0c8db415bf60cda41fca67b2950a6ac
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Wed Jul 13 13:53:08 2022 +0200

    resource provider impl
---
 pom.xml                                            |  12 +++
 .../resourceresolver/MockResourceProvider.java     | 119 +++++++++++++++++++++
 2 files changed, 131 insertions(+)

diff --git a/pom.xml b/pom.xml
index 1f2225b..b6e074c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,6 +108,18 @@
         </dependency>
 
         <!-- testing -->
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
+            <version>3.3.2</version>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.sling</groupId>
+                    <artifactId>org.apache.sling.testing.resourceresolver-mock</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
diff --git a/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceProvider.java b/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceProvider.java
new file mode 100644
index 0000000..199fbbb
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/resourceresolver/MockResourceProvider.java
@@ -0,0 +1,119 @@
+/*
+ * 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.resourceresolver;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.sling.api.resource.LoginException;
+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.ResourceResolverFactory;
+import org.apache.sling.api.resource.ResourceUtil;
+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.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.event.EventAdmin;
+
+/**
+ * This is a wrapper around {@link MockResourceResolver} to act as resource provider.
+ */
+@Component(service = ResourceProvider.class, property = {
+        ResourceProvider.PROPERTY_NAME + "=MockResourceProvider",
+        ResourceProvider.PROPERTY_ROOT + "=/",
+        ResourceProvider.PROPERTY_MODIFIABLE + ":Boolean=true",
+        // although we do not really support authentication, it's required for a modifiable resource provider
+        ResourceProvider.PROPERTY_AUTHENTICATE + "=" + ResourceProvider.AUTHENTICATE_REQUIRED
+})
+public final class MockResourceProvider extends ResourceProvider<Void> {
+
+    @Reference(cardinality = ReferenceCardinality.OPTIONAL)
+    private EventAdmin eventAdmin;
+
+    private ResourceResolver resourceResolver;
+
+    @Activate
+    private void activate() {
+        MockResourceResolverFactoryOptions options = new MockResourceResolverFactoryOptions();
+        options.setMangleNamespacePrefixes(true);
+        options.setEventAdmin(eventAdmin);
+        ResourceResolverFactory resourceResolverFactory = new MockResourceResolverFactory(options);
+        try {
+            this.resourceResolver = resourceResolverFactory.getResourceResolver(null);
+        }
+        catch (LoginException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    @Override
+    public @Nullable Resource getResource(@NotNull ResolveContext<Void> ctx,
+            @NotNull String path, @NotNull ResourceContext resourceContext,
+            @Nullable Resource parent) {
+        return resourceResolver.getResource(path);
+    }
+
+    @Override
+    public @Nullable Iterator<Resource> listChildren(
+            @NotNull ResolveContext<Void> ctx, @NotNull Resource parent) {
+        return resourceResolver.listChildren(parent);
+    }
+
+    @Override
+    public @NotNull Resource create(@NotNull ResolveContext<Void> ctx, String path,
+            Map<String, Object> properties) throws PersistenceException {
+        String parentPath = ResourceUtil.getParent(path);
+        if (parentPath == null) {
+            throw new PersistenceException("Invalid path: " + path);
+        }
+        Resource parent = resourceResolver.getResource(parentPath);
+        if (parent == null) {
+            throw new PersistenceException("Parent does not exist: " + parentPath);
+        }
+        return resourceResolver.create(parent, path, properties);
+    }
+
+    @Override
+    public void delete(@NotNull ResolveContext<Void> ctx, @NotNull Resource resource) throws PersistenceException {
+        resourceResolver.delete(resource);
+    }
+
+    @Override
+    public void revert(@NotNull ResolveContext<Void> ctx) {
+        resourceResolver.revert();
+    }
+
+    @Override
+    public void commit(@NotNull ResolveContext<Void> ctx) throws PersistenceException {
+        resourceResolver.commit();
+    }
+
+    @Override
+    public boolean hasChanges(@NotNull ResolveContext<Void> ctx) {
+        return resourceResolver.hasChanges();
+    }
+
+}


[sling-org-apache-sling-testing-resourceresolver-mock] 02/03: update mockito dependency use compile scope for osgi dependencies

Posted by ss...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch experimental/resource-provider
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-resourceresolver-mock.git

commit c276a28ae9476b5ba83cb3de010597fe3c16cac7
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Wed Jul 13 12:20:34 2022 +0200

    update mockito dependency
    use compile scope for osgi dependencies
---
 pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index b163369..1f2225b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,17 +84,17 @@
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.service.event</artifactId>
-            <scope>provided</scope>
+            <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.util.converter</artifactId>
-            <scope>provided</scope>
+            <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.util.function</artifactId>
-            <scope>provided</scope>
+            <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>commons-io</groupId>
@@ -122,7 +122,7 @@
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
-            <version>4.5.1</version>
+            <version>4.6.1</version>
             <scope>test</scope>
         </dependency>
         <dependency>