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 [4/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/main/resources/SLING-CONTENT/libs/sling/replication/config.publish/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config.publish/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config.publish/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json (added)
+++ sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/config.publish/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json Mon Dec  9 13:37:48 2013
@@ -0,0 +1,12 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "reverserepo",
+    "endpoint" : "repo://var/replication/outbox/reverserepo",
+    "TransportHandler.target" : "(name=repository)", 
+    "ReplicationPackageBuilder.target" : "(name=vlt)",
+    "ReplicationQueueProvider.target" : "(name=sjh)",
+    "TransportAuthenticationProviderFactory.target" : "(name=repo-user)",
+    "authentication.properties" : ["user=admin","password=admin"],
+    "ReplicationQueueDistributionStrategy.target" : "(name=error)",
+    "rules" : ["trigger on path: /content/usergenerated"]
+}

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java Mon Dec  9 13:37:48 2013
@@ -28,7 +28,7 @@ import static org.junit.Assert.assertNot
  */
 public class ReplicationAgentConfigurationTest {
     @Test
-    public void testDefaultConfiguration() throws Exception {
+    public void testNullsWithDefaultConfiguration() throws Exception {
         ReplicationAgentConfiguration replicationAgentConfiguration = new ReplicationAgentConfiguration(new Properties());
         assertNotNull(replicationAgentConfiguration.getAuthenticationProperties());
         assertNotNull(replicationAgentConfiguration.getEndpoint());

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResourceTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResourceTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentConfigurationResourceTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.agent.impl;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Testcase for {@link ReplicationAgentConfigurationResource}
+ */
+public class ReplicationAgentConfigurationResourceTest {
+
+    @Test
+    public void testResourceCreationWithNullConfiguration() throws Exception {
+        try {
+            ReplicationAgentConfiguration configuration = null;
+            ResourceResolver resourceResolver = mock(ResourceResolver.class);
+            new ReplicationAgentConfigurationResource(configuration, resourceResolver);
+            fail("it should not be possible to create a configuration resource out of a null configuration");
+        } catch (Throwable t) {
+            // expected
+        }
+    }
+
+    @Test
+    public void testResourceCreationWithAgentConfiguration() throws Exception {
+        ReplicationAgentConfiguration agentConfiguration = mock(ReplicationAgentConfiguration.class);
+        ResourceResolver resourceResolver = mock(ResourceResolver.class);
+        ReplicationAgentConfigurationResource replicationAgentConfigurationResource = new ReplicationAgentConfigurationResource(agentConfiguration, resourceResolver);
+        assertNotNull(replicationAgentConfigurationResource.getPath());
+        assertEquals(ReplicationAgentResource.BASE_PATH + "/null/configuration", replicationAgentConfigurationResource.getPath());
+        assertNotNull(replicationAgentConfigurationResource.getResourceResolver());
+        assertEquals(resourceResolver, replicationAgentConfigurationResource.getResourceResolver());
+        assertNotNull(replicationAgentConfigurationResource.getResourceType());
+        assertEquals(ReplicationAgentConfigurationResource.RESOURCE_TYPE, replicationAgentConfigurationResource.getResourceType());
+        assertNotNull(replicationAgentConfigurationResource.getResourceMetadata());
+        assertEquals("/system/replication/agent/null", replicationAgentConfigurationResource.getResourceMetadata().getResolutionPath());
+        assertNull(replicationAgentConfigurationResource.getResourceSuperType());
+    }
+}

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProviderTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProviderTest.java (original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProviderTest.java Mon Dec  9 13:37:48 2013
@@ -18,23 +18,22 @@
  */
 package org.apache.sling.replication.agent.impl;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.replication.agent.AgentConfigurationException;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
+import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 
-import org.apache.sling.replication.agent.AgentConfigurationException;
-import org.apache.sling.replication.agent.ReplicationAgent;
-import org.apache.sling.replication.agent.ReplicationAgentConfiguration;
-import org.apache.sling.replication.agent.ReplicationAgentConfigurationManager;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 /**
  * Testcase for {@link ReplicationAgentResourceProvider}
@@ -94,14 +93,14 @@ public class ReplicationAgentResourcePro
         when(configurationManager.getConfiguration(replicationAgent)).thenReturn(configuration);
     }
 
-    private SimpleReplicationAgentImpl createMockedReplicationAgent(String path,
+    private SimpleReplicationAgent createMockedReplicationAgent(String path,
                     BundleContext context) throws InvalidSyntaxException {
         ServiceReference serviceReference = mock(ServiceReference.class);
         ServiceReference[] agentServiceReferences = new ServiceReference[] { serviceReference };
-        String filter = new StringBuilder("(name=").append(path).append(")").toString();
+        String filter = "(name=" + path + ")";
         when(context.getServiceReferences(ReplicationAgent.class.getName(), filter)).thenReturn(
                         agentServiceReferences);
-        SimpleReplicationAgentImpl replicationAgent = new SimpleReplicationAgentImpl(path, null,
+        SimpleReplicationAgent replicationAgent = new SimpleReplicationAgent(path, null, null,
                         null, null, null, null, null);
         when(context.getService(serviceReference)).thenReturn(replicationAgent);
         return replicationAgent;

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.agent.impl;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Testcase for {@link ReplicationAgentResource}
+ */
+public class ReplicationAgentResourceTest {
+
+    @Test
+    public void testResourceCreationWithNullAgent() throws Exception {
+        try {
+            ReplicationAgent agent = null;
+            ResourceResolver resourceResolver = mock(ResourceResolver.class);
+            new ReplicationAgentResource(agent, resourceResolver);
+            fail("it should not be possible to create an agent resource out of a null agent");
+        } catch (Throwable t) {
+            // expected
+        }
+    }
+
+    @Test
+    public void testResourceCreationWithAgent() throws Exception {
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ResourceResolver resourceResolver = mock(ResourceResolver.class);
+        ReplicationAgentResource replicationAgentResource = new ReplicationAgentResource(agent, resourceResolver);
+        assertNotNull(replicationAgentResource.getPath());
+        assertEquals(ReplicationAgentResource.BASE_PATH +"/null", replicationAgentResource.getPath());
+        assertNotNull(replicationAgentResource.getResourceResolver());
+        assertEquals(resourceResolver, replicationAgentResource.getResourceResolver());
+        assertNotNull(replicationAgentResource.getResourceType());
+        assertEquals(ReplicationAgentResource.RESOURCE_TYPE, replicationAgentResource.getResourceType());
+        assertNotNull(replicationAgentResource.getResourceMetadata());
+        assertEquals(ReplicationAgentResource.BASE_PATH, replicationAgentResource.getResourceMetadata().getResolutionPath());
+        assertNull(replicationAgentResource.getResourceSuperType());
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactoryTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactoryTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentServiceFactoryTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,97 @@
+/*
+ * 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.agent.impl;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.sling.replication.agent.AgentConfigurationException;
+import org.apache.sling.replication.queue.ReplicationQueueDistributionStrategy;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
+import org.apache.sling.replication.transport.TransportHandler;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProviderFactory;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link ReplicationAgentServiceFactory}
+ */
+public class ReplicationAgentServiceFactoryTest {
+
+    @Test
+    public void testActivationWithAllServicesAndPropertiesBound() throws Exception {
+        ReplicationAgentServiceFactory serviceFactory = new ReplicationAgentServiceFactory();
+
+        Field packageBuilderField = serviceFactory.getClass().getDeclaredField("packageBuilder");
+        packageBuilderField.setAccessible(true);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        packageBuilderField.set(serviceFactory, packageBuilder);
+
+        Field distributionField = serviceFactory.getClass().getDeclaredField("queueDistributionStrategy");
+        distributionField.setAccessible(true);
+        ReplicationQueueDistributionStrategy distributionStrategy = mock(ReplicationQueueDistributionStrategy.class);
+        distributionField.set(serviceFactory, distributionStrategy);
+
+        Field queueField = serviceFactory.getClass().getDeclaredField("queueProvider");
+        queueField.setAccessible(true);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        queueField.set(serviceFactory, queueProvider);
+
+        Field transportField = serviceFactory.getClass().getDeclaredField("transportHandler");
+        transportField.setAccessible(true);
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        transportField.set(serviceFactory, transportHandler);
+
+        Field transportAuthenticationField = serviceFactory.getClass().getDeclaredField("transportAuthenticationProviderFactory");
+        transportAuthenticationField.setAccessible(true);
+        TransportAuthenticationProviderFactory transportAuthenticationProviderFactory = mock(TransportAuthenticationProviderFactory.class);
+        transportAuthenticationField.set(serviceFactory, transportAuthenticationProviderFactory);
+
+        TransportAuthenticationProvider transportAuthenticationProvider = mock(TransportAuthenticationProvider.class);
+        when(transportAuthenticationProviderFactory.createAuthenticationProvider(any(Map.class))).thenReturn(transportAuthenticationProvider);
+        when(transportHandler.supportsAuthenticationProvider(any(TransportAuthenticationProvider.class))).thenReturn(true);
+
+        Map<String, Object> dictionary = new HashMap<String, Object>();
+        dictionary.put("endpoint", "http://somewhere.com");
+        dictionary.put("name", "agent1");
+        BundleContext context = mock(BundleContext.class);
+        serviceFactory.activate(context, dictionary);
+    }
+
+    @Test
+    public void testActivationWithNoServicesBound() throws Exception {
+        try {
+            ReplicationAgentServiceFactory serviceFactory = new ReplicationAgentServiceFactory();
+
+            Map<String, Object> dictionary = new HashMap<String, Object>();
+            BundleContext context = mock(BundleContext.class);
+            serviceFactory.activate(context, dictionary);
+            fail("missing / incomplete configuration should trigger agent configuration exception");
+        } catch (AgentConfigurationException e) {
+            // expected
+        }
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,182 @@
+/*
+ * 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.agent.impl;
+
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.communication.ReplicationResponse;
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.queue.ReplicationQueueDistributionStrategy;
+import org.apache.sling.replication.queue.ReplicationQueueItemState;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.queue.impl.simple.SimpleReplicationQueue;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
+import org.apache.sling.replication.transport.TransportHandler;
+import org.apache.sling.replication.transport.authentication.TransportAuthenticationProvider;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link SimpleReplicationAgent}
+ */
+public class SimpleReplicationAgentTest {
+
+    @Test
+    public void testProcess() throws Exception {
+        String name = "sample-agent";
+        String endpoint = "/tmp";
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        TransportAuthenticationProvider transportAuthenticationProvider = mock(TransportAuthenticationProvider.class);
+        ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class);
+        SimpleReplicationAgent agent = new SimpleReplicationAgent(name, endpoint, new String[0],
+                        transportHandler, packageBuilder, queueProvider, transportAuthenticationProvider, distributionHandler);
+        ReplicationPackage item = mock(ReplicationPackage.class);
+        assertTrue(agent.process(item));
+    }
+
+    @Test
+    public void testSyncReplicationWithFailingDistributionStrategy() throws Exception {
+        String name = "sample-agent";
+        String endpoint = "/tmp";
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        TransportAuthenticationProvider transportAuthenticationProvider = mock(TransportAuthenticationProvider.class);
+        ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class);
+        SimpleReplicationAgent agent = new SimpleReplicationAgent(name, endpoint, new String[0],
+                        transportHandler, packageBuilder, queueProvider, transportAuthenticationProvider, distributionHandler);
+        ReplicationRequest request = new ReplicationRequest(System.nanoTime(),
+                        ReplicationActionType.ADD, "/");
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(packageBuilder.createPackage(request)).thenReturn(replicationPackage);
+        when(queueProvider.getQueue(agent, replicationPackage)).thenReturn(
+                        new SimpleReplicationQueue(agent, "name"));
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(
+              new SimpleReplicationQueue(agent, "name"));
+        ReplicationResponse response = agent.execute(request);
+        assertNotNull(response);
+        assertEquals("ERROR", response.getStatus());
+    }
+
+    @Test
+    public void testSyncReplicationWithWorkingDistributionStrategy() throws Exception {
+        String name = "sample-agent";
+        String endpoint = "/tmp";
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        TransportAuthenticationProvider transportAuthenticationProvider = mock(TransportAuthenticationProvider.class);
+        ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class);
+        SimpleReplicationAgent agent = new SimpleReplicationAgent(name, endpoint, new String[0],
+                transportHandler, packageBuilder, queueProvider, transportAuthenticationProvider, distributionHandler);
+        ReplicationRequest request = new ReplicationRequest(System.nanoTime(),
+                ReplicationActionType.ADD, "/");
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationQueueItemState state = new ReplicationQueueItemState();
+        state.setItemState(ReplicationQueueItemState.ItemState.SUCCEEDED);
+        when(distributionHandler.add(replicationPackage, agent, queueProvider)).thenReturn(state);
+        when(packageBuilder.createPackage(request)).thenReturn(replicationPackage);
+        when(queueProvider.getQueue(agent, replicationPackage)).thenReturn(
+                new SimpleReplicationQueue(agent, "name"));
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(
+                new SimpleReplicationQueue(agent, "name"));
+        ReplicationResponse response = agent.execute(request);
+        assertNotNull(response);
+        assertEquals("SUCCEEDED", response.getStatus());
+    }
+
+    @Test
+    public void testAsyncReplication() throws Exception {
+        String name = "sample-agent";
+        String endpoint = "/tmp";
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        TransportAuthenticationProvider transportAuthenticationProvider = mock(TransportAuthenticationProvider.class);
+        ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class);
+        SimpleReplicationAgent agent = new SimpleReplicationAgent(name, endpoint, new String[0],
+                transportHandler, packageBuilder, queueProvider, transportAuthenticationProvider, distributionHandler);
+        ReplicationRequest request = new ReplicationRequest(System.nanoTime(),
+                ReplicationActionType.ADD, "/");
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(packageBuilder.createPackage(request)).thenReturn(replicationPackage);
+        when(queueProvider.getQueue(agent, replicationPackage)).thenReturn(
+                new SimpleReplicationQueue(agent, "name"));
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(
+                new SimpleReplicationQueue(agent, "name"));
+        agent.send(request);
+    }
+
+    @Test
+    public void testGetDefaultQueue() throws Exception {
+        String name = "sample-agent";
+        String endpoint = "/tmp";
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        TransportAuthenticationProvider transportAuthenticationProvider = mock(TransportAuthenticationProvider.class);
+        ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class);
+        SimpleReplicationAgent agent = new SimpleReplicationAgent(name, endpoint, new String[0],
+                transportHandler, packageBuilder, queueProvider, transportAuthenticationProvider, distributionHandler);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        assertNotNull(agent.getQueue(null));
+    }
+
+    @Test
+    public void testGetExistingNamedQueue() throws Exception {
+        String name = "sample-agent";
+        String endpoint = "/tmp";
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        TransportAuthenticationProvider transportAuthenticationProvider = mock(TransportAuthenticationProvider.class);
+        ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class);
+        SimpleReplicationAgent agent = new SimpleReplicationAgent(name, endpoint, new String[0],
+                transportHandler, packageBuilder, queueProvider, transportAuthenticationProvider, distributionHandler);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getQueue(agent, "priority")).thenReturn(queue);
+        assertNotNull(agent.getQueue("priority"));
+    }
+
+    @Test
+    public void testGetNonExistingNamedQueue() throws Exception {
+        String name = "sample-agent";
+        String endpoint = "/tmp";
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        TransportAuthenticationProvider transportAuthenticationProvider = mock(TransportAuthenticationProvider.class);
+        ReplicationQueueDistributionStrategy distributionHandler = mock(ReplicationQueueDistributionStrategy.class);
+        SimpleReplicationAgent agent = new SimpleReplicationAgent(name, endpoint, new String[0],
+                transportHandler, packageBuilder, queueProvider, transportAuthenticationProvider, distributionHandler);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getQueue(agent, "priority")).thenReturn(queue);
+        assertNull(agent.getQueue("weird"));
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/ErrorAwareQueueDistributionStrategyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/ErrorAwareQueueDistributionStrategyTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/ErrorAwareQueueDistributionStrategyTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/ErrorAwareQueueDistributionStrategyTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,157 @@
+/*
+ * 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.queue.impl;
+
+import java.util.Dictionary;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.queue.ReplicationQueueItemState;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.junit.Test;
+import org.osgi.service.component.ComponentContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link org.apache.sling.replication.queue.impl.ErrorAwareQueueDistributionStrategy}
+ */
+public class ErrorAwareQueueDistributionStrategyTest {
+
+    @Test
+    public void testPackageAdditionWithSucceedingItemDelivery() throws Exception {
+        ErrorAwareQueueDistributionStrategy errorAwareDistributionStrategy = new ErrorAwareQueueDistributionStrategy();
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(true);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = errorAwareDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertTrue(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithFailingItemDelivery() throws Exception {
+        ErrorAwareQueueDistributionStrategy errorAwareDistributionStrategy = new ErrorAwareQueueDistributionStrategy();
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(false);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = errorAwareDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertFalse(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithMultipleFailingItemsDeliveryAndErrorQueue() throws Exception {
+        ErrorAwareQueueDistributionStrategy errorAwareDistributionStrategy = new ErrorAwareQueueDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("attempts.threshold")).thenReturn(new String[]{"1"});
+        when(properties.get("stuck.handling")).thenReturn(new String[]{"ERROR"});
+        when(context.getProperties()).thenReturn(properties);
+        errorAwareDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        when(queue.getHead()).thenReturn(replicationPackage);
+        ReplicationQueue errorQueue = mock(ReplicationQueue.class);
+        when(errorQueue.add(replicationPackage)).thenReturn(true);
+        when(queueProvider.getQueue(agent, "-error")).thenReturn(errorQueue);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(false);
+        when(state.getAttempts()).thenReturn(2);
+        when(queue.getStatus(any(ReplicationPackage.class))).thenReturn(state);
+        ReplicationQueueItemState returnedState = errorAwareDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertFalse(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithMultipleFailingItemsDeliveryAndDropFromQueue() throws Exception {
+        ErrorAwareQueueDistributionStrategy errorAwareDistributionStrategy = new ErrorAwareQueueDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("attempts.threshold")).thenReturn(new String[]{"1"});
+        when(properties.get("stuck.handling")).thenReturn(new String[]{"DROP"});
+        when(context.getProperties()).thenReturn(properties);
+        errorAwareDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        when(queue.getHead()).thenReturn(replicationPackage);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(false);
+        when(state.getAttempts()).thenReturn(2);
+        when(queue.getStatus(any(ReplicationPackage.class))).thenReturn(state);
+        ReplicationQueueItemState returnedState = errorAwareDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertFalse(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithNullItemStateFromTheQueue() throws Exception {
+        ErrorAwareQueueDistributionStrategy errorAwareDistributionStrategy = new ErrorAwareQueueDistributionStrategy();
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState returnedState = errorAwareDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNull(returnedState);
+    }
+
+    @Test
+    public void testPackageAdditionWithNotNullItemStateFromTheQueue() throws Exception {
+        ErrorAwareQueueDistributionStrategy errorAwareDistributionStrategy = new ErrorAwareQueueDistributionStrategy();
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = errorAwareDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/PriorityPathQueueDistributionStrategyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/PriorityPathQueueDistributionStrategyTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/PriorityPathQueueDistributionStrategyTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/PriorityPathQueueDistributionStrategyTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,213 @@
+/*
+ * 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.queue.impl;
+
+import java.util.Dictionary;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.queue.ReplicationQueueItemState;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.junit.Test;
+import org.osgi.service.component.ComponentContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link org.apache.sling.replication.queue.impl.PriorityPathDistributionStrategy}
+ */
+public class PriorityPathQueueDistributionStrategyTest {
+
+    @Test
+    public void testPackageAdditionWithSucceedingItemDelivery() throws Exception {
+        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
+        when(context.getProperties()).thenReturn(properties);
+        priorityPathDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/etc"});
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(true);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertTrue(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithSucceedingItemDeliveryOnPriorityPath() throws Exception {
+        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
+        when(context.getProperties()).thenReturn(properties);
+        priorityPathDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/content/sample1"});
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getQueue(agent, "/content")).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(true);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertTrue(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithFailingItemDelivery() throws Exception {
+        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
+        when(context.getProperties()).thenReturn(properties);
+        priorityPathDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/etc"});
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(false);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertFalse(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithFailingItemDeliveryOnPriorityPath() throws Exception {
+        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
+        when(context.getProperties()).thenReturn(properties);
+        priorityPathDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/content/sample2"});
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getQueue(agent, "/content")).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(false);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertFalse(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithNullItemStateFromTheQueue() throws Exception {
+        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
+        when(context.getProperties()).thenReturn(properties);
+        priorityPathDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/etc"});
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNull(returnedState);
+    }
+
+    @Test
+    public void testPackageAdditionWithNullItemStateFromTheQueueOnPriorityPath() throws Exception {
+        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
+        when(context.getProperties()).thenReturn(properties);
+        priorityPathDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/apps/some/stuff"});
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getQueue(agent, "/apps")).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNull(returnedState);
+    }
+
+    @Test
+    public void testPackageAdditionWithNotNullItemStateFromTheQueue() throws Exception {
+        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
+        when(context.getProperties()).thenReturn(properties);
+        priorityPathDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/etc"});
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+    }
+
+    @Test
+    public void testPackageAdditionWithNotNullItemStateFromTheQueueOnPriorityPath() throws Exception {
+        PriorityPathDistributionStrategy priorityPathDistributionStrategy = new PriorityPathDistributionStrategy();
+        ComponentContext context = mock(ComponentContext.class);
+        Dictionary properties = mock(Dictionary.class);
+        when(properties.get("priority.paths")).thenReturn(new String[]{"/content", "/apps"});
+        when(context.getProperties()).thenReturn(properties);
+        priorityPathDistributionStrategy.activate(context);
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/apps"});
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getQueue(agent, "/apps")).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = priorityPathDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/SingleQueueDistributionStrategyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/SingleQueueDistributionStrategyTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/SingleQueueDistributionStrategyTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/SingleQueueDistributionStrategyTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,101 @@
+/*
+ * 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.queue.impl;
+
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.queue.ReplicationQueueItemState;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link SingleQueueDistributionStrategy}
+ */
+public class SingleQueueDistributionStrategyTest {
+
+    @Test
+    public void testPackageAdditionWithSucceedingItemDelivery() throws Exception {
+        SingleQueueDistributionStrategy singleQueueDistributionStrategy = new SingleQueueDistributionStrategy();
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(true);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = singleQueueDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertTrue(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithFailingItemDelivery() throws Exception {
+        SingleQueueDistributionStrategy singleQueueDistributionStrategy = new SingleQueueDistributionStrategy();
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(state.isSuccessful()).thenReturn(false);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = singleQueueDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+        assertFalse(returnedState.isSuccessful());
+    }
+
+    @Test
+    public void testPackageAdditionWithNullItemStateFromTheQueue() throws Exception {
+        SingleQueueDistributionStrategy singleQueueDistributionStrategy = new SingleQueueDistributionStrategy();
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState returnedState = singleQueueDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNull(returnedState);
+    }
+
+    @Test
+    public void testPackageAdditionWithNotNullItemStateFromTheQueue() throws Exception {
+        SingleQueueDistributionStrategy singleQueueDistributionStrategy = new SingleQueueDistributionStrategy();
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        ReplicationQueue queue = mock(ReplicationQueue.class);
+        when(queueProvider.getDefaultQueue(agent)).thenReturn(queue);
+        when(queue.add(replicationPackage)).thenReturn(true);
+        ReplicationQueueItemState state = mock(ReplicationQueueItemState.class);
+        when(queue.getStatus(replicationPackage)).thenReturn(state);
+        ReplicationQueueItemState returnedState = singleQueueDistributionStrategy.add(replicationPackage, agent, queueProvider);
+        assertNotNull(returnedState);
+    }
+}

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueueTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueueTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueueTest.java (original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueueTest.java Mon Dec  9 13:37:48 2013
@@ -74,7 +74,7 @@ public class JobHandlingReplicationQueue
         assertTrue(queue.add(pkg));
         ReplicationQueueItemState status = queue.getStatus(pkg);
         assertNotNull(status);
-        assertFalse(status.isSuccessfull());
+        assertFalse(status.isSuccessful());
         assertEquals(ItemState.DROPPED, status.getItemState());
     }
 

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingUtilsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingUtilsTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingUtilsTest.java (original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingUtilsTest.java Mon Dec  9 13:37:48 2013
@@ -38,7 +38,7 @@ public class JobHandlingUtilsTest {
         ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
         InputStream stream = IOUtils.toInputStream("some text");
         when(replicationPackage.getInputStream()).thenReturn(stream);
-        when(replicationPackage.getAction()).thenReturn("ACTIVATE");
+        when(replicationPackage.getAction()).thenReturn("ADD");
         when(replicationPackage.getId()).thenReturn("an-id");
         when(replicationPackage.getLength()).thenReturn(10l);
         when(replicationPackage.getPaths()).thenReturn(new String[]{"/content", "/apps"});

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueueTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueueTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueueTest.java (original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueueTest.java Mon Dec  9 13:37:48 2013
@@ -18,17 +18,16 @@
  */
 package org.apache.sling.replication.queue.impl.simple;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-import org.junit.Test;
-
 import org.apache.sling.replication.agent.ReplicationAgent;
 import org.apache.sling.replication.queue.ReplicationQueue;
 import org.apache.sling.replication.queue.ReplicationQueueItemState;
 import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
 
 /**
  * Testcase for {@link SimpleReplicationQueue}
@@ -38,7 +37,7 @@ public class SimpleReplicationQueueTest 
     @Test
     public void testPackageAddition() throws Exception {
         ReplicationAgent agent = mock(ReplicationAgent.class);
-        ReplicationQueue queue = new SimpleReplicationQueue(agent);
+        ReplicationQueue queue = new SimpleReplicationQueue(agent, "default");
         ReplicationPackage pkg = mock(ReplicationPackage.class);
         assertTrue(queue.add(pkg));
     }
@@ -46,26 +45,26 @@ public class SimpleReplicationQueueTest 
     @Test
     public void testPackageAdditionAndRemoval() throws Exception {
         ReplicationAgent agent = mock(ReplicationAgent.class);
-        ReplicationQueue queue = new SimpleReplicationQueue(agent);
+        ReplicationQueue queue = new SimpleReplicationQueue(agent, "default");
         ReplicationPackage pkg = mock(ReplicationPackage.class);
         assertTrue(queue.add(pkg));
         queue.removeHead();
         ReplicationQueueItemState status = queue.getStatus(pkg);
         assertNotNull(status);
-        assertTrue(status.isSuccessfull());
+        assertTrue(status.isSuccessful());
     }
 
     @Test
     public void testPackageAdditionRetrievalAndRemoval() throws Exception {
         ReplicationAgent agent = mock(ReplicationAgent.class);
-        ReplicationQueue queue = new SimpleReplicationQueue(agent);
+        ReplicationQueue queue = new SimpleReplicationQueue(agent, "default");
         ReplicationPackage pkg = mock(ReplicationPackage.class);
         assertTrue(queue.add(pkg));
         assertEquals(pkg, queue.getHead());
         queue.removeHead();
         ReplicationQueueItemState status = queue.getStatus(pkg);
         assertNotNull(status);
-        assertTrue(status.isSuccessfull());
+        assertTrue(status.isSuccessful());
         assertEquals(1, status.getAttempts());
     }
 

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/ChainReplicateReplicationRuleTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,122 @@
+/*
+ * 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.rule.impl;
+
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Testcase for {@link ChainReplicateReplicationRule}
+ */
+public class ChainReplicateReplicationRuleTest {
+
+    @Test
+    public void testSignatureNotNull() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        assertNotNull(chainPathReplicationRule.getSignature());
+    }
+
+    @Test
+    public void testSignatureMatching() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        assertFalse(chainPathReplicationRule.signatureMatches(""));
+        assertTrue(chainPathReplicationRule.signatureMatches("chain on path: /apps"));
+        assertTrue(chainPathReplicationRule.signatureMatches("chain on path: /apps/sling"));
+        assertFalse(chainPathReplicationRule.signatureMatches("chain on path: /"));
+        assertFalse(chainPathReplicationRule.signatureMatches("chain on path: foo bar"));
+    }
+
+    @Test
+    public void testApplyWithNonMatchingString() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        String ruleString = "";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        chainPathReplicationRule.apply(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testApplyWithMatchingString() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        String ruleString = "chain on path: /foo/bar";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        chainPathReplicationRule.apply(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testApplyWithMatchingStringAndRegisteredContext() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        String ruleString = "chain on path: /foo/bar";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        BundleContext context = mock(BundleContext.class);
+        chainPathReplicationRule.activate(context);
+        chainPathReplicationRule.apply(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testApplyWithNonMatchingStringAndRegisteredContext() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        String ruleString = "chain on path: 1 2 3";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        BundleContext context = mock(BundleContext.class);
+        chainPathReplicationRule.activate(context);
+        chainPathReplicationRule.apply(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testUndoWithNonMatchingString() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        String ruleString = "";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        chainPathReplicationRule.undo(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testUndoWithMatchingString() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        String ruleString = "chain on path: /foo/bar";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        chainPathReplicationRule.undo(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testUndoWithMatchingStringAndRegisteredContext() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        String ruleString = "chain on path: /foo/bar";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        BundleContext context = mock(BundleContext.class);
+        chainPathReplicationRule.activate(context);
+        chainPathReplicationRule.undo(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testUndoWithNonMatchingStringAndRegisteredContext() throws Exception {
+        ChainReplicateReplicationRule chainPathReplicationRule = new ChainReplicateReplicationRule();
+        String ruleString = "chain on path: 1 2 3";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        BundleContext context = mock(BundleContext.class);
+        chainPathReplicationRule.activate(context);
+        chainPathReplicationRule.undo(ruleString, replicationAgent);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngineTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngineTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngineTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/DefaultReplicationRuleEngineTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.rule.impl;
+
+import java.util.Collections;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.rule.ReplicationRule;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link DefaultReplicationRuleEngine}
+ */
+public class DefaultReplicationRuleEngineTest {
+
+    @Test
+    public void testApplyWithNoRules() throws Exception {
+        DefaultReplicationRuleEngine defaultReplicationRuleEngine = new DefaultReplicationRuleEngine();
+        String ruleString = "do something sometimes";
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        defaultReplicationRuleEngine.applyRules(agent, ruleString);
+    }
+
+    @Test
+    public void testApplyWithNoMatchingRules() throws Exception {
+        DefaultReplicationRuleEngine defaultReplicationRuleEngine = new DefaultReplicationRuleEngine();
+        String ruleString = "do something sometimes";
+        ReplicationRule rule = mock(ReplicationRule.class);
+        when(rule.signatureMatches(ruleString)).thenReturn(false);
+        defaultReplicationRuleEngine.bindReplicationRule(rule, Collections.<String,Object>emptyMap());
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        defaultReplicationRuleEngine.applyRules(agent, ruleString);
+    }
+
+    @Test
+    public void testApplyWithMatchingRules() throws Exception {
+        DefaultReplicationRuleEngine defaultReplicationRuleEngine = new DefaultReplicationRuleEngine();
+        String ruleString = "do something sometimes";
+        ReplicationRule rule = mock(ReplicationRule.class);
+        when(rule.signatureMatches(ruleString)).thenReturn(true);
+        defaultReplicationRuleEngine.bindReplicationRule(rule, Collections.<String,Object>emptyMap());
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        defaultReplicationRuleEngine.applyRules(agent, ruleString);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/rule/impl/TriggerPathReplicationRuleTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,122 @@
+/*
+ * 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.rule.impl;
+
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Testcase for {@link TriggerPathReplicationRule}
+ */
+public class TriggerPathReplicationRuleTest {
+
+    @Test
+    public void testSignatureNotNull() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        assertNotNull(triggerPathReplicationRule.getSignature());
+    }
+
+    @Test
+    public void testSignatureMatching() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        assertFalse(triggerPathReplicationRule.signatureMatches(""));
+        assertTrue(triggerPathReplicationRule.signatureMatches("trigger on path: /apps"));
+        assertTrue(triggerPathReplicationRule.signatureMatches("trigger on path: /apps/sling"));
+        assertFalse(triggerPathReplicationRule.signatureMatches("trigger on path: /"));
+        assertFalse(triggerPathReplicationRule.signatureMatches("trigger on path: foo bar"));
+    }
+
+    @Test
+    public void testApplyWithNonMatchingString() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        String ruleString = "";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        triggerPathReplicationRule.apply(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testApplyWithMatchingString() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        String ruleString = "trigger on path: /foo/bar";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        triggerPathReplicationRule.apply(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testApplyWithMatchingStringAndRegisteredContext() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        String ruleString = "trigger on path: /foo/bar";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        BundleContext context = mock(BundleContext.class);
+        triggerPathReplicationRule.activate(context);
+        triggerPathReplicationRule.apply(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testApplyWithNonMatchingStringAndRegisteredContext() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        String ruleString = "trigger on path: 1 2 3";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        BundleContext context = mock(BundleContext.class);
+        triggerPathReplicationRule.activate(context);
+        triggerPathReplicationRule.apply(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testUndoWithNonMatchingString() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        String ruleString = "";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        triggerPathReplicationRule.undo(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testUndoWithMatchingString() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        String ruleString = "trigger on path: /foo/bar";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        triggerPathReplicationRule.undo(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testUndoWithMatchingStringAndRegisteredContext() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        String ruleString = "trigger on path: /foo/bar";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        BundleContext context = mock(BundleContext.class);
+        triggerPathReplicationRule.activate(context);
+        triggerPathReplicationRule.undo(ruleString, replicationAgent);
+    }
+
+    @Test
+    public void testUndoWithNonMatchingStringAndRegisteredContext() throws Exception {
+        TriggerPathReplicationRule triggerPathReplicationRule = new TriggerPathReplicationRule();
+        String ruleString = "trigger on path: 1 2 3";
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        BundleContext context = mock(BundleContext.class);
+        triggerPathReplicationRule.activate(context);
+        triggerPathReplicationRule.undo(ruleString, replicationAgent);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/VoidReplicationPackageTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/VoidReplicationPackageTest.java?rev=1549567&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/VoidReplicationPackageTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/VoidReplicationPackageTest.java Mon Dec  9 13:37:48 2013
@@ -0,0 +1,48 @@
+/*
+ * 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.serialization.impl;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import org.apache.commons.io.IOUtils;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Testcase for {@link VoidReplicationPackage}
+ */
+public class VoidReplicationPackageTest {
+
+    @Test
+    public void testCreatedAndReadPackagesEquality() throws Exception {
+        ReplicationRequest request = new ReplicationRequest(123l, ReplicationActionType.DELETE, "/abc");
+        VoidReplicationPackage createdPackage = new VoidReplicationPackage(request, "VOID");
+        VoidReplicationPackage readPackage = VoidReplicationPackage.fromStream(new ByteArrayInputStream("DELETE:[/abc]:123".getBytes()));
+        assertEquals(createdPackage.getId(), readPackage.getId());
+        assertEquals(createdPackage.getAction(), readPackage.getAction());
+        assertEquals(createdPackage.getType(), readPackage.getType());
+        assertEquals(createdPackage.getLength(), readPackage.getLength());
+        assertEquals(Arrays.toString(createdPackage.getPaths()), Arrays.toString(readPackage.getPaths()));
+        assertTrue(IOUtils.contentEquals(createdPackage.getInputStream(), readPackage.getInputStream()));
+    }
+}

Modified: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilderTest.java?rev=1549567&r1=1549566&r2=1549567&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilderTest.java (original)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilderTest.java Mon Dec  9 13:37:48 2013
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.mock;
 public class FileVaultReplicationPackageBuilderTest {
 
     @Test
-    public void testCreatePackageForActivationWithoutPermissions() throws Exception {
+    public void testCreatePackageForAddWithoutPermissions() throws Exception {
         try {
             SlingRepository repository = mock(SlingRepository.class);
             FileVaultReplicationPackageBuilder fileVaultReplicationPackageBuilder = new FileVaultReplicationPackageBuilder();
@@ -47,7 +47,7 @@ public class FileVaultReplicationPackage
             packagingField.set(fileVaultReplicationPackageBuilder, packaging);
 
             ReplicationRequest request = mock(ReplicationRequest.class);
-            fileVaultReplicationPackageBuilder.createPackageForActivation(request);
+            fileVaultReplicationPackageBuilder.createPackageForAdd(request);
             fail("cannot create a package without supplying needed credentials");
         } catch (Throwable t) {
             // expected to fail



Mime
View raw message