You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by to...@apache.org on 2014/03/20 15:56:33 UTC

svn commit: r1579646 - /sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/

Author: tommaso
Date: Thu Mar 20 14:56:32 2014
New Revision: 1579646

URL: http://svn.apache.org/r1579646
Log:
SLING-3470 - Improved coverage of agent and importer resources

Added:
    sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java
      - copied, changed from r1579587, sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/DefaultAgentsIntegrationTest.java
    sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java
      - copied, changed from r1579587, sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterIntegrationTest.java
Removed:
    sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/DefaultAgentsIntegrationTest.java
    sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterIntegrationTest.java
Modified:
    sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationITBase.java

Copied: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java (from r1579587, sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/DefaultAgentsIntegrationTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java?p2=sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java&p1=sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/DefaultAgentsIntegrationTest.java&r1=1579587&r2=1579646&rev=1579646&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/DefaultAgentsIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java Thu Mar 20 14:56:32 2014
@@ -22,9 +22,9 @@ import java.io.IOException;
 import org.junit.Test;
 
 /**
- * Integration test for default replication agents.
+ * Integration test for {@link org.apache.sling.replication.agent.ReplicationAgent} resources
  */
-public class DefaultAgentsIntegrationTest extends ReplicationITBase {
+public class ReplicationAgentResourcesIntegrationTest extends ReplicationITBase {
 
     @Test
     public void testDefaultAgentConfigurationResources() throws IOException {
@@ -93,6 +93,17 @@ public class DefaultAgentsIntegrationTes
 
     @Test
     public void testDefaultAgentsRootResource() throws Exception {
-        assertResourceExists("/libs/sling/replication/agent.json");
+        String rootResource = "/libs/sling/replication/agent.json";
+        assertResourceExists(rootResource);
+        assertJsonResponseEquals(rootResource,
+                "{\"sling:resourceType\":\"replication/agents\",\"items\":[\"publish-reverse\",\"publish\"]}");
+    }
+
+    @Test
+    public void testAgentConfigurationResourceCreation() throws Exception {
+        String newConfigResource = "/libs/sling/replication/config/agent/sample-publish";
+        assertPostResource(201, newConfigResource, "name", "sample-publish", "transportHandler", "(name=author)");
+//        assertResourceExists(newConfigResource + ".json");
+//        assertJsonResponseEquals(newConfigResource + ".json", "{\"sling:resourceType\":\"replication/agent\",\"name\":\"sample-publish\",\"transportHandler\":\"(name=author)\"}");
     }
 }
\ No newline at end of file

Modified: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationITBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationITBase.java?rev=1579646&r1=1579645&r2=1579646&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationITBase.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationITBase.java Thu Mar 20 14:56:32 2014
@@ -1,25 +1,55 @@
 package org.apache.sling.replication.it;
 
 import java.io.IOException;
+import org.apache.sling.testing.tools.http.Request;
 import org.apache.sling.testing.tools.sling.SlingTestBase;
 
+import static org.junit.Assert.assertEquals;
+
 /**
  * Integration test base class for replication
  */
 public abstract class ReplicationITBase extends SlingTestBase {
 
-    protected void assertResourceExists(String path) throws IOException {
+    private static final String JSON_SELECTOR = ".json";
+
+    protected void assertGetResource(int status, String path, String... parameters) throws IOException {
         getRequestExecutor().execute(
-                getRequestBuilder().buildGetRequest(path)
+                getRequestBuilder().buildGetRequest(path, parameters)
                         .withCredentials(getServerUsername(), getServerPassword())
-        ).assertStatus(200);
+        ).assertStatus(status);
     }
 
-    protected void assertResourceDoesNotExist(String path) throws IOException {
+    protected void assertPostResource(int status, String path, String... headers) throws IOException {
+        Request request = getRequestBuilder().buildPostRequest(path);
+        if (headers != null) {
+            assertEquals(0, headers.length % 2);
+            for (int i = 0; i < headers.length; i += 2) {
+                request = request.withHeader(headers[i], headers[i + 1]);
+            }
+        }
         getRequestExecutor().execute(
-                getRequestBuilder().buildGetRequest(path)
+                request.withCredentials(getServerUsername(), getServerPassword())
+        ).assertStatus(status);
+    }
+
+    protected void assertResourceExists(String path) throws IOException {
+        assertGetResource(200, path);
+    }
+
+    protected void assertResourceDoesNotExist(String path) throws IOException {
+        assertGetResource(404, path);
+    }
+
+    protected void assertJsonResponseEquals(String resource, String expectedJsonString) throws IOException {
+        if (!resource.endsWith(JSON_SELECTOR)) {
+            resource += JSON_SELECTOR;
+        }
+        assertEquals(expectedJsonString.trim(), getRequestExecutor().execute(
+                getRequestBuilder().buildGetRequest(resource)
                         .withCredentials(getServerUsername(), getServerPassword())
-        ).assertStatus(404);
+        ).getContent().replaceAll("\n", "").trim());
+
     }
 
 

Copied: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java (from r1579587, sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterIntegrationTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java?p2=sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java&p1=sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterIntegrationTest.java&r1=1579587&r2=1579646&rev=1579646&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java Thu Mar 20 14:56:32 2014
@@ -23,15 +23,20 @@ import org.junit.Test;
 /**
  * Integration test for {@link org.apache.sling.replication.serialization.ReplicationPackageImporter} resources
  */
-public class ReplicationPackageImporterIntegrationTest extends ReplicationITBase {
+public class ReplicationPackageImporterResourcesIntegrationTest extends ReplicationITBase {
 
     @Test
     public void testImporterRootResource() throws Exception {
         assertResourceExists("/libs/sling/replication/importer.json");
+        assertJsonResponseEquals("/libs/sling/replication/importer.json",
+                "{\"sling:resourceType\":\"replication/importers\",\"items\":[\"default\"]}");
     }
 
     @Test
     public void testDefaultImporterResource() throws Exception {
-        assertResourceExists("/libs/sling/replication/importer/default.json");
+        String rootResource = "/libs/sling/replication/importer/default.json";
+        assertResourceExists(rootResource);
+        assertJsonResponseEquals(rootResource,
+                "{\"sling:resourceType\":\"replication/importer\",\"name\":\"default\"}");
     }
 }