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/04/01 12:08:25 UTC
svn commit: r1583591 -
/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/
Author: tommaso
Date: Tue Apr 1 10:08:24 2014
New Revision: 1583591
URL: http://svn.apache.org/r1583591
Log:
SLING-3480 - adding / improving tests for replication configs
Modified:
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationITBase.java
sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java
Modified: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java?rev=1583591&r1=1583590&r2=1583591&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentCommandsIntegrationTest.java Tue Apr 1 10:08:24 2014
@@ -29,20 +29,20 @@ public class ReplicationAgentCommandsInt
@Test
public void testAddCommand() throws Exception {
- String agentResource = "/libs/sling/replication/agent/publish";
- assertPostResource(202, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.ADD.toString(), ReplicationHeader.PATH.toString(), "/libs/sling/replication");
+ String agentResource = getAgentUrl("publish");
+ assertPostResourceWithHeaders(202, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.ADD.toString(), ReplicationHeader.PATH.toString(), "/libs/sling/replication");
}
@Test
public void testPollCommand() throws Exception {
- String agentResource = "/libs/sling/replication/agent/publish";
- assertPostResource(200, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.POLL.toString());
+ String agentResource = getAgentUrl("publish");
+ assertPostResourceWithHeaders(200, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.POLL.toString());
}
@Test
public void testDeleteCommand() throws Exception {
- String agentResource = "/libs/sling/replication/agent/publish";
- assertPostResource(202, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.DELETE.toString(), ReplicationHeader.PATH.toString(), "/not/existing");
+ String agentResource = getAgentUrl("publish");
+ assertPostResourceWithHeaders(202, agentResource, ReplicationHeader.ACTION.toString(), ReplicationActionType.DELETE.toString(), ReplicationHeader.PATH.toString(), "/not/existing");
}
}
\ No newline at end of file
Modified: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java?rev=1583591&r1=1583590&r2=1583591&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationAgentResourcesIntegrationTest.java Tue Apr 1 10:08:24 2014
@@ -28,15 +28,15 @@ public class ReplicationAgentResourcesIn
@Test
public void testDefaultAgentConfigurationResources() throws IOException {
- String[] defaultAgentConfigPaths = new String[]{
- "/libs/sling/replication/config/agent/publish.json",
- "/libs/sling/replication/config/agent/publish-reverse.json",
- "/libs/sling/replication/config/agent/reverserepo.json",
- "/libs/sling/replication/config/agent/author.json",
- "/libs/sling/replication/config/agent/cache-flush.json"
+ String[] defaultAgentNames = new String[]{
+ "publish",
+ "publish-reverse",
+ "reverserepo",
+ "author",
+ "cache-flush"
};
- for (String path : defaultAgentConfigPaths) {
- assertResourceExists(path);
+ for (String agentName : defaultAgentNames) {
+ assertResourceExists(getAgentConfigUrl(agentName));
}
}
@@ -44,66 +44,93 @@ public class ReplicationAgentResourcesIn
@Test
public void testDefaultPublishAgentResources() throws IOException {
// these agents do not exist as they are bundled to publish runMode
- String[] defaultPublishAgents = new String[]{
- "/libs/sling/replication/agent/reverserepo.json",
- "/libs/sling/replication/agent/author.json",
- "/libs/sling/replication/agent/cache-flush.json"
+ String[] defaultPublishAgentNames = new String[]{
+ "reverserepo",
+ "author",
+ "cache-flush"
};
- for (String path : defaultPublishAgents) {
- assertResourceDoesNotExist(path);
+ for (String agentName : defaultPublishAgentNames) {
+ assertResourceDoesNotExist(getAgentUrl(agentName));
}
}
@Test
public void testDefaultAuthorAgentResources() throws IOException {
// these agents exist as they are bundled to author runMode
- String[] defaultAuthorAgents = new String[]{
- "/libs/sling/replication/agent/publish.json",
- "/libs/sling/replication/agent/publish-reverse.json",
+ String[] defaultAuthorAgentNames = new String[]{
+ "publish",
+ "publish-reverse"
};
- for (String path : defaultAuthorAgents) {
- assertResourceExists(path);
+ for (String agentName : defaultAuthorAgentNames) {
+ assertResourceExists(getAgentUrl(agentName));
}
}
@Test
public void testDefaultPublishAgentQueueResources() throws IOException {
// these agent queues do not exist as they are bundled to publish runMode
- String[] defaultPublishAgents = new String[]{
- "/libs/sling/replication/agent/reverserepo/queue.json",
- "/libs/sling/replication/agent/author/queue.json",
- "/libs/sling/replication/agent/cache-flush/queue.json"
+ String[] defaultPublishAgentNames = new String[]{
+ "reverserepo",
+ "author",
+ "cache-flush"
};
- for (String path : defaultPublishAgents) {
- assertResourceDoesNotExist(path);
+ for (String agentName : defaultPublishAgentNames) {
+ assertResourceDoesNotExist(getAgentUrl(agentName)+"/queue");
}
}
@Test
public void testDefaultAuthorAgentQueueResources() throws IOException {
// these agent queues exist as they are bundled to author runMode
- String[] defaultAuthorAgents = new String[]{
- "/libs/sling/replication/agent/publish/queue.json",
- "/libs/sling/replication/agent/publish-reverse/queue.json",
+ String[] defaultAuthorAgentNames = new String[]{
+ "publish",
+ "publish-reverse"
};
- for (String path : defaultAuthorAgents) {
- assertResourceExists(path);
+ for (String agentName : defaultAuthorAgentNames) {
+ assertResourceExists(getAgentUrl(agentName)+"/queue");
}
}
@Test
public void testDefaultAgentsRootResource() throws Exception {
- String rootResource = "/libs/sling/replication/agent.json";
+ String rootResource = getAgentRootUrl();
assertResourceExists(rootResource);
- assertJsonResponseEquals(rootResource,
- "{\"sling:resourceType\":\"replication/agents\",\"items\":[\"publish-reverse\",\"publish\"]}");
+ assertJsonResponseContains(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)\"}");
+ public void testAgentConfigurationResourceCreate() throws Exception {
+ String agentName = "sample-create-config";
+ String newConfigResource = getAgentConfigUrl(agentName);
+
+ assertPostResourceWithParameters(201, newConfigResource, "name", agentName);
+ assertResourceExists(newConfigResource);
+ assertJsonResponseContains(newConfigResource,
+ "sling:resourceType", "replication/config/agent",
+ "name", agentName);
+ }
+
+ @Test
+ public void testAgentConfigurationResourceDelete() throws Exception {
+ String agentName = "sample-delete-config";
+ String newConfigResource = getAgentConfigUrl(agentName);
+ assertPostResourceWithParameters(201, newConfigResource, "name", agentName);
+ assertResourceExists(newConfigResource);
+ assertPostResourceWithParameters(200, newConfigResource, ":operation", "delete");
+ assertResourceDoesNotExist(newConfigResource);
+ }
+
+
+ @Test
+ public void testAgentConfigurationResourceUpdate() throws Exception {
+ String agentName = "sample-update-config";
+ String newConfigResource = getAgentConfigUrl(agentName);
+ assertPostResourceWithParameters(201, newConfigResource, "name", agentName);
+ assertResourceExists(newConfigResource);
+ assertJsonResponseContains(newConfigResource,
+ "sling:resourceType", "replication/config/agent",
+ "name", agentName);
}
}
\ 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=1583591&r1=1583590&r2=1583591&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 Tue Apr 1 10:08:24 2014
@@ -1,10 +1,17 @@
package org.apache.sling.replication.it;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.message.BasicNameValuePair;
import org.apache.sling.testing.tools.http.Request;
import org.apache.sling.testing.tools.sling.SlingTestBase;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* Integration test base class for replication
@@ -12,6 +19,7 @@ import static org.junit.Assert.assertEqu
public abstract class ReplicationITBase extends SlingTestBase {
private static final String JSON_SELECTOR = ".json";
+ private static final String REPLICATION_ROOT_PATH = "/libs/sling/replication";
protected void assertGetResource(int status, String path, String... parameters) throws IOException {
getRequestExecutor().execute(
@@ -20,7 +28,25 @@ public abstract class ReplicationITBase
).assertStatus(status);
}
- protected void assertPostResource(int status, String path, String... headers) throws IOException {
+ protected void assertPostResourceWithParameters(int status, String path, String... parameters) throws IOException {
+ Request request = getRequestBuilder().buildPostRequest(path);
+
+ if (parameters != null) {
+ assertEquals(0, parameters.length % 2);
+ List<NameValuePair> valuePairList = new ArrayList<NameValuePair>();
+
+ for (int i = 0; i < parameters.length; i += 2) {
+ valuePairList.add(new BasicNameValuePair(parameters[i], parameters[i + 1]));
+ }
+ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(valuePairList);
+ request.withEntity(entity);
+ }
+ getRequestExecutor().execute(
+ request.withCredentials(getServerUsername(), getServerPassword())
+ ).assertStatus(status);
+ }
+
+ protected void assertPostResourceWithHeaders(int status, String path, String... headers) throws IOException {
Request request = getRequestBuilder().buildPostRequest(path);
if (headers != null) {
assertEquals(0, headers.length % 2);
@@ -34,10 +60,17 @@ public abstract class ReplicationITBase
}
protected void assertResourceExists(String path) throws IOException {
+ if (!path.endsWith(JSON_SELECTOR)) {
+ path += JSON_SELECTOR;
+ }
+
assertGetResource(200, path);
}
protected void assertResourceDoesNotExist(String path) throws IOException {
+ if (!path.endsWith(JSON_SELECTOR)) {
+ path += JSON_SELECTOR;
+ }
assertGetResource(404, path);
}
@@ -52,5 +85,44 @@ public abstract class ReplicationITBase
}
+ protected void assertJsonResponseContains(String resource, String... parameters) throws IOException {
+ if (!resource.endsWith(JSON_SELECTOR)) {
+ resource += JSON_SELECTOR;
+ }
+ String content = getRequestExecutor().execute(
+ getRequestBuilder().buildGetRequest(resource)
+ .withCredentials(getServerUsername(), getServerPassword())
+ ).getContent().replaceAll("\n", "").trim();
+
+ assertEquals(0, parameters.length % 2);
+
+ for (int i = 0; i < parameters.length; i += 2) {
+ assertTrue(parameters[i] + ":" + parameters[i + 1] + " is not contained in " + content,
+ content.contains("\"" + parameters[i] + "\":\"" + parameters[i + 1] + "\"") ||
+ content.contains("\"" + parameters[i] + "\":" + parameters[i + 1])
+ );
+ }
+ }
+
+
+ protected String getAgentRootUrl() {
+ return REPLICATION_ROOT_PATH + "/agent";
+ }
+ protected String getAgentUrl(String agentName) {
+ return REPLICATION_ROOT_PATH + "/agent/" + agentName;
+ }
+
+ protected String getAgentConfigUrl(String agentName) {
+ return REPLICATION_ROOT_PATH + "/config/agent/" + agentName;
+ }
+
+
+ protected String getImporterRootUrl() {
+ return REPLICATION_ROOT_PATH + "/importer";
+ }
+
+ protected String getImporterUrl(String importerName) {
+ return REPLICATION_ROOT_PATH + "/importer/" + importerName;
+ }
}
Modified: sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java?rev=1583591&r1=1583590&r2=1583591&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java (original)
+++ sling/trunk/contrib/extensions/replication/it/src/test/java/org/apache/sling/replication/it/ReplicationPackageImporterResourcesIntegrationTest.java Tue Apr 1 10:08:24 2014
@@ -27,16 +27,19 @@ public class ReplicationPackageImporterR
@Test
public void testImporterRootResource() throws Exception {
- assertResourceExists("/libs/sling/replication/importer.json");
- assertJsonResponseEquals("/libs/sling/replication/importer.json",
- "{\"sling:resourceType\":\"replication/importers\",\"items\":[\"default\"]}");
+ String rootResource = getImporterRootUrl();
+ assertResourceExists(rootResource);
+ assertJsonResponseContains(rootResource,
+ "sling:resourceType", "replication/importers",
+ "items", "[\"default\"]");
}
@Test
public void testDefaultImporterResource() throws Exception {
- String rootResource = "/libs/sling/replication/importer/default.json";
+ String rootResource = getImporterUrl("default");
assertResourceExists(rootResource);
- assertJsonResponseEquals(rootResource,
- "{\"sling:resourceType\":\"replication/importer\",\"name\":\"default\"}");
+ assertJsonResponseContains(rootResource,
+ "sling:resourceType", "replication/importer",
+ "name", "default");
}
}