You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2016/02/05 16:24:05 UTC

svn commit: r1728684 - in /sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl: providers/stateful/ stateful/

Author: cziegeler
Date: Fri Feb  5 15:24:04 2016
New Revision: 1728684

URL: http://svn.apache.org/viewvc?rev=1728684&view=rev
Log:
Add some simple tests.

Added:
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/
      - copied from r1728641, sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProviderTest.java   (with props)
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecoratorTest.java
      - copied, changed from r1728654, sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java
Removed:
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/

Added: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProviderTest.java?rev=1728684&view=auto
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProviderTest.java (added)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProviderTest.java Fri Feb  5 15:24:04 2016
@@ -0,0 +1,105 @@
+/*
+ * 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.stateful;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+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.security.AccessSecurityException;
+import org.apache.sling.api.security.ResourceAccessSecurity;
+import org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker;
+import org.apache.sling.spi.resource.provider.QueryLanguageProvider;
+import org.apache.sling.spi.resource.provider.ResolveContext;
+import org.apache.sling.spi.resource.provider.ResourceProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AuthenticatedResourceProviderTest {
+
+    private AuthenticatedResourceProvider src;
+
+    private ResourceAccessSecurity security;
+    private ResourceResolver resourceResolver;
+    private ResolveContext<Object> resolveContext;
+    private ResourceProvider<Object> resourceProvider;
+    private QueryLanguageProvider<Object> queryLanguageProvider;
+
+    private boolean useRAS;
+
+    @Before
+    public void prepare() throws PersistenceException, AccessSecurityException {
+        this.resourceResolver = mock(ResourceResolver.class);
+        this.resolveContext = mock(ResolveContext.class);
+        when(this.resolveContext.getResourceResolver()).thenReturn(this.resourceResolver);
+
+        this.security = mock(ResourceAccessSecurity.class);
+
+        this.queryLanguageProvider = mock(QueryLanguageProvider.class);
+
+        this.resourceProvider = mock(ResourceProvider.class);
+        when(resourceProvider.getQueryLanguageProvider()).thenReturn(this.queryLanguageProvider);
+
+        useRAS = false;
+
+        final ResourceAccessSecurityTracker securityTracker = new ResourceAccessSecurityTracker() {
+            @Override
+            public ResourceAccessSecurity getApplicationResourceAccessSecurity() {
+                if ( useRAS) {
+                    return security;
+                }
+                return null;
+            }
+        };
+
+        this.src = new AuthenticatedResourceProvider(this.resourceProvider, false, this.resolveContext, securityTracker);
+
+    }
+
+    @Test public void testBasics() throws Exception {
+        assertEquals(this.resolveContext, this.src.getResolveContext());
+
+        this.src.refresh();
+        verify(this.resourceProvider).refresh(this.resolveContext);
+
+        when(this.resourceProvider.isLive(this.resolveContext)).thenReturn(true);
+        assertTrue(this.src.isLive());
+        when(this.resourceProvider.isLive(this.resolveContext)).thenReturn(false);
+        assertFalse(this.src.isLive());
+
+        this.src.commit();
+        verify(this.resourceProvider).commit(this.resolveContext);
+    }
+
+    @Test public void testGetParent() {
+        final Resource child = mock(Resource.class);
+        when(child.getPath()).thenReturn("/parent/child");
+        final Resource parent = mock(Resource.class);
+        when(parent.getPath()).thenReturn("/parent");
+        when(this.resourceProvider.getParent(this.resolveContext, child)).thenReturn(parent);
+
+        assertEquals("/parent", this.src.getParent(child).getPath());
+    }
+}

Propchange: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/AuthenticatedResourceProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Copied: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecoratorTest.java (from r1728654, sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecoratorTest.java?p2=sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecoratorTest.java&p1=sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java&r1=1728654&r2=1728684&rev=1728684&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/stateful/SecureResourceProviderDecoratorTest.java (original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/providers/stateful/SecureResourceProviderDecoratorTest.java Fri Feb  5 15:24:04 2016
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.resourceresolver.impl.stateful;
+package org.apache.sling.resourceresolver.impl.providers.stateful;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;