incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1549567 [5/5] - in /sling/trunk/contrib/extensions/replication: ./ src/main/java/org/apache/sling/replication/agent/ src/main/java/org/apache/sling/replication/agent/impl/ src/main/java/org/apache/sling/replication/communication/ src/main/...
Date Mon, 09 Dec 2013 13:37:50 GMT
Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopTransportAuthenticationProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopTransportAuthenticationProviderTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopTransportAuthenticationProviderTest.java
(added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopTransportAuthenticationProviderTest.java
Mon Dec  9 13:37:48 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.replication.transport.authentication.impl;
+
+import org.apache.http.client.fluent.Executor;
+import org.apache.sling.replication.communication.ReplicationEndpoint;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationContext;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testcase for {@link NopTransportAuthenticationProvider}
+ */
+public class NopTransportAuthenticationProviderTest {
+
+    @Test
+    public void testAuthenticationWithNullAuthenticableAndContext() throws Exception {
+        NopTransportAuthenticationProvider authenticationHandler = new NopTransportAuthenticationProvider();
+        Object authenticable = null;
+        TransportAuthenticationContext context = null;
+        assertEquals(authenticable, authenticationHandler.authenticate(authenticable, context));
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndNullContext() throws Exception {
+        NopTransportAuthenticationProvider authenticationHandler = new NopTransportAuthenticationProvider();
+        Executor authenticable = Executor.newInstance();
+        TransportAuthenticationContext context = null;
+        assertEquals(authenticable, authenticationHandler.authenticate(authenticable, context));
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndEmptyContext() throws Exception {
+        NopTransportAuthenticationProvider authenticationHandler = new NopTransportAuthenticationProvider();
+        Executor authenticable = Executor.newInstance();
+        TransportAuthenticationContext context = new TransportAuthenticationContext();
+        assertEquals(authenticable, authenticationHandler.authenticate(authenticable, context));
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndCorrectContext() throws Exception {
+        NopTransportAuthenticationProvider authenticationHandler = new NopTransportAuthenticationProvider();
+        Executor authenticable = Executor.newInstance();
+        TransportAuthenticationContext context = new TransportAuthenticationContext();
+        context.addAttribute("endpoint", new ReplicationEndpoint("http://www.apache.org"));
+        assertEquals(authenticable, authenticationHandler.authenticate(authenticable, context));
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderTest.java
(added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsTransportAuthenticationProviderTest.java
Mon Dec  9 13:37:48 2013
@@ -0,0 +1,84 @@
+/*
+ * 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.replication.transport.authentication.impl;
+
+import org.apache.http.client.fluent.Executor;
+import org.apache.sling.replication.communication.ReplicationEndpoint;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationContext;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+/**
+ * Testcase for {@link UserCredentialsTransportAuthenticationProvider}
+ */
+public class UserCredentialsTransportAuthenticationProviderTest {
+
+    @Test
+    public void testAuthenticationWithNullAuthenticableAndContext() throws Exception {
+        UserCredentialsTransportAuthenticationProvider authenticationHandler = new UserCredentialsTransportAuthenticationProvider(
+                        "foo", "bar");
+        Executor authenticable = null;
+        TransportAuthenticationContext context = null;
+        try {
+            authenticationHandler.authenticate(authenticable, context);
+            fail("could not authenticate a null authenticable");
+        } catch (Exception e) {
+            // expected to fail
+        }
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndNullContext() throws Exception {
+        UserCredentialsTransportAuthenticationProvider authenticationHandler = new UserCredentialsTransportAuthenticationProvider(
+                        "foo", "bar");
+        Executor authenticable = Executor.newInstance();
+        TransportAuthenticationContext context = null;
+        try {
+            authenticationHandler.authenticate(authenticable, context);
+            fail("could not authenticate with a null context");
+        } catch (Exception e) {
+            // expected to fail
+        }
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndEmptyContext() throws Exception {
+        UserCredentialsTransportAuthenticationProvider authenticationHandler = new UserCredentialsTransportAuthenticationProvider(
+                        "foo", "bar");
+        Executor authenticable = Executor.newInstance();
+        TransportAuthenticationContext context = new TransportAuthenticationContext();
+        try {
+            authenticationHandler.authenticate(authenticable, context);
+            fail("could not authenticate with an empty context");
+        } catch (Exception e) {
+            // expected to fail
+        }
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndCorrectContext() throws Exception {
+        UserCredentialsTransportAuthenticationProvider authenticationHandler = new UserCredentialsTransportAuthenticationProvider(
+                        "foo", "bar");
+        Executor authenticable = Executor.newInstance();
+        TransportAuthenticationContext context = new TransportAuthenticationContext();
+        context.addAttribute("endpoint", new ReplicationEndpoint("http://www.apache.org"));
+        authenticationHandler.authenticate(authenticable, context);
+    }
+}

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/HttpTransportHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/HttpTransportHandlerTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/HttpTransportHandlerTest.java
(original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/HttpTransportHandlerTest.java
Mon Dec  9 13:37:48 2013
@@ -26,8 +26,8 @@ import org.apache.http.client.fluent.Res
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationEndpoint;
 import org.apache.sling.replication.serialization.ReplicationPackage;
-import org.apache.sling.replication.transport.authentication.AuthenticationContext;
-import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationContext;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
 import org.junit.Test;
 
 import static org.mockito.Matchers.any;
@@ -42,17 +42,17 @@ public class HttpTransportHandlerTest {
     public void testHttpTransport() throws Exception {
         HttpTransportHandler httpTransportHandler = new HttpTransportHandler();
         ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
-        when(replicationPackage.getAction()).thenReturn(ReplicationActionType.ACTIVATE.toString());
+        when(replicationPackage.getAction()).thenReturn(ReplicationActionType.ADD.toString());
         when(replicationPackage.getType()).thenReturn("test");
-        when(replicationPackage.getPaths()).thenReturn(new String[]{"/"});
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/content"});
         ReplicationEndpoint replicationEndpoint = new ReplicationEndpoint(new URI("http://localhost:8080/system/replication/receive"));
-        AuthenticationHandler<Executor, Executor> authenticationHandler = mock(AuthenticationHandler.class);
+        TransportAuthenticationProvider<Executor, Executor> transportAuthenticationProvider
= mock(TransportAuthenticationProvider.class);
         Executor executor = mock(Executor.class);
         Response response = mock(Response.class);
         Content content = mock(Content.class);
         when(response.returnContent()).thenReturn(content);
         when(executor.execute(any(Request.class))).thenReturn(response);
-        when(authenticationHandler.authenticate(any(Executor.class), any(AuthenticationContext.class))).thenReturn(executor);
-        httpTransportHandler.transport(replicationPackage, replicationEndpoint, authenticationHandler);
+        when(transportAuthenticationProvider.authenticate(any(Executor.class), any(TransportAuthenticationContext.class))).thenReturn(executor);
+        httpTransportHandler.transport(replicationPackage, replicationEndpoint, transportAuthenticationProvider);
     }
 }

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/PollingTransportHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/PollingTransportHandlerTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/PollingTransportHandlerTest.java
(original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/PollingTransportHandlerTest.java
Mon Dec  9 13:37:48 2013
@@ -27,8 +27,8 @@ import org.apache.http.client.fluent.Res
 import org.apache.sling.replication.communication.ReplicationActionType;
 import org.apache.sling.replication.communication.ReplicationEndpoint;
 import org.apache.sling.replication.serialization.ReplicationPackage;
-import org.apache.sling.replication.transport.authentication.AuthenticationContext;
-import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationContext;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
 import org.junit.Test;
 
 import static org.mockito.Matchers.any;
@@ -44,11 +44,11 @@ public class PollingTransportHandlerTest
     public void testPollingTransport() throws Exception {
         PollingTransportHandler pollingTransportHandler = new PollingTransportHandler();
         ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
-        when(replicationPackage.getAction()).thenReturn(ReplicationActionType.ACTIVATE.toString());
+        when(replicationPackage.getAction()).thenReturn(ReplicationActionType.ADD.toString());
         when(replicationPackage.getType()).thenReturn("test");
-        when(replicationPackage.getPaths()).thenReturn(new String[]{"/"});
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/content"});
         ReplicationEndpoint replicationEndpoint = new ReplicationEndpoint(new URI("http://localhost:8080/system/replication/agent/reverse"));
-        AuthenticationHandler<Executor, Executor> authenticationHandler = mock(AuthenticationHandler.class);
+        TransportAuthenticationProvider<Executor, Executor> transportAuthenticationProvider
= mock(TransportAuthenticationProvider.class);
         Executor executor = mock(Executor.class);
         Response response = mock(Response.class);
         HttpEntity entity = mock(HttpEntity.class);
@@ -56,7 +56,7 @@ public class PollingTransportHandlerTest
         when(response.returnResponse()).thenReturn(httpResponse);
         when(httpResponse.getEntity()).thenReturn(entity);
         when(executor.execute(any(Request.class))).thenReturn(response);
-        when(authenticationHandler.authenticate(any(Executor.class), any(AuthenticationContext.class))).thenReturn(executor);
-        pollingTransportHandler.transport(replicationPackage, replicationEndpoint, authenticationHandler);
+        when(transportAuthenticationProvider.authenticate(any(Executor.class), any(TransportAuthenticationContext.class))).thenReturn(executor);
+        pollingTransportHandler.transport(replicationPackage, replicationEndpoint, transportAuthenticationProvider);
     }
 }

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandlerTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandlerTest.java
(original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandlerTest.java
Mon Dec  9 13:37:48 2013
@@ -24,10 +24,11 @@ import javax.jcr.Node;
 import javax.jcr.Session;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.replication.communication.ReplicationEndpoint;
+import org.apache.sling.replication.event.ReplicationEventFactory;
 import org.apache.sling.replication.serialization.ReplicationPackage;
 import org.apache.sling.replication.transport.ReplicationTransportException;
-import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
-import org.apache.sling.replication.transport.authentication.impl.RepositoryAuthenticationHandler;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
+import org.apache.sling.replication.transport.authentication.impl.RepositoryTransportAuthenticationProvider;
 import org.junit.Test;
 
 import static org.junit.Assert.fail;
@@ -44,10 +45,10 @@ public class RepositoryTransportHandlerT
     public void testDeliveryWithoutAuthenticatedSession() throws Exception {
         RepositoryTransportHandler handler = new RepositoryTransportHandler();
         @SuppressWarnings("unchecked")
-        AuthenticationHandler<SlingRepository, Session> authenticationHandler = mock(AuthenticationHandler.class);
+        TransportAuthenticationProvider<SlingRepository, Session> transportAuthenticationProvider
= mock(TransportAuthenticationProvider.class);
         try {
             handler.transport(null, new ReplicationEndpoint("repo://var/outbox/replication/rev1"),
-                    authenticationHandler);
+                    transportAuthenticationProvider);
             fail("cannot deliver without a proper session");
         } catch (ReplicationTransportException re) {
             // failure expected
@@ -56,7 +57,7 @@ public class RepositoryTransportHandlerT
 
     @Test
     public void testDeliveryWithAuthenticatedSession() throws Exception {
-        String repoPath = "var/outbox/replication/rev1";
+        String repoPath = "/var/outbox/replication/rev1";
 
         Node addedNode = mock(Node.class);
         when(addedNode.getPath()).thenReturn(repoPath + "/some-id");
@@ -72,13 +73,20 @@ public class RepositoryTransportHandlerT
         when(repo.login(any(Credentials.class))).thenReturn(session);
 
         RepositoryTransportHandler handler = new RepositoryTransportHandler();
-        Field field = handler.getClass().getDeclaredField("repository");
-        field.setAccessible(true);
-        field.set(handler, repo);
-        AuthenticationHandler<SlingRepository, Session> authenticationHandler = new
RepositoryAuthenticationHandler("user-123", "p455w0rd");
+        Field repositoryField = handler.getClass().getDeclaredField("repository");
+        repositoryField.setAccessible(true);
+        repositoryField.set(handler, repo);
+
+        ReplicationEventFactory replicationEventFactory = mock(ReplicationEventFactory.class);
+        Field replicationEventFactoryField = handler.getClass().getDeclaredField("replicationEventFactory");
+        replicationEventFactoryField.setAccessible(true);
+        replicationEventFactoryField.set(handler, replicationEventFactory);
+
+        TransportAuthenticationProvider<SlingRepository, Session> transportAuthenticationProvider
= new RepositoryTransportAuthenticationProvider("user-123", "p455w0rd");
         ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
         when(replicationPackage.getId()).thenReturn("some-id");
-        handler.transport(replicationPackage, new ReplicationEndpoint("repo://" + repoPath),
-                authenticationHandler);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/apps", "/libs"});
+        handler.transport(replicationPackage, new ReplicationEndpoint("repo:/" + repoPath),
+                transportAuthenticationProvider);
     }
 }



Mime
View raw message