incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1547378 [4/5] - in /sling/trunk/contrib/extensions/replication: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/replication/ src/main/java/org/apa...
Date Tue, 03 Dec 2013 13:19:53 GMT
Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerFactory.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerFactory.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerFactory.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,46 @@
+/*
+ * 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 java.util.Map;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandlerFactory;
+
+
+@Component(immediate = true)
+@Service(value = AuthenticationHandlerFactory.class)
+@Property(name = "name", value = NopAuthenticationHandlerFactory.TYPE)
+public class NopAuthenticationHandlerFactory implements AuthenticationHandlerFactory {
+    public static final String TYPE = "nop";
+
+    private static final AuthenticationHandler<Object, Object> nopAuthenticationHandler = new NopAuthenticationHandler();
+
+    public AuthenticationHandler<Object, Object> createAuthenticationHandler(Map<String, String> properties) {
+        return nopAuthenticationHandler;
+    }
+
+    public String getType() {
+        return TYPE;
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandler.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandler.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandler.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,74 @@
+/*
+ * 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 javax.jcr.Credentials;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.replication.transport.authentication.AuthenticationContext;
+import org.apache.sling.replication.transport.authentication.AuthenticationException;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RepositoryAuthenticationHandler implements AuthenticationHandler<SlingRepository, Session> {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final Credentials credentials;
+
+    public RepositoryAuthenticationHandler(String user, String password) {
+        this.credentials = new SimpleCredentials(user, password.toCharArray());
+    }
+
+    public boolean canAuthenticate(Class<?> authenticable) {
+        return SlingRepository.class.isAssignableFrom(authenticable);
+    }
+
+    public Session authenticate(SlingRepository authenticable, AuthenticationContext context)
+                    throws AuthenticationException {
+        if (authenticable instanceof SlingRepository) {
+            String path = context.getAttribute("path", String.class);
+            if (path != null) {
+                try {
+                    Session session = authenticable.login(credentials);
+                    if (!session.nodeExists(path)) {
+                        throw new AuthenticationException("failed to read path " + path);
+                    } else {
+                        if (log.isInfoEnabled()) {
+                            log.info("authenticated path {} ", path);
+                        }
+                        return session;
+                    }
+                } catch (RepositoryException re) {
+                    throw new AuthenticationException(re);
+                }
+            } else {
+                throw new AuthenticationException(
+                                "the path to authenticate is missing from the context");
+            }
+        } else {
+            throw new AuthenticationException("could not authenticate a " + authenticable);
+        }
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandlerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandlerFactory.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandlerFactory.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/RepositoryAuthenticationHandlerFactory.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,56 @@
+/*
+ * 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 java.util.Map;
+import javax.jcr.Session;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandlerFactory;
+
+
+@Component(immediate = true)
+@Service(value = AuthenticationHandlerFactory.class)
+@Property(name = "name", value = RepositoryAuthenticationHandlerFactory.TYPE)
+public class RepositoryAuthenticationHandlerFactory implements AuthenticationHandlerFactory {
+    public static final String TYPE = "repo-user";
+
+    public AuthenticationHandler<SlingRepository, Session> createAuthenticationHandler(Map<String, String> properties) {
+        String user = null;
+        Object userProp = properties.get("user");
+        if (userProp != null) {
+            user = String.valueOf(userProp);
+        }
+        String password = null;
+        Object passwordProp = properties.get("password");
+        if (passwordProp != null) {
+            password = String.valueOf(passwordProp);
+        }
+        return new RepositoryAuthenticationHandler(user, password);
+    }
+
+    public String getType() {
+        return TYPE;
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandler.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandler.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandler.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,69 @@
+/*
+ * 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.HttpHost;
+import org.apache.http.client.fluent.Executor;
+import org.apache.sling.replication.communication.ReplicationEndpoint;
+import org.apache.sling.replication.transport.authentication.AuthenticationContext;
+import org.apache.sling.replication.transport.authentication.AuthenticationException;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UserCredentialsAuthenticationHandler implements
+        AuthenticationHandler<Executor, Executor> {
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+
+    private String username;
+
+    private String password;
+
+    public UserCredentialsAuthenticationHandler(String username, String password) {
+        this.username = username;
+        this.password = password;
+    }
+
+    public Executor authenticate(Executor authenticable, AuthenticationContext context)
+                    throws AuthenticationException {
+        if (authenticable instanceof Executor) {
+            ReplicationEndpoint endpoint = context.getAttribute("endpoint",
+                            ReplicationEndpoint.class);
+            if (endpoint != null) {
+                Executor authenticated = ((Executor) authenticable).auth(new HttpHost(endpoint
+                                .getUri().getHost()), username, password);
+                if (log.isInfoEnabled()) {
+                    log.info("authenticated executor {} with user and password", authenticated);
+                }
+                return authenticated;
+            } else {
+                throw new AuthenticationException(
+                                "the endpoint to authenticate is missing from the context");
+            }
+        } else {
+            throw new AuthenticationException("could not authenticate a " + authenticable);
+        }
+    }
+
+    public boolean canAuthenticate(Class<?> authenticable) {
+        return Executor.class.isAssignableFrom(authenticable);
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerFactory.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerFactory.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerFactory.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,56 @@
+/*
+ * 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 java.util.Map;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.http.client.fluent.Executor;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandlerFactory;
+
+
+@Component(immediate = true)
+@Service(value = AuthenticationHandlerFactory.class)
+@Property(name = "name", value = UserCredentialsAuthenticationHandlerFactory.TYPE)
+public class UserCredentialsAuthenticationHandlerFactory implements AuthenticationHandlerFactory {
+    public static final String TYPE = "user";
+
+    public AuthenticationHandler<Executor, Executor> createAuthenticationHandler(
+                    Map<String, String> properties) {
+        String user = null;
+        Object userProp = properties.get("user");
+        if (userProp != null) {
+            user = String.valueOf(userProp);
+        }
+        String password = null;
+        Object passwordProp = properties.get("password");
+        if (passwordProp != null) {
+            password = String.valueOf(passwordProp);
+        }
+        return new UserCredentialsAuthenticationHandler(user, password);
+    }
+
+    public String getType() {
+        return TYPE;
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/HttpTransportHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/HttpTransportHandler.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/HttpTransportHandler.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/HttpTransportHandler.java Tue Dec  3 13:19:50 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.transport.impl;
+
+import java.io.IOException;
+import java.util.Arrays;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.http.client.fluent.Content;
+import org.apache.http.client.fluent.Executor;
+import org.apache.http.client.fluent.Request;
+import org.apache.http.client.fluent.Response;
+import org.apache.http.entity.ContentType;
+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.ReplicationTransportException;
+import org.apache.sling.replication.transport.TransportHandler;
+import org.apache.sling.replication.transport.authentication.AuthenticationContext;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * basic HTTP POST {@link TransportHandler}
+ */
+@Component(metatype = false)
+@Service(value = TransportHandler.class)
+@Property(name = "name", value = HttpTransportHandler.NAME)
+public class HttpTransportHandler implements TransportHandler {
+
+    public static final String NAME = "http";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @SuppressWarnings("unchecked")
+    public void transport(ReplicationPackage replicationPackage,
+                          ReplicationEndpoint replicationEndpoint,
+                          AuthenticationHandler<?, ?> authenticationHandler)
+            throws ReplicationTransportException {
+        if (log.isInfoEnabled()) {
+            log.info("delivering package {} to {} using auth {}",
+                    new Object[]{replicationPackage.getId(),
+                            replicationEndpoint.getUri(), authenticationHandler});
+        }
+        try {
+            Executor executor = Executor.newInstance();
+            AuthenticationContext context = new AuthenticationContext();
+            context.addAttribute("endpoint", replicationEndpoint);
+            executor = ((AuthenticationHandler<Executor, Executor>) authenticationHandler)
+                    .authenticate(executor, context);
+
+            String[] paths = replicationPackage.getPaths();
+            String type = replicationPackage.getType();
+            String pathsString = Arrays.toString(paths);
+            ReplicationActionType action = ReplicationActionType.valueOf(replicationPackage
+                    .getAction());
+            Request req = Request.Post(replicationEndpoint.getUri()).useExpectContinue()
+                    .addHeader("Path", pathsString).addHeader("Action", action.toString())
+                    .addHeader("Type", type);
+            if (replicationPackage.getInputStream() != null) {
+                req = req.bodyStream(replicationPackage.getInputStream(),
+                        ContentType.APPLICATION_OCTET_STREAM);
+            }
+            Response response = executor.execute(req);
+            if (response != null) {
+                Content content = response.returnContent();
+                if (log.isInfoEnabled()) {
+                    log.info("Replication content of type {} for {} delivered: {}", new Object[]{
+                            type, pathsString, content});
+                }
+            }
+            else {
+                throw new IOException("response is empty");
+            }
+        } catch (Exception e) {
+            throw new ReplicationTransportException(e);
+        }
+    }
+
+    public boolean supportsAuthenticationHandler(AuthenticationHandler<?, ?> authenticationHandler) {
+        return authenticationHandler.canAuthenticate(Executor.class);
+    }
+}
\ No newline at end of file

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/PollingTransportHandler.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,114 @@
+/*
+ * 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.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.fluent.Executor;
+import org.apache.http.client.fluent.Request;
+import org.apache.http.client.fluent.Response;
+import org.apache.jackrabbit.util.Text;
+import org.apache.sling.replication.communication.ReplicationActionType;
+import org.apache.sling.replication.communication.ReplicationEndpoint;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilderProvider;
+import org.apache.sling.replication.transport.ReplicationTransportException;
+import org.apache.sling.replication.transport.TransportHandler;
+import org.apache.sling.replication.transport.authentication.AuthenticationContext;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * basic HTTP GET {@link TransportHandler}
+ */
+@Component(metatype = false)
+@Service(value = TransportHandler.class)
+@Property(name = "name", value = PollingTransportHandler.NAME)
+public class PollingTransportHandler implements TransportHandler {
+
+    public static final String NAME = "poll";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference
+    private ReplicationPackageBuilderProvider packageBuilderProvider;
+
+    @SuppressWarnings("unchecked")
+    public void transport(ReplicationPackage replicationPackage,
+                    ReplicationEndpoint replicationEndpoint,
+                    AuthenticationHandler<?, ?> authenticationHandler)
+                    throws ReplicationTransportException {
+        if (log.isInfoEnabled()) {
+            log.info("polling from {}", replicationEndpoint.getUri());
+        }
+        try {
+            Executor executor = Executor.newInstance();
+            AuthenticationContext context = new AuthenticationContext();
+            context.addAttribute("endpoint", replicationEndpoint);
+            executor = ((AuthenticationHandler<Executor, Executor>) authenticationHandler)
+                            .authenticate(executor, context);
+
+            Request req = Request.Get(replicationEndpoint.getUri()).useExpectContinue();
+            // TODO : missing queue header
+            Response response = executor.execute(req);
+            HttpResponse httpResponse = response.returnResponse();
+            HttpEntity entity = httpResponse.getEntity();
+            Header typeHeader = httpResponse.getFirstHeader("type");
+            Header pathsHeader = httpResponse.getFirstHeader("path");
+            Header actionHeader = httpResponse.getFirstHeader("action");
+
+            if (typeHeader != null && pathsHeader != null && actionHeader != null) {
+                String type = typeHeader.getValue();
+                String[] paths = Text.unescape(pathsHeader.getValue()).replace("[", "")
+                                .replace("]", "").split(", ");
+                ReplicationActionType action = ReplicationActionType.valueOf(actionHeader
+                                .getValue());
+                ReplicationRequest replicationRequest = new ReplicationRequest(
+                                System.currentTimeMillis(), action, paths);
+
+                ReplicationPackage readPackage = packageBuilderProvider
+                                .getReplicationPacakageBuilder(type).readPackage(
+                                                replicationRequest, entity.getContent(), true);
+
+                if (log.isInfoEnabled()) {
+                    log.info("package {} fetched and installed", readPackage.getId());
+                }
+
+            } else {
+                if (log.isInfoEnabled()) {
+                    log.info("nothing to fetch");
+                }
+            }
+        } catch (Exception e) {
+            throw new ReplicationTransportException(e);
+        }
+
+    }
+
+    public boolean supportsAuthenticationHandler(AuthenticationHandler<?, ?> authenticationHandler) {
+        return authenticationHandler.canAuthenticate(Executor.class);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandler.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandler.java (added)
+++ sling/trunk/contrib/extensions/replication/src/main/java/org/apache/sling/replication/transport/impl/RepositoryTransportHandler.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,96 @@
+/*
+ * 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.impl;
+
+import java.net.URI;
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.replication.communication.ReplicationEndpoint;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.apache.sling.replication.transport.ReplicationTransportException;
+import org.apache.sling.replication.transport.TransportHandler;
+import org.apache.sling.replication.transport.authentication.AuthenticationContext;
+import org.apache.sling.replication.transport.authentication.AuthenticationHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(metatype = false)
+@Service(value = TransportHandler.class)
+@Property(name = "name", value = RepositoryTransportHandler.NAME)
+public class RepositoryTransportHandler implements TransportHandler {
+
+    public static final String NAME = "repository";
+
+    private static final String REPO_SCHEME = "repo";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference
+    private SlingRepository repository;
+
+    public void transport(ReplicationPackage replicationPackage,
+                    ReplicationEndpoint replicationEndpoint,
+                    AuthenticationHandler<?, ?> authenticationHandler)
+                    throws ReplicationTransportException {
+        if (validateEndpoint(replicationEndpoint)) {
+            try {
+                AuthenticationContext authenticationContext = new AuthenticationContext();
+                String path = new StringBuilder(replicationEndpoint.getUri().getHost()).append(
+                                replicationEndpoint.getUri().getPath()).toString();
+                authenticationContext.addAttribute("path", path);
+                @SuppressWarnings("unchecked")
+                Session session = ((AuthenticationHandler<SlingRepository, Session>) authenticationHandler)
+                                .authenticate(repository, authenticationContext);
+                if (session != null) {
+                    Node addedNode = session.getNode(path).addNode(replicationPackage.getId(),
+                                    NodeType.NT_FILE);
+                    if (log.isInfoEnabled()) {
+                        log.info("package {} delivered to the repository as node {} ",
+                                        replicationPackage.getId(), addedNode.getPath());
+                    }
+                    // TODO : trigger event, this event can be used to ask an author to get the persisted package
+                } else {
+                    throw new ReplicationTransportException(
+                                    "could not get a Session to deliver package to the repository");
+                }
+            } catch (Exception e) {
+                throw new ReplicationTransportException(e);
+            }
+        } else {
+            throw new ReplicationTransportException("invalid endpoint "
+                            + replicationEndpoint.getUri());
+        }
+    }
+
+    private boolean validateEndpoint(ReplicationEndpoint replicationEndpoint) {
+        URI uri = replicationEndpoint.getUri();
+        return REPO_SCHEME.equals(uri.getScheme()) && uri.getHost() != null;
+    }
+
+    public boolean supportsAuthenticationHandler(AuthenticationHandler<?, ?> authenticationHandler) {
+        return authenticationHandler.canAuthenticate(SlingRepository.class);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish-reverse.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish-reverse.json?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish-reverse.json (added)
+++ sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish-reverse.json Tue Dec  3 13:19:50 2013
@@ -0,0 +1,11 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "publish-reverse",
+    "endpoint" : "http://localhost:4503/system/replication/agent/reverse-pub",
+    "TransportHandler.target" : "(name=poll)", 
+    "ReplicationPackageBuilder.target" : "(name=vlt)",
+    "ReplicationQueueProvider.target" : "(name=sjh)",
+    "AuthenticationHandlerFactory.target" : "(name=user)",
+    "authentication.properties" : ["user=admin","password=admin"],
+    "ReplicationQueueDistributionStrategy.target" : "(name=single)"
+}

Added: sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish.json?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish.json (added)
+++ sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-publish.json Tue Dec  3 13:19:50 2013
@@ -0,0 +1,11 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "publish",
+    "endpoint" : "http://localhost:4503/system/replication/receive",
+    "TransportHandler.target" : "(name=http)", 
+    "ReplicationPackageBuilder.target" : "(name=vlt)",
+    "ReplicationQueueProvider.target" : "(name=sjh)",
+    "AuthenticationHandlerFactory.target" : "(name=user)",
+    "authentication.properties" : ["user=admin","password=admin"],
+    "ReplicationQueueDistributionStrategy.target" : "(name=single)"
+}

Added: sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reversehttp.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reversehttp.json?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reversehttp.json (added)
+++ sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reversehttp.json Tue Dec  3 13:19:50 2013
@@ -0,0 +1,12 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "reversehttp",
+    "endpoint" : "http://localhost:4502/system/replication/receive",
+    "TransportHandler.target" : "(name=http)", 
+    "ReplicationPackageBuilder.target" : "(name=vlt)",
+    "ReplicationQueueProvider.target" : "(name=sjh)",
+    "AuthenticationHandlerFactory.target" : "(name=user)",
+    "authentication.properties" : ["user=admin","password=admin"],
+    "ReplicationQueueDistributionStrategy.target" : "(name=error)",
+    "rules" : ["trigger on path: /content/usergenerated"]
+}

Added: sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/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/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json (added)
+++ sling/trunk/contrib/extensions/replication/src/main/resources/SLING-CONTENT/libs/sling/replication/agents/org.apache.sling.replication.agent.impl.ReplicationAgentServiceFactory-reverserepo.json Tue Dec  3 13:19:50 2013
@@ -0,0 +1,12 @@
+{
+    "jcr:primaryType" : "sling:OsgiConfig",
+    "name" : "reverserepo",
+    "endpoint" : "repo://var/replication/outbox",
+    "TransportHandler.target" : "(name=repository)", 
+    "ReplicationPackageBuilder.target" : "(name=vlt)",
+    "ReplicationQueueProvider.target" : "(name=sjh)",
+    "AuthenticationHandlerFactory.target" : "(name=repo-user)",
+    "authentication.properties" : ["user=admin","password=admin"],
+    "ReplicationQueueDistributionStrategy.target" : "(name=single)",
+    "rules" : ["trigger on path: /content"]
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/ReplicationAgentConfigurationTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import java.util.Properties;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Testcase for {@link ReplicationAgentConfiguration}
+ */
+public class ReplicationAgentConfigurationTest {
+    @Test
+    public void testDefaultConfiguration() throws Exception {
+        ReplicationAgentConfiguration replicationAgentConfiguration = new ReplicationAgentConfiguration(new Properties());
+        assertNotNull(replicationAgentConfiguration.getAuthenticationProperties());
+        assertNotNull(replicationAgentConfiguration.getEndpoint());
+        assertNotNull(replicationAgentConfiguration.getName());
+        assertNotNull(replicationAgentConfiguration.getTargetAuthenticationHandlerFactory());
+        assertNotNull(replicationAgentConfiguration.getTargetReplicationBuilder());
+        assertNotNull(replicationAgentConfiguration.getTargetReplicationQueueProvider());
+        assertNotNull(replicationAgentConfiguration.getTargetTransportHandler());
+    }
+
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/DefaultReplicationAgentConfigurationManagerTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,85 @@
+/*
+ * 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.Properties;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link DefaultReplicationAgentConfigurationManager}
+ */
+public class DefaultReplicationAgentConfigurationManagerTest {
+
+    @Test
+    public void testRetrievalWithNoConfigurationAvailable() throws Exception {
+        try {
+            ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
+            ReplicationAgent agent = mock(ReplicationAgent.class);
+            DefaultReplicationAgentConfigurationManager defaultReplicationAgentConfigurationManager = new DefaultReplicationAgentConfigurationManager();
+            Field configAdminField = defaultReplicationAgentConfigurationManager.getClass().getDeclaredField("configAdmin");
+            configAdminField.setAccessible(true);
+            configAdminField.set(defaultReplicationAgentConfigurationManager, configAdmin);
+            defaultReplicationAgentConfigurationManager.getConfiguration(agent);
+            fail("an exception should be thrown when no configuration is available");
+        } catch (Exception e) {
+            // failure is expected
+        }
+    }
+
+    @Test
+    public void testRetrievalWithMultipleConfigurationsAvailable() throws Exception {
+        try {
+            ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
+            ReplicationAgent agent = mock(ReplicationAgent.class);
+            when(agent.getName()).thenReturn("publish");
+            when(configAdmin.listConfigurations("(name=publish)")).thenReturn(new Configuration[]{null, null});
+            DefaultReplicationAgentConfigurationManager defaultReplicationAgentConfigurationManager = new DefaultReplicationAgentConfigurationManager();
+            Field configAdminField = defaultReplicationAgentConfigurationManager.getClass().getDeclaredField("configAdmin");
+            configAdminField.setAccessible(true);
+            configAdminField.set(defaultReplicationAgentConfigurationManager, configAdmin);
+            defaultReplicationAgentConfigurationManager.getConfiguration(agent);
+            fail("an exception should be thrown when multiple configurations are available");
+        } catch (Exception e) {
+            // failure is expected
+        }
+    }
+
+    @Test
+    public void testRetrievalWithOneConfigurationAvailable() throws Exception {
+        Configuration configuration = mock(Configuration.class);
+        when(configuration.getProperties()).thenReturn(new Properties());
+        ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        when(agent.getName()).thenReturn("publish");
+        when(configAdmin.listConfigurations("(name=publish)")).thenReturn(new Configuration[]{configuration});
+        DefaultReplicationAgentConfigurationManager defaultReplicationAgentConfigurationManager = new DefaultReplicationAgentConfigurationManager();
+        Field configAdminField = defaultReplicationAgentConfigurationManager.getClass().getDeclaredField("configAdmin");
+        configAdminField.setAccessible(true);
+        configAdminField.set(defaultReplicationAgentConfigurationManager, configAdmin);
+        defaultReplicationAgentConfigurationManager.getConfiguration(agent);
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumerTest.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumerTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentJobConsumerTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,41 @@
+package org.apache.sling.replication.agent.impl;
+
+import org.apache.sling.event.jobs.Job;
+import org.apache.sling.event.jobs.consumer.JobConsumer;
+import org.apache.sling.replication.agent.ReplicationAgent;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+import org.apache.sling.replication.serialization.ReplicationPackageBuilder;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link ReplicationAgentJobConsumer}
+ */
+public class ReplicationAgentJobConsumerTest {
+
+    @Test
+    public void testJobWithSuccessfulAgent() throws Exception {
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        when(replicationAgent.process(any(ReplicationPackage.class))).thenReturn(true);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationAgentJobConsumer replicationAgentJobConsumer = new ReplicationAgentJobConsumer(replicationAgent, packageBuilder);
+        Job job = mock(Job.class);
+        JobConsumer.JobResult jobResult = replicationAgentJobConsumer.process(job);
+        assertEquals(JobConsumer.JobResult.OK, jobResult);
+    }
+
+    @Test
+    public void testJobWithUnsuccessfulAgent() throws Exception {
+        ReplicationAgent replicationAgent = mock(ReplicationAgent.class);
+        when(replicationAgent.process(any(ReplicationPackage.class))).thenReturn(false);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationAgentJobConsumer replicationAgentJobConsumer = new ReplicationAgentJobConsumer(replicationAgent, packageBuilder);
+        Job job = mock(Job.class);
+        JobConsumer.JobResult jobResult = replicationAgentJobConsumer.process(job);
+        assertEquals(JobConsumer.JobResult.FAILED, jobResult);
+    }
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProviderTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/ReplicationAgentResourceProviderTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,110 @@
+/*
+ * 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 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.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;
+
+/**
+ * Testcase for {@link ReplicationAgentResourceProvider}
+ */
+public class ReplicationAgentResourceProviderTest {
+
+    @Test
+    public void testAgentResolutionWithoutSpecifiedAgentService() throws Exception {
+        BundleContext context = mock(BundleContext.class);
+        ReplicationAgentResourceProvider agentResourceProvider = new ReplicationAgentResourceProvider();
+        agentResourceProvider.activate(context);
+        ResourceResolver resourceResolver = mock(ResourceResolver.class);
+        String path = "publish";
+        Resource resource = agentResourceProvider.getResource(resourceResolver, path);
+        assertNull(resource);
+    }
+
+    @Test
+    public void testAgentResolutionWithSpecifiedAgentService() throws Exception {
+        String path = "publish";
+        BundleContext context = mock(BundleContext.class);
+        createMockedReplicationAgent(path, context);
+        ReplicationAgentResourceProvider agentResourceProvider = new ReplicationAgentResourceProvider();
+        agentResourceProvider.activate(context);
+        ResourceResolver resourceResolver = mock(ResourceResolver.class);
+
+        Resource resource = agentResourceProvider.getResource(resourceResolver, path);
+        assertNotNull(resource);
+        assertEquals(ReplicationAgentResource.RESOURCE_TYPE, resource.getResourceType());
+    }
+
+    @Test
+    public void testAgentConfigurationResolutionWithSpecifiedAgentService() throws Exception {
+        String path = "publish";
+        BundleContext context = mock(BundleContext.class);
+        ReplicationAgent replicationAgent = createMockedReplicationAgent(path, context);
+        mockReplicationAgentConfiguration(context, replicationAgent);
+        ReplicationAgentResourceProvider agentResourceProvider = new ReplicationAgentResourceProvider();
+        agentResourceProvider.activate(context);
+        ResourceResolver resourceResolver = mock(ResourceResolver.class);
+
+        Resource resource = agentResourceProvider.getResource(resourceResolver, path
+                        + "/configuration");
+        assertNotNull(resource);
+        assertEquals(ReplicationAgentConfigurationResource.RESOURCE_TYPE, resource.getResourceType());
+    }
+
+    private void mockReplicationAgentConfiguration(BundleContext context,
+                    ReplicationAgent replicationAgent) throws AgentConfigurationException {
+        ServiceReference configurationManagerServiceReference = mock(ServiceReference.class);
+        when(context.getServiceReference(ReplicationAgentConfigurationManager.class.getName()))
+                        .thenReturn(configurationManagerServiceReference);
+        ReplicationAgentConfigurationManager configurationManager = mock(ReplicationAgentConfigurationManager.class);
+        when(context.getService(configurationManagerServiceReference)).thenReturn(
+                        configurationManager);
+        ReplicationAgentConfiguration configuration = mock(ReplicationAgentConfiguration.class);
+        when(configurationManager.getConfiguration(replicationAgent)).thenReturn(configuration);
+    }
+
+    private SimpleReplicationAgentImpl 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();
+        when(context.getServiceReferences(ReplicationAgent.class.getName(), filter)).thenReturn(
+                        agentServiceReferences);
+        SimpleReplicationAgentImpl replicationAgent = new SimpleReplicationAgentImpl(path, 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/SimpleReplicationAgentImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentImplTest.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentImplTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/agent/impl/SimpleReplicationAgentImplTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,103 @@
+/*
+ * 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.ReplicationQueueDistributionStrategy;
+import org.apache.sling.replication.queue.ReplicationQueueProvider;
+import org.apache.sling.replication.queue.impl.SingleQueueDistributionStrategy;
+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.AuthenticationHandler;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link SimpleReplicationAgentImpl}
+ */
+public class SimpleReplicationAgentImplTest {
+
+    @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);
+        AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
+        ReplicationQueueDistributionStrategy distributionHandler = new SingleQueueDistributionStrategy();
+        SimpleReplicationAgentImpl agent = new SimpleReplicationAgentImpl(name, endpoint,
+                        transportHandler, packageBuilder, queueProvider, authenticationHandler, distributionHandler);
+        ReplicationPackage item = mock(ReplicationPackage.class);
+        assertTrue(agent.process(item));
+    }
+
+    @Test
+    public void testSyncReplication() throws Exception {
+        String name = "sample-agent";
+        String endpoint = "/tmp";
+        TransportHandler transportHandler = mock(TransportHandler.class);
+        ReplicationPackageBuilder packageBuilder = mock(ReplicationPackageBuilder.class);
+        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
+        AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
+        ReplicationQueueDistributionStrategy distributionHandler = new SingleQueueDistributionStrategy();
+        SimpleReplicationAgentImpl agent = new SimpleReplicationAgentImpl(name, endpoint,
+                        transportHandler, packageBuilder, queueProvider, authenticationHandler, distributionHandler);
+        ReplicationRequest request = new ReplicationRequest(System.nanoTime(),
+                        ReplicationActionType.ACTIVATE, "/");
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(packageBuilder.createPackage(request)).thenReturn(replicationPackage);
+        when(queueProvider.getOrCreateQueue(agent, replicationPackage)).thenReturn(
+                        new SimpleReplicationQueue(agent));
+        when(queueProvider.getOrCreateDefaultQueue(agent)).thenReturn(
+              new SimpleReplicationQueue(agent));
+        ReplicationResponse response = agent.execute(request);
+        assertNotNull(response);
+    }
+
+    @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);
+        AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
+        ReplicationQueueDistributionStrategy distributionHandler = new SingleQueueDistributionStrategy();
+        SimpleReplicationAgentImpl agent = new SimpleReplicationAgentImpl(name, endpoint,
+                transportHandler, packageBuilder, queueProvider, authenticationHandler, distributionHandler);
+        ReplicationRequest request = new ReplicationRequest(System.nanoTime(),
+                ReplicationActionType.ACTIVATE, "/");
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(packageBuilder.createPackage(request)).thenReturn(replicationPackage);
+        when(queueProvider.getOrCreateQueue(agent, replicationPackage)).thenReturn(
+                new SimpleReplicationQueue(agent));
+        when(queueProvider.getOrCreateDefaultQueue(agent)).thenReturn(
+                new SimpleReplicationQueue(agent));
+        agent.send(request);
+    }
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueueTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingReplicationQueueTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,81 @@
+/*
+ * 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.jobhandling;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Map;
+
+import org.apache.sling.event.jobs.JobBuilder;
+import org.apache.sling.event.jobs.JobManager;
+import org.junit.Test;
+
+import org.apache.sling.replication.queue.ReplicationQueue;
+import org.apache.sling.replication.queue.ReplicationQueueItemState;
+import org.apache.sling.replication.queue.ReplicationQueueItemState.ItemState;
+import org.apache.sling.replication.serialization.ReplicationPackage;
+
+/**
+ * Testcase for {@link JobHandlingReplicationQueue}
+ */
+public class JobHandlingReplicationQueueTest {
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testPackageAddition() throws Exception {
+        JobManager jobManager = mock(JobManager.class);
+        JobBuilder builder = mock(JobBuilder.class);
+        String topic = JobHandlingReplicationQueue.REPLICATION_QUEUE_TOPIC + "/aname";
+        when(jobManager.createJob(topic)).thenReturn(builder);
+        when(builder.properties(any(Map.class))).thenReturn(builder);
+        ReplicationQueue queue = new JobHandlingReplicationQueue("aname", topic, jobManager);
+        ReplicationPackage pkg = mock(ReplicationPackage.class);
+        InputStream stream = new ByteArrayInputStream("rep".getBytes());
+        when(pkg.getInputStream()).thenReturn(stream);
+        assertTrue(queue.add(pkg));
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testPackageAdditionAndStatusCheck() throws Exception {
+        JobManager jobManager = mock(JobManager.class);
+        JobBuilder builder = mock(JobBuilder.class);
+        String topic = JobHandlingReplicationQueue.REPLICATION_QUEUE_TOPIC + "/aname";
+        when(jobManager.createJob(topic)).thenReturn(builder);
+        when(builder.properties(any(Map.class))).thenReturn(builder);
+        ReplicationQueue queue = new JobHandlingReplicationQueue("aname", topic, jobManager);
+        ReplicationPackage pkg = mock(ReplicationPackage.class);
+        InputStream stream = new ByteArrayInputStream("rep".getBytes());
+        when(pkg.getInputStream()).thenReturn(stream);
+        assertTrue(queue.add(pkg));
+        ReplicationQueueItemState status = queue.getStatus(pkg);
+        assertNotNull(status);
+        assertFalse(status.isSuccessfull());
+        assertEquals(ItemState.DROPPED, status.getItemState());
+    }
+
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingUtilsTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/jobhandling/JobHandlingUtilsTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,66 @@
+/*
+ * 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.jobhandling;
+
+import java.io.InputStream;
+import java.util.Map;
+import org.apache.commons.io.IOUtils;
+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.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * Testcase for {@link JobHandlingUtils}
+ */
+public class JobHandlingUtilsTest {
+    @Test
+    public void testFullPropertiesFromPackageCreation() throws Exception {
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        InputStream stream = IOUtils.toInputStream("some text");
+        when(replicationPackage.getInputStream()).thenReturn(stream);
+        when(replicationPackage.getAction()).thenReturn("ACTIVATE");
+        when(replicationPackage.getId()).thenReturn("an-id");
+        when(replicationPackage.getLength()).thenReturn(10l);
+        when(replicationPackage.getPaths()).thenReturn(new String[]{"/content", "/apps"});
+        when(replicationPackage.getType()).thenReturn("vlt");
+        Map<String,Object> fullPropertiesFromPackage = JobHandlingUtils.createFullPropertiesFromPackage(replicationPackage);
+        assertNotNull(fullPropertiesFromPackage);
+        assertEquals(5, fullPropertiesFromPackage.size());
+        assertNotNull(fullPropertiesFromPackage.get("replication.package.paths"));
+        assertNotNull(fullPropertiesFromPackage.get("replication.package.id"));
+        assertNotNull(fullPropertiesFromPackage.get("replication.package.length"));
+//        assertNotNull(fullPropertiesFromPackage.get("replication.package.stream"));
+        assertNotNull(fullPropertiesFromPackage.get("replication.package.type"));
+        assertNotNull(fullPropertiesFromPackage.get("replication.package.action"));
+    }
+
+    @Test
+    public void testIdPropertiesFromPackageCreation() throws Exception {
+        ReplicationPackage replicationPackage = mock(ReplicationPackage.class);
+        when(replicationPackage.getId()).thenReturn("an-id");
+        Map<String,Object> idPropertiesFromPackage = JobHandlingUtils.createIdPropertiesFromPackage(replicationPackage);
+        assertNotNull(idPropertiesFromPackage);
+        assertEquals(1, idPropertiesFromPackage.size());
+        assertNotNull(idPropertiesFromPackage.get("replication.package.id"));
+    }
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueueTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/queue/impl/simple/SimpleReplicationQueueTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,72 @@
+/*
+ * 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.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;
+
+/**
+ * Testcase for {@link SimpleReplicationQueue}
+ */
+public class SimpleReplicationQueueTest {
+
+    @Test
+    public void testPackageAddition() throws Exception {
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueue queue = new SimpleReplicationQueue(agent);
+        ReplicationPackage pkg = mock(ReplicationPackage.class);
+        assertTrue(queue.add(pkg));
+    }
+
+    @Test
+    public void testPackageAdditionAndRemoval() throws Exception {
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueue queue = new SimpleReplicationQueue(agent);
+        ReplicationPackage pkg = mock(ReplicationPackage.class);
+        assertTrue(queue.add(pkg));
+        queue.removeHead();
+        ReplicationQueueItemState status = queue.getStatus(pkg);
+        assertNotNull(status);
+        assertTrue(status.isSuccessfull());
+    }
+
+    @Test
+    public void testPackageAdditionRetrievalAndRemoval() throws Exception {
+        ReplicationAgent agent = mock(ReplicationAgent.class);
+        ReplicationQueue queue = new SimpleReplicationQueue(agent);
+        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());
+        assertEquals(1, status.getAttempts());
+    }
+
+}

Added: 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=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilderTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/serialization/impl/vlt/FileVaultReplicationPackageBuilderTest.java Tue Dec  3 13:19:50 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.vlt;
+
+import java.lang.reflect.Field;
+import org.apache.jackrabbit.vault.packaging.Packaging;
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.replication.communication.ReplicationRequest;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Testcase for {@link FileVaultReplicationPackageBuilder}
+ */
+public class FileVaultReplicationPackageBuilderTest {
+
+    @Test
+    public void testCreatePackageForActivationWithoutPermissions() throws Exception {
+        try {
+            SlingRepository repository = mock(SlingRepository.class);
+            FileVaultReplicationPackageBuilder fileVaultReplicationPackageBuilder = new FileVaultReplicationPackageBuilder();
+            Field repositoryField = fileVaultReplicationPackageBuilder.getClass().getDeclaredField("repository");
+            repositoryField.setAccessible(true);
+            repositoryField.set(fileVaultReplicationPackageBuilder, repository);
+
+            Packaging packaging = mock(Packaging.class);
+            Field packagingField = fileVaultReplicationPackageBuilder.getClass().getDeclaredField("packaging");
+            packagingField.setAccessible(true);
+            packagingField.set(fileVaultReplicationPackageBuilder, packaging);
+
+            ReplicationRequest request = mock(ReplicationRequest.class);
+            fileVaultReplicationPackageBuilder.createPackageForActivation(request);
+            fail("cannot create a package without supplying needed credentials");
+        } catch (Throwable t) {
+            // expected to fail
+        }
+    }
+}

Added: sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerTest.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/NopAuthenticationHandlerTest.java Tue Dec  3 13:19:50 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.AuthenticationContext;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Testcase for {@link NopAuthenticationHandler}
+ */
+public class NopAuthenticationHandlerTest {
+
+    @Test
+    public void testAuthenticationWithNullAuthenticableAndContext() throws Exception {
+        NopAuthenticationHandler authenticationHandler = new NopAuthenticationHandler();
+        Object authenticable = null;
+        AuthenticationContext context = null;
+        assertEquals(authenticable, authenticationHandler.authenticate(authenticable, context));
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndNullContext() throws Exception {
+        NopAuthenticationHandler authenticationHandler = new NopAuthenticationHandler();
+        Executor authenticable = Executor.newInstance();
+        AuthenticationContext context = null;
+        assertEquals(authenticable, authenticationHandler.authenticate(authenticable, context));
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndEmptyContext() throws Exception {
+        NopAuthenticationHandler authenticationHandler = new NopAuthenticationHandler();
+        Executor authenticable = Executor.newInstance();
+        AuthenticationContext context = new AuthenticationContext();
+        assertEquals(authenticable, authenticationHandler.authenticate(authenticable, context));
+    }
+
+    @Test
+    public void testAuthenticationWithAuthenticableAndCorrectContext() throws Exception {
+        NopAuthenticationHandler authenticationHandler = new NopAuthenticationHandler();
+        Executor authenticable = Executor.newInstance();
+        AuthenticationContext context = new AuthenticationContext();
+        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/UserCredentialsAuthenticationHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerTest.java?rev=1547378&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerTest.java (added)
+++ sling/trunk/contrib/extensions/replication/src/test/java/org/apache/sling/replication/transport/authentication/impl/UserCredentialsAuthenticationHandlerTest.java Tue Dec  3 13:19:50 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.AuthenticationContext;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+/**
+ * Testcase for {@link UserCredentialsAuthenticationHandler}
+ */
+public class UserCredentialsAuthenticationHandlerTest {
+
+    @Test
+    public void testAuthenticationWithNullAuthenticableAndContext() throws Exception {
+        UserCredentialsAuthenticationHandler authenticationHandler = new UserCredentialsAuthenticationHandler(
+                        "foo", "bar");
+        Executor authenticable = null;
+        AuthenticationContext 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 {
+        UserCredentialsAuthenticationHandler authenticationHandler = new UserCredentialsAuthenticationHandler(
+                        "foo", "bar");
+        Executor authenticable = Executor.newInstance();
+        AuthenticationContext 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 {
+        UserCredentialsAuthenticationHandler authenticationHandler = new UserCredentialsAuthenticationHandler(
+                        "foo", "bar");
+        Executor authenticable = Executor.newInstance();
+        AuthenticationContext context = new AuthenticationContext();
+        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 {
+        UserCredentialsAuthenticationHandler authenticationHandler = new UserCredentialsAuthenticationHandler(
+                        "foo", "bar");
+        Executor authenticable = Executor.newInstance();
+        AuthenticationContext context = new AuthenticationContext();
+        context.addAttribute("endpoint", new ReplicationEndpoint("http://www.apache.org"));
+        authenticationHandler.authenticate(authenticable, context);
+    }
+}



Mime
View raw message