sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1680700 - in /sling/trunk/contrib/nosql: couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/ generic/src/main/java/org/apache/sling/nosql/generic/resource/impl/ generic/src/test/java/org/...
Date Wed, 20 May 2015 23:28:05 GMT
Author: sseifert
Date: Wed May 20 23:28:04 2015
New Revision: 1680700

URL: http://svn.apache.org/r1680700
Log:
SLING-4381 add special handling for root resource

Added:
    sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderRootIT.java
  (with props)
    sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
  (with props)
    sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/simple/SimpleNoSqlResourceProviderRootTest.java
  (with props)
Modified:
    sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java
    sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java
    sling/trunk/contrib/nosql/generic/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java

Modified: sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java?rev=1680700&r1=1680699&r2=1680700&view=diff
==============================================================================
--- sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java
(original)
+++ sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderIT.java
Wed May 20 23:28:04 2015
@@ -40,15 +40,15 @@ public class CouchbaseNoSqlResourceProvi
 
     @Override
     protected void registerResourceProviderFactory() {
-        context.registerInjectActivateService(
-                new CouchbaseClientImpl(),
-                ImmutableMap.<String, Object> builder()
+        context.registerInjectActivateService(new CouchbaseClientImpl(), ImmutableMap.<String,
Object>builder()
                         .put(CouchbaseClient.CLIENT_ID_PROPERTY, CouchbaseNoSqlResourceProviderFactory.COUCHBASE_CLIENT_ID)
                         .put("couchbaseHosts", System.getProperty("couchbaseHosts", "localhost:8091"))
-                        .put("bucketName", System.getProperty("bucketName", "resource-test")).build());
+                        .put("bucketName", System.getProperty("bucketName", "resource-test"))
+                        .build());
 
-        context.registerInjectActivateService(new CouchbaseNoSqlResourceProviderFactory(),
ImmutableMap
-                .<String, Object> builder().put(ResourceProvider.ROOTS, "/test").build());
+        context.registerInjectActivateService(new CouchbaseNoSqlResourceProviderFactory(),
ImmutableMap.<String, Object>builder()
+                .put(ResourceProvider.ROOTS, "/test")
+                .build());
     }
 
     @Override
@@ -58,15 +58,13 @@ public class CouchbaseNoSqlResourceProvi
                 Resource root = context.resourceResolver().getResource("/");
                 Resource providerRoot = root.getChild("test");
                 if (providerRoot == null) {
-                    providerRoot = context.resourceResolver().create(
-                            root,
-                            "test",
-                            ImmutableMap
-                                    .<String, Object> of(JcrConstants.JCR_PRIMARYTYPE,
JcrConstants.NT_UNSTRUCTURED));
+                    providerRoot = context.resourceResolver().create(root, "test",
+                            ImmutableMap.<String, Object>of(JcrConstants.JCR_PRIMARYTYPE,
JcrConstants.NT_UNSTRUCTURED));
                 }
                 this.testRoot = context.resourceResolver().create(providerRoot, UUID.randomUUID().toString(),
-                        ImmutableMap.<String, Object> of(JcrConstants.JCR_PRIMARYTYPE,
JcrConstants.NT_UNSTRUCTURED));
-            } catch (PersistenceException ex) {
+                        ImmutableMap.<String, Object>of(JcrConstants.JCR_PRIMARYTYPE,
JcrConstants.NT_UNSTRUCTURED));
+            }
+            catch (PersistenceException ex) {
                 throw new RuntimeException(ex);
             }
         }

Added: sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderRootIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderRootIT.java?rev=1680700&view=auto
==============================================================================
--- sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderRootIT.java
(added)
+++ sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderRootIT.java
Wed May 20 23:28:04 2015
@@ -0,0 +1,47 @@
+/*
+ * 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.nosql.couchbase.resourceprovider.integration;
+
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.nosql.couchbase.client.CouchbaseClient;
+import org.apache.sling.nosql.couchbase.client.impl.CouchbaseClientImpl;
+import org.apache.sling.nosql.couchbase.resourceprovider.impl.CouchbaseNoSqlResourceProviderFactory;
+import org.apache.sling.nosql.generic.resource.impl.AbstractNoSqlResourceProviderRootTest;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Test basic ResourceResolver and ValueMap with different data types.
+ */
+public class CouchbaseNoSqlResourceProviderRootIT extends AbstractNoSqlResourceProviderRootTest
{
+    
+    @Override
+    protected void registerResourceProviderFactoryAsRoot() {
+        context.registerInjectActivateService(new CouchbaseClientImpl(), ImmutableMap.<String,
Object>builder()
+                        .put(CouchbaseClient.CLIENT_ID_PROPERTY, CouchbaseNoSqlResourceProviderFactory.COUCHBASE_CLIENT_ID)
+                        .put("couchbaseHosts", System.getProperty("couchbaseHosts", "localhost:8091"))
+                        .put("bucketName", System.getProperty("bucketName", "resource-test"))
+                        .build());
+
+        context.registerInjectActivateService(new CouchbaseNoSqlResourceProviderFactory(),
ImmutableMap.<String, Object>builder()
+                .put(ResourceProvider.ROOTS, "/")
+                .build());
+    }
+
+}

Propchange: sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderRootIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderRootIT.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed May 20 23:28:04 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderRootIT.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java?rev=1680700&r1=1680699&r2=1680700&view=diff
==============================================================================
--- sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java
(original)
+++ sling/trunk/contrib/nosql/couchbase-resourceprovider/src/test/java/org/apache/sling/nosql/couchbase/resourceprovider/integration/CouchbaseNoSqlResourceProviderTransactionalIT.java
Wed May 20 23:28:04 2015
@@ -40,15 +40,15 @@ public class CouchbaseNoSqlResourceProvi
 
     @Override
     protected void registerResourceProviderFactory() {
-        context.registerInjectActivateService(
-                new CouchbaseClientImpl(),
-                ImmutableMap.<String, Object> builder()
+        context.registerInjectActivateService(new CouchbaseClientImpl(),ImmutableMap.<String,
Object>builder()
                         .put(CouchbaseClient.CLIENT_ID_PROPERTY, CouchbaseNoSqlResourceProviderFactory.COUCHBASE_CLIENT_ID)
                         .put("couchbaseHosts", System.getProperty("couchbaseHosts", "localhost:8091"))
-                        .put("bucketName", System.getProperty("bucketName", "resource-test")).build());
+                        .put("bucketName", System.getProperty("bucketName", "resource-test"))
+                        .build());
 
-        context.registerInjectActivateService(new CouchbaseNoSqlResourceProviderFactory(),
ImmutableMap
-                .<String, Object> builder().put(ResourceProvider.ROOTS, "/test").build());
+        context.registerInjectActivateService(new CouchbaseNoSqlResourceProviderFactory(),
ImmutableMap.<String, Object>builder()
+                .put(ResourceProvider.ROOTS, "/test")
+                .build());
     }
 
     @Override
@@ -58,15 +58,13 @@ public class CouchbaseNoSqlResourceProvi
                 Resource root = context.resourceResolver().getResource("/");
                 Resource providerRoot = root.getChild("test");
                 if (providerRoot == null) {
-                    providerRoot = context.resourceResolver().create(
-                            root,
-                            "test",
-                            ImmutableMap
-                                    .<String, Object> of(JcrConstants.JCR_PRIMARYTYPE,
JcrConstants.NT_UNSTRUCTURED));
+                    providerRoot = context.resourceResolver().create(root,"test",
+                            ImmutableMap.<String, Object>of(JcrConstants.JCR_PRIMARYTYPE,
JcrConstants.NT_UNSTRUCTURED));
                 }
                 this.testRoot = context.resourceResolver().create(providerRoot, UUID.randomUUID().toString(),
-                        ImmutableMap.<String, Object> of(JcrConstants.JCR_PRIMARYTYPE,
JcrConstants.NT_UNSTRUCTURED));
-            } catch (PersistenceException ex) {
+                        ImmutableMap.<String, Object>of(JcrConstants.JCR_PRIMARYTYPE,
JcrConstants.NT_UNSTRUCTURED));
+            }
+            catch (PersistenceException ex) {
                 throw new RuntimeException(ex);
             }
         }

Modified: sling/trunk/contrib/nosql/generic/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/nosql/generic/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java?rev=1680700&r1=1680699&r2=1680700&view=diff
==============================================================================
--- sling/trunk/contrib/nosql/generic/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
(original)
+++ sling/trunk/contrib/nosql/generic/src/main/java/org/apache/sling/nosql/generic/resource/impl/NoSqlResourceProvider.java
Wed May 20 23:28:04 2015
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.nosql.generic.resource.impl;
 
+import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -50,6 +51,9 @@ import org.osgi.service.event.EventAdmin
  */
 public class NoSqlResourceProvider implements ResourceProvider, ModifyingResourceProvider,
QueriableResourceProvider {
     
+    private static final String ROOT_PATH = "/";
+    private static final NoSqlData ROOT_DATA = new NoSqlData(ROOT_PATH, Collections.<String,
Object>emptyMap());
+    
     private final NoSqlAdapter adapter;
     private final EventAdmin eventAdmin;
     private final Map<String, NoSqlData> changedResources = new HashMap<String,
NoSqlData>();
@@ -64,6 +68,10 @@ public class NoSqlResourceProvider imple
     // ### READONLY ACCESS ###
     
     public Resource getResource(ResourceResolver resourceResolver, String path) {
+        if (ROOT_PATH.equals(path)) {
+            return new NoSqlResource(ROOT_DATA, resourceResolver, this);
+        }
+        
         if (!adapter.validPath(path)) {
             return null;
         }
@@ -128,7 +136,7 @@ public class NoSqlResourceProvider imple
     
     public Resource create(ResourceResolver resolver, String path, Map<String, Object>
properties)
             throws PersistenceException {
-        if (!adapter.validPath(path)) {
+        if (ROOT_PATH.equals(path) || !adapter.validPath(path)) {
             throw new PersistenceException("Illegal path - unable to create resource at "
+ path, null, path, null);
         }
 
@@ -146,7 +154,7 @@ public class NoSqlResourceProvider imple
     }
     
     public void delete(ResourceResolver resolver, String path) throws PersistenceException
{
-        if (!adapter.validPath(path)) {
+        if (ROOT_PATH.equals(path) || !adapter.validPath(path)) {
             throw new PersistenceException("Unable to delete resource at {}" + path, null,
path, null);
         }
 

Added: sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java?rev=1680700&view=auto
==============================================================================
--- sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
(added)
+++ sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
Wed May 20 23:28:04 2015
@@ -0,0 +1,79 @@
+/*
+ * 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.nosql.generic.resource.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Test monting NoSqlResourceProvider as root resource provider.
+ */
+public abstract class AbstractNoSqlResourceProviderRootTest {
+    
+    @Rule
+    public SlingContext context = new SlingContext(ResourceResolverType.NONE);
+    
+    protected abstract void registerResourceProviderFactoryAsRoot();
+
+    @Before
+    public void setUp() throws Exception {
+        registerResourceProviderFactoryAsRoot();
+    }
+    
+    @After
+    public void tearDown() {
+        context.resourceResolver().revert();
+    }
+    
+    @Test
+    public void testRoot() {
+        Resource root = context.resourceResolver().getResource("/");
+        assertNotNull(root);
+        assertTrue(root instanceof NoSqlResource);
+    }
+
+    @Test
+    public void testCreatePath() throws PersistenceException {
+        ResourceUtil.getOrCreateResource(context.resourceResolver(), "/test/test1",
+                ImmutableMap.<String, Object>of(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED),
+                JcrConstants.NT_UNSTRUCTURED, true);
+        
+        Resource test = context.resourceResolver().getResource("/test");
+        assertNotNull(test);
+        
+        Resource test1 = context.resourceResolver().getResource("/test/test1");
+        assertNotNull(test1);
+        
+        context.resourceResolver().delete(test);
+    }
+
+}

Propchange: sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed May 20 23:28:04 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/resource/impl/AbstractNoSqlResourceProviderRootTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/simple/SimpleNoSqlResourceProviderRootTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/simple/SimpleNoSqlResourceProviderRootTest.java?rev=1680700&view=auto
==============================================================================
--- sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/simple/SimpleNoSqlResourceProviderRootTest.java
(added)
+++ sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/simple/SimpleNoSqlResourceProviderRootTest.java
Wed May 20 23:28:04 2015
@@ -0,0 +1,39 @@
+/*
+ * 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.nosql.generic.simple;
+
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.nosql.generic.resource.impl.AbstractNoSqlResourceProviderRootTest;
+import org.apache.sling.nosql.generic.simple.provider.SimpleNoSqlResourceProviderFactory;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Test basic ResourceResolver and ValueMap with different data types.
+ */
+public class SimpleNoSqlResourceProviderRootTest extends AbstractNoSqlResourceProviderRootTest
{
+    
+    @Override
+    protected void registerResourceProviderFactoryAsRoot() {
+        context.registerInjectActivateService(new SimpleNoSqlResourceProviderFactory(), ImmutableMap.<String,
Object>builder()
+                .put(ResourceProvider.ROOTS, "/")
+                .build());
+    }
+
+}

Propchange: sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/simple/SimpleNoSqlResourceProviderRootTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/simple/SimpleNoSqlResourceProviderRootTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Wed May 20 23:28:04 2015
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author

Propchange: sling/trunk/contrib/nosql/generic/src/test/java/org/apache/sling/nosql/generic/simple/SimpleNoSqlResourceProviderRootTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message