stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [2/8] stratos git commit: adding integration tests for CRUD operation of autoscaling policy, deployment policy, network partition and cartridges
Date Tue, 04 Aug 2015 08:40:34 GMT
adding integration tests for CRUD operation of autoscaling policy, deployment policy, network partition and cartridges

Conflicts:
	products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/SampleApplicationsTest.java


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/56601e6e
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/56601e6e
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/56601e6e

Branch: refs/heads/tenant-isolation
Commit: 56601e6e792735b79bca2e8336fc433a500ee7f0
Parents: e6eb0ec
Author: reka <rthirunavukkarasu23@gmail.com>
Authored: Wed Jul 29 16:10:36 2015 +0530
Committer: Gayan Gunarathne <gayang@wso2.com>
Committed: Mon Aug 3 14:57:55 2015 +0530

----------------------------------------------------------------------
 products/stratos/modules/integration/pom.xml    |  10 +
 .../tests/ApplicationPolicyTest.java            | 142 ++++++++
 .../tests/AutoscalingPolicyTest.java            | 141 ++++++++
 .../integration/tests/CartridgeTest.java        | 142 ++++++++
 .../integration/tests/DeploymentPolicyTest.java | 142 ++++++++
 .../integration/tests/NetworkPartitionTest.java | 144 ++++++++
 .../integration/tests/RestConstants.java        |  33 ++
 .../tests/SampleApplicationsTest.java           | 352 +++++++++++++++++--
 .../tests/StratosArtifactsUtils.java            |  53 +++
 .../integration/tests/rest/ErrorResponse.java   |  56 +++
 .../integration/tests/rest/HttpResponse.java    |  59 ++++
 .../tests/rest/HttpResponseHandler.java         |  68 ++++
 .../integration/tests/rest/RestClient.java      | 133 +++++++
 .../tests/rest/WebClientWrapper.java            |  62 ++++
 .../application-policy-1.json                   |  17 +
 .../single-cartridge-app-multi-cloud/README.md  |  30 ++
 .../artifacts/application.json                  |  25 ++
 .../simple/single-cartridge-app/README.md       |  25 ++
 .../artifacts/application-signup.json           |  18 +
 .../artifacts/application.json                  |  25 ++
 .../artifacts/domain-mappings.json              |   9 +
 .../simple/single-group-app/README.md           |  28 ++
 .../single-group-app/artifacts/application.json |  69 ++++
 .../autoscaling-policy-c0.json                  |  14 +
 .../update/autoscaling-policy-c0.json           |  14 +
 .../test/resources/cartridge-groups/group1.json |  38 ++
 .../cartridges-groups/cartrdige-nested.json     |  36 ++
 .../src/test/resources/cartridges/mock/c0.json  | 124 +++++++
 .../resources/cartridges/mock/update/c0.json    | 124 +++++++
 .../deployment-policy-1.json                    |  32 ++
 .../update/deployment-policy-1.json             |  36 ++
 .../ec2/network-partition-1.json                |  19 +
 .../ec2/network-partition-2.json                |  19 +
 .../gce/network-partition-1.json                |  15 +
 .../kubernetes/network-partition-1.json         |  15 +
 .../kubernetes/network-partition-2.json         |  15 +
 .../kubernetes/network-partition-3.json         |  15 +
 .../mock/network-partition-1.json               |  15 +
 .../mock/network-partition-2.json               |  24 ++
 .../mock/network-partition-3.json               |  15 +
 .../mock/network-partition-4.json               |  15 +
 .../mock/update/network-partition-1.json        |  28 ++
 .../multi/ap-southeast-1-nw-partition.json      |  19 +
 .../multi/ap-southeast-2-nw-partition.json      |  25 ++
 .../multi/openstack-nw-partition.json           |  21 ++
 .../openstack/network-partition-1.json          |  15 +
 .../openstack/network-partition-2.json          |  15 +
 47 files changed, 2454 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/pom.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/pom.xml b/products/stratos/modules/integration/pom.xml
index da97156..edca877 100755
--- a/products/stratos/modules/integration/pom.xml
+++ b/products/stratos/modules/integration/pom.xml
@@ -83,6 +83,16 @@
             <version>5.10.0</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.httpcomponents.wso2</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.3.0.wso2v1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents.wso2</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.2.5.wso2v1</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.stratos</groupId>
             <artifactId>org.apache.stratos.messaging</artifactId>
             <version>4.1.0-SNAPSHOT</version>

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java
new file mode 100644
index 0000000..c4c0261
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.stratos.integration.tests;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
+import org.apache.stratos.integration.tests.rest.ErrorResponse;
+import org.apache.stratos.integration.tests.rest.HttpResponse;
+import org.apache.stratos.integration.tests.rest.RestClient;
+
+import java.net.URI;
+
+/**
+ * Test to handle Network partition CRUD operations
+ */
+public class ApplicationPolicyTest extends StratosArtifactsUtils {
+    private static final Log log = LogFactory.getLog(StratosTestServerManager.class);
+    String applicationPolicies = "/application-policies/";
+    String applicationPoliciesUpdate = "/application-policies/update/";
+
+
+    public boolean addApplicationPolicy(String networkPartitionId, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(applicationPolicies + networkPartitionId);
+            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATION_POLICIES).build();
+
+            HttpResponse response = restClient.doPost(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public ApplicationPolicyBean getApplicationPolicy(String networkPartitionId, String endpoint,
+                                                    RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATION_POLICIES + "/" +
+                    networkPartitionId).build();
+            HttpResponse response = restClient.doGet(uri);
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return gson.fromJson(response.getContent(), ApplicationPolicyBean.class);
+                } else if (response.getStatusCode() == 404) {
+                    return null;
+                } else {
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean updateApplicationPolicy(String networkPartitionId, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(applicationPoliciesUpdate + networkPartitionId);
+            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATION_POLICIES).build();
+            HttpResponse response = restClient.doPut(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean removeApplicationPolicy(String networkPartitionId, String endpoint, RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.APPLICATION_POLICIES + "/" +
+                    networkPartitionId).build();
+            HttpResponse response = restClient.doDelete(uri);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java
new file mode 100644
index 0000000..fe4fa55
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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.stratos.integration.tests;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.stratos.common.beans.policy.autoscale.AutoscalePolicyBean;
+import org.apache.stratos.integration.tests.rest.ErrorResponse;
+import org.apache.stratos.integration.tests.rest.HttpResponse;
+import org.apache.stratos.integration.tests.rest.RestClient;
+
+import java.net.URI;
+
+/**
+ * Test to handle autoscaling policy CRUD operations
+ */
+public class AutoscalingPolicyTest extends StratosArtifactsUtils {
+    private static final Log log = LogFactory.getLog(StratosTestServerManager.class);
+    String autoscalingPolicy = "/autoscaling-policies/";
+    String autoscalingPolicyUpdate = "/autoscaling-policies/update/";
+
+
+    public boolean addAutoscalingPolicy(String autoscalingPolicyName, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(autoscalingPolicy + autoscalingPolicyName);
+            URI uri = new URIBuilder(endpoint + RestConstants.AUTOSCALING_POLICIES).build();
+
+            HttpResponse response = restClient.doPost(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public AutoscalePolicyBean getAutoscalingPolicy(String autoscalingPolicyName, String endpoint,
+                                                    RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.AUTOSCALING_POLICIES + "/" +
+                    autoscalingPolicyName).build();
+            HttpResponse response = restClient.doGet(uri);
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return gson.fromJson(response.getContent(), AutoscalePolicyBean.class);
+                } else if (response.getStatusCode() == 404) {
+                    return null;
+                } else {
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean updateAutoscalingPolicy(String autoscalingPolicyName, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(autoscalingPolicyUpdate + autoscalingPolicyName);
+            URI uri = new URIBuilder(endpoint + RestConstants.AUTOSCALING_POLICIES).build();
+            HttpResponse response = restClient.doPut(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean removeAutoscalingPolicy(String autoscalingPolicyName, String endpoint, RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.AUTOSCALING_POLICIES + "/" +
+                    autoscalingPolicyName).build();
+            HttpResponse response = restClient.doDelete(uri);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java
new file mode 100644
index 0000000..9e9e07f
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.stratos.integration.tests;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.stratos.common.beans.cartridge.CartridgeBean;
+import org.apache.stratos.integration.tests.rest.ErrorResponse;
+import org.apache.stratos.integration.tests.rest.HttpResponse;
+import org.apache.stratos.integration.tests.rest.RestClient;
+
+import java.net.URI;
+
+/**
+ * Test to handle Network partition CRUD operations
+ */
+public class CartridgeTest extends StratosArtifactsUtils {
+    private static final Log log = LogFactory.getLog(StratosTestServerManager.class);
+    String cartridges = "/cartridges/mock/";
+    String cartridgesUpdate = "/cartridges/mock/update/";
+
+
+    public boolean addCartridge(String cartridgeType, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(cartridges + cartridgeType);
+            URI uri = new URIBuilder(endpoint + RestConstants.CARTRIDGES).build();
+
+            HttpResponse response = restClient.doPost(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public CartridgeBean getCartridge(String cartridgeType, String endpoint,
+                                                    RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.CARTRIDGES + "/" +
+                    cartridgeType).build();
+            HttpResponse response = restClient.doGet(uri);
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return gson.fromJson(response.getContent(), CartridgeBean.class);
+                } else if (response.getStatusCode() == 404) {
+                    return null;
+                } else {
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean updateCartridge(String cartridgeType, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(cartridgesUpdate + cartridgeType);
+            URI uri = new URIBuilder(endpoint + RestConstants.CARTRIDGES).build();
+            HttpResponse response = restClient.doPut(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean removeCartridge(String cartridgeType, String endpoint, RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.CARTRIDGES + "/" +
+                    cartridgeType).build();
+            HttpResponse response = restClient.doDelete(uri);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java
new file mode 100644
index 0000000..b437c5e
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.stratos.integration.tests;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean;
+import org.apache.stratos.integration.tests.rest.ErrorResponse;
+import org.apache.stratos.integration.tests.rest.HttpResponse;
+import org.apache.stratos.integration.tests.rest.RestClient;
+
+import java.net.URI;
+
+/**
+ * Test to handle Network partition CRUD operations
+ */
+public class DeploymentPolicyTest extends StratosArtifactsUtils {
+    private static final Log log = LogFactory.getLog(StratosTestServerManager.class);
+    String deploymentPolicies = "/deployment-policies/";
+    String deploymentPoliciesUpdate = "/deployment-policies/update/";
+
+
+    public boolean addDeploymentPolicy(String deploymentPolicyId, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(deploymentPolicies + deploymentPolicyId);
+            URI uri = new URIBuilder(endpoint + RestConstants.DEPLOYMENT_POLICIES).build();
+
+            HttpResponse response = restClient.doPost(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public DeploymentPolicyBean getDeploymentPolicy(String deploymentPolicyId, String endpoint,
+                                                    RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.DEPLOYMENT_POLICIES + "/" +
+                    deploymentPolicyId).build();
+            HttpResponse response = restClient.doGet(uri);
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return gson.fromJson(response.getContent(), DeploymentPolicyBean.class);
+                } else if (response.getStatusCode() == 404) {
+                    return null;
+                } else {
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean updateDeploymentPolicy(String deploymentPolicyId, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(deploymentPoliciesUpdate + deploymentPolicyId);
+            URI uri = new URIBuilder(endpoint + RestConstants.DEPLOYMENT_POLICIES).build();
+            HttpResponse response = restClient.doPut(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean removeDeploymentPolicy(String deploymentPolicyId, String endpoint, RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.DEPLOYMENT_POLICIES + "/" +
+                    deploymentPolicyId).build();
+            HttpResponse response = restClient.doDelete(uri);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java
new file mode 100644
index 0000000..f0b46cf
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.stratos.integration.tests;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.stratos.common.beans.partition.NetworkPartitionBean;
+import org.apache.stratos.integration.tests.rest.ErrorResponse;
+import org.apache.stratos.integration.tests.rest.HttpResponse;
+import org.apache.stratos.integration.tests.rest.RestClient;
+
+import java.net.URI;
+
+/**
+ * Test to handle Network partition CRUD operations
+ */
+public class NetworkPartitionTest extends StratosArtifactsUtils {
+    private static final Log log = LogFactory.getLog(StratosTestServerManager.class);
+    String networkPartitions = "/network-partitions/mock/";
+    String networkPartitionsUpdate = "/network-partitions/mock/update/";
+
+
+    public boolean addNetworkPartition(String networkPartitionId, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(networkPartitions + networkPartitionId);
+            URI uri = new URIBuilder(endpoint + RestConstants.NETWORK_PARTITIONS).build();
+
+            HttpResponse response = restClient.doPost(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public NetworkPartitionBean getNetworkPartition(String networkPartitionId, String endpoint,
+                                                    RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.NETWORK_PARTITIONS + "/" +
+                    networkPartitionId).build();
+            HttpResponse response = restClient.doGet(uri);
+            GsonBuilder gsonBuilder = new GsonBuilder();
+            Gson gson = gsonBuilder.create();
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return gson.fromJson(response.getContent(), NetworkPartitionBean.class);
+                } else if (response.getStatusCode() == 404) {
+                    return null;
+                } else {
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean updateNetworkPartition(String networkPartitionId, String endpoint, RestClient restClient) {
+        try {
+            String content = getJsonStringFromFile(networkPartitionsUpdate + networkPartitionId);
+            URI uri = new URIBuilder(endpoint + RestConstants.NETWORK_PARTITIONS).build();
+            HttpResponse response = restClient.doPut(uri, content);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public boolean removeNetworkPartition(String networkPartitionId, String endpoint, RestClient restClient) {
+        try {
+            URI uri = new URIBuilder(endpoint + RestConstants.NETWORK_PARTITIONS + "/" +
+                    networkPartitionId).build();
+            HttpResponse response = restClient.doDelete(uri);
+            if (response != null) {
+                if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+                    return true;
+                } else if(response.getContent().contains("it is used")) {
+                    return false;
+                } else {
+                    GsonBuilder gsonBuilder = new GsonBuilder();
+                    Gson gson = gsonBuilder.create();
+                    ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
+                    if (errorResponse != null) {
+                        throw new RuntimeException(errorResponse.getErrorMessage());
+                    }
+                }
+            }
+            throw new RuntimeException("An unknown error occurred");
+        } catch (Exception e) {
+            String message = "Could not start mock instance";
+            throw new RuntimeException(message, e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java
new file mode 100644
index 0000000..577d211
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java
@@ -0,0 +1,33 @@
+/*
+ * 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.stratos.integration.tests;
+
+/**
+ * Constant class to keep track of rest endpoint context
+ */
+public class RestConstants {
+    public static final String API = "api";
+    public static final String AUTOSCALING_POLICIES = "/" + API + "/autoscalingPolicies";
+    public static final String DEPLOYMENT_POLICIES = "/" + API + "/deploymentPolicies";
+    public static final String NETWORK_PARTITIONS = "/" + API + "/networkPartitions";
+    public static final String CARTRIDGES = "/" + API + "/cartridges";
+    public static final String APPLICATION_POLICIES = "/" + API + "/applicationPolicies";
+    public static final String APPLICATIONS = "/" + API + "/applications";
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/SampleApplicationsTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/SampleApplicationsTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/SampleApplicationsTest.java
index 50a8347..bf0ea85 100644
--- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/SampleApplicationsTest.java
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/SampleApplicationsTest.java
@@ -25,7 +25,13 @@ import org.apache.commons.exec.PumpStreamHandler;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.beans.PropertyBean;
+import org.apache.stratos.common.beans.cartridge.CartridgeBean;
+import org.apache.stratos.common.beans.partition.NetworkPartitionBean;
+import org.apache.stratos.common.beans.policy.autoscale.AutoscalePolicyBean;
+import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean;
 import org.apache.stratos.common.threading.StratosThreadPool;
+import org.apache.stratos.integration.tests.rest.RestClient;
 import org.apache.stratos.messaging.domain.application.Application;
 import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.message.receiver.application.ApplicationManager;
@@ -38,6 +44,7 @@ import java.io.File;
 import java.util.concurrent.ExecutorService;
 
 import static junit.framework.Assert.*;
+import static junit.framework.Assert.assertEquals;
 
 /**
  * Sample application tests.
@@ -48,48 +55,313 @@ public class SampleApplicationsTest extends StratosTestServerManager {
 
     public static final int APPLICATION_ACTIVATION_TIMEOUT = 600000;
     private ApplicationsEventReceiver applicationsEventReceiver;
+    private RestClient restClient = new RestClient();
+    private String endpoint = "https://localhost:9443";
+    private AutoscalingPolicyTest autoscalingPolicyTest;
+    private NetworkPartitionTest networkPartitionTest;
+    private CartridgeTest cartridgeTest;
+    private DeploymentPolicyTest deploymentPolicyTest;
 
     @BeforeClass
-    public void setUp(){
+    public void setUp() {
         // Set jndi.properties.dir system property for initializing event receivers
         System.setProperty("jndi.properties.dir", getResourcesFolderPath());
+        autoscalingPolicyTest = new AutoscalingPolicyTest();
+        networkPartitionTest = new NetworkPartitionTest();
+        cartridgeTest = new CartridgeTest();
+        deploymentPolicyTest = new DeploymentPolicyTest();
     }
 
     @Test
-    public void testApplications() {
+    public void testSingleCartridgeApplication() {
         try {
             initializeApplicationEventReceiver();
-            runApplicationTest("simple/single-group-app", "cartridge-group-app");
+            //runApplicationTest("simple/single-cartridge-app", "single-cartridge-app");
         } catch (Exception e) {
             log.error(e);
             assertTrue("An error occurred", false);
         }
     }
 
+    /*@Test
+    public void testAutoscalingPolicy() {
+        try {
+            initializeApplicationEventReceiver();
+            boolean added = autoscalingPolicyTest.addAutoscalingPolicy("autoscaling-policy-c0.json",
+                    endpoint, restClient);
+            assertEquals(added, true);
+            AutoscalePolicyBean bean = autoscalingPolicyTest.getAutoscalingPolicy("autoscaling-policy-c0", endpoint,
+                    restClient);
+            assertEquals(bean.getLoadThresholds().getRequestsInFlight().getThreshold(), 35.0, 0.0);
+            assertEquals(bean.getLoadThresholds().getMemoryConsumption().getThreshold(), 45.0, 0.0);
+            assertEquals(bean.getLoadThresholds().getLoadAverage().getThreshold(), 25.0, 0.0);
+
+            boolean updated = autoscalingPolicyTest.updateAutoscalingPolicy("autoscaling-policy-c0.json",
+                    endpoint, restClient);
+            assertEquals(updated, true);
+            AutoscalePolicyBean updatedBean = autoscalingPolicyTest.getAutoscalingPolicy("autoscaling-policy-c0", endpoint,
+                    restClient);
+            assertEquals(updatedBean.getLoadThresholds().getRequestsInFlight().getThreshold(), 30.0, 0.0);
+            assertEquals(updatedBean.getLoadThresholds().getMemoryConsumption().getThreshold(), 40.0, 0.0);
+            assertEquals(updatedBean.getLoadThresholds().getLoadAverage().getThreshold(), 20.0, 0.0);
+
+            boolean removed = autoscalingPolicyTest.removeAutoscalingPolicy("autoscaling-policy-c0", endpoint,
+                    restClient);
+            assertEquals(removed, true);
+
+            AutoscalePolicyBean beanRemoved = autoscalingPolicyTest.getAutoscalingPolicy("autoscaling-policy-c0", endpoint,
+                    restClient);
+            assertEquals(beanRemoved, null);
+
+        } catch (Exception e) {
+            log.error(e);
+            assertTrue("An error occurred while handling autoscaling policy", false);
+        }
+    }
+
+    @Test
+    public void testNetworkPartition() {
+        try {
+            initializeApplicationEventReceiver();
+            boolean added = networkPartitionTest.addNetworkPartition("network-partition-1.json",
+                    endpoint, restClient);
+            assertEquals(added, true);
+            NetworkPartitionBean bean = networkPartitionTest.getNetworkPartition("network-partition-1", endpoint,
+                    restClient);
+            assertEquals(bean.getId(), "network-partition-1");
+            assertEquals(bean.getPartitions().size(), 1);
+            assertEquals(bean.getPartitions().get(0).getId(), "partition-1");
+            assertEquals(bean.getPartitions().get(0).getProperty().get(0).getName(), "region");
+            assertEquals(bean.getPartitions().get(0).getProperty().get(0).getValue(), "default");
+
+            boolean updated = networkPartitionTest.updateNetworkPartition("network-partition-1.json",
+                    endpoint, restClient);
+            assertEquals(updated, true);
+            NetworkPartitionBean updatedBean = networkPartitionTest.getNetworkPartition("network-partition-1", endpoint,
+                    restClient);
+            assertEquals(updatedBean.getId(), "network-partition-1");
+            assertEquals(updatedBean.getPartitions().size(), 2);
+            assertEquals(updatedBean.getPartitions().get(1).getId(), "partition-2");
+            assertEquals(updatedBean.getPartitions().get(1).getProperty().get(0).getName(), "region");
+            assertEquals(updatedBean.getPartitions().get(1).getProperty().get(0).getValue(), "default1");
+            assertEquals(updatedBean.getPartitions().get(1).getProperty().get(1).getName(), "zone");
+            assertEquals(updatedBean.getPartitions().get(1).getProperty().get(1).getValue(), "z1");
+
+            boolean removed = networkPartitionTest.removeNetworkPartition("network-partition-1", endpoint,
+                    restClient);
+            assertEquals(removed, true);
+
+            NetworkPartitionBean beanRemoved = networkPartitionTest.getNetworkPartition("network-partition-1", endpoint,
+                    restClient);
+            assertEquals(beanRemoved, null);
+
+        } catch (Exception e) {
+            log.error(e);
+            assertTrue("An error occurred while handling network partitions", false);
+        }
+    }
+
+    @Test
+    public void testDeploymentPolicy() {
+        try {
+            initializeApplicationEventReceiver();
+            boolean addedN1 = networkPartitionTest.addNetworkPartition("network-partition-1.json",
+                    endpoint, restClient);
+            assertEquals(addedN1, true);
+
+            boolean addedN2 = networkPartitionTest.addNetworkPartition("network-partition-2.json",
+                    endpoint, restClient);
+            assertEquals(addedN2, true);
+
+            boolean addedDep = deploymentPolicyTest.addDeploymentPolicy("deployment-policy-1.json",
+                    endpoint, restClient);
+            assertEquals(addedDep, true);
+
+            DeploymentPolicyBean bean = deploymentPolicyTest.getDeploymentPolicy(
+                    "deployment-policy-1", endpoint, restClient);
+            assertEquals(bean.getId(), "deployment-policy-1");
+            assertEquals(bean.getNetworkPartitions().size(), 2);
+            assertEquals(bean.getNetworkPartitions().get(0).getId(), "network-partition-1");
+            assertEquals(bean.getNetworkPartitions().get(0).getPartitionAlgo(), "one-after-another");
+            assertEquals(bean.getNetworkPartitions().get(0).getPartitions().size(), 1);
+            assertEquals(bean.getNetworkPartitions().get(0).getPartitions().get(0).getId(), "partition-1");
+            assertEquals(bean.getNetworkPartitions().get(0).getPartitions().get(0).getPartitionMax(), 20);
+
+            assertEquals(bean.getNetworkPartitions().get(1).getId(), "network-partition-2");
+            assertEquals(bean.getNetworkPartitions().get(1).getPartitionAlgo(), "round-robin");
+            assertEquals(bean.getNetworkPartitions().get(1).getPartitions().size(), 2);
+            assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(0).getId(),
+                    "network-partition-2-partition-1");
+            assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(0).getPartitionMax(), 10);
+            assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(1).getId(),
+                    "network-partition-2-partition-2");
+            assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(1).getPartitionMax(), 9);
+
+            //update network partition
+            boolean updated = networkPartitionTest.updateNetworkPartition("network-partition-1.json",
+                    endpoint, restClient);
+            assertEquals(updated, true);
+
+            //update deployment policy with new partition and max values
+            boolean updatedDep = deploymentPolicyTest.updateDeploymentPolicy("deployment-policy-1.json",
+                    endpoint, restClient);
+            assertEquals(updatedDep, true);
+
+            DeploymentPolicyBean updatedBean = deploymentPolicyTest.getDeploymentPolicy(
+                    "deployment-policy-1", endpoint, restClient);
+            assertEquals(updatedBean.getId(), "deployment-policy-1");
+            assertEquals(updatedBean.getNetworkPartitions().size(), 2);
+            assertEquals(updatedBean.getNetworkPartitions().get(0).getId(), "network-partition-1");
+            assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitionAlgo(), "one-after-another");
+            assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().size(), 2);
+            assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(0).getId(), "partition-1");
+            assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(0).getPartitionMax(), 25);
+            assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(1).getId(), "partition-2");
+            assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(1).getPartitionMax(), 20);
+
+            assertEquals(updatedBean.getNetworkPartitions().get(1).getId(), "network-partition-2");
+            assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitionAlgo(), "round-robin");
+            assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().size(), 2);
+            assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(0).getId(),
+                    "network-partition-2-partition-1");
+            assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(0).getPartitionMax(), 15);
+            assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(1).getId(),
+                    "network-partition-2-partition-2");
+            assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(1).getPartitionMax(), 5);
+
+            boolean removedNet = networkPartitionTest.removeNetworkPartition("network-partition-1", endpoint,
+                    restClient);
+            //Trying to remove the used network partition
+            assertEquals(removedNet, false);
+
+            boolean removedDep = deploymentPolicyTest.removeDeploymentPolicy("deployment-policy-1", endpoint,
+                    restClient);
+            assertEquals(removedDep, true);
+
+            DeploymentPolicyBean beanRemovedDep = deploymentPolicyTest.getDeploymentPolicy("network-partition-1", endpoint,
+                    restClient);
+            assertEquals(beanRemovedDep, null);
+
+            boolean removedN1 = networkPartitionTest.removeNetworkPartition("network-partition-1", endpoint,
+                    restClient);
+            assertEquals(removedN1, true);
+
+            NetworkPartitionBean beanRemovedN1 = networkPartitionTest.getNetworkPartition("network-partition-1", endpoint,
+                    restClient);
+            assertEquals(beanRemovedN1, null);
+
+            boolean removedN2 = networkPartitionTest.removeNetworkPartition("network-partition-2", endpoint,
+                    restClient);
+            assertEquals(removedN2, true);
+
+            NetworkPartitionBean beanRemovedN2 = networkPartitionTest.getNetworkPartition("network-partition-2", endpoint,
+                    restClient);
+            assertEquals(beanRemovedN2, null);
+
+        } catch (Exception e) {
+            log.error(e);
+            assertTrue("An error occurred while handling autoscaling policy", false);
+        }
+    }
+
+    @Test
+    public void testCartridge() {
+        try {
+            initializeApplicationEventReceiver();
+            boolean added = cartridgeTest.addCartridge("c0.json", endpoint, restClient);
+            assertEquals(added, true);
+            CartridgeBean bean = cartridgeTest.getCartridge("c0", endpoint, restClient);
+            assertEquals(bean.getType(), "c0");
+            assertEquals(bean.getCategory(), "Application");
+            assertEquals(bean.getHost(), "qmog.cisco.com");
+            for(PropertyBean property : bean.getProperty()) {
+                if(property.getName().equals("payload_parameter.CEP_IP")) {
+                    assertEquals(property.getValue(), "octl.qmog.cisco.com");
+                } else if(property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) {
+                    assertEquals(property.getValue(), "admin");
+                } else if(property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) {
+                    assertEquals(property.getValue(), "octl.qmog.cisco.com");
+                } else if(property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) {
+                    assertEquals(property.getValue(), "1");
+                } else if(property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) {
+                    assertEquals(property.getValue(), "admin");
+                } else if(property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) {
+                    assertEquals(property.getValue(), "test");
+                } else if(property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) {
+                    assertEquals(property.getValue(), "7711");
+                } else if(property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) {
+                    assertEquals(property.getValue(), "7611");
+                } else if(property.getName().equals("payload_parameter.CEP_PORT")) {
+                    assertEquals(property.getValue(), "7611");
+                } else if(property.getName().equals("payload_parameter.MB_PORT")) {
+                    assertEquals(property.getValue(), "61616");
+                }
+            }
+
+
+            boolean updated = cartridgeTest.updateCartridge("c0.json",
+                    endpoint, restClient);
+            assertEquals(updated, true);
+            CartridgeBean updatedBean = cartridgeTest.getCartridge("c0", endpoint,
+                    restClient);
+            assertEquals(updatedBean.getType(), "c0");
+            assertEquals(updatedBean.getCategory(), "Data");
+            assertEquals(updatedBean.getHost(), "qmog.cisco.com12");
+            for(PropertyBean property : updatedBean.getProperty()) {
+                if(property.getName().equals("payload_parameter.CEP_IP")) {
+                    assertEquals(property.getValue(), "octl.qmog.cisco.com123");
+                } else if(property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) {
+                    assertEquals(property.getValue(), "admin123");
+                } else if(property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) {
+                    assertEquals(property.getValue(), "octl.qmog.cisco.com123");
+                } else if(property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) {
+                    assertEquals(property.getValue(), "3");
+                } else if(property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) {
+                    assertEquals(property.getValue(), "admin123");
+                } else if(property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) {
+                    assertEquals(property.getValue(), "test123");
+                } else if(property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) {
+                    assertEquals(property.getValue(), "7712");
+                } else if(property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) {
+                    assertEquals(property.getValue(), "7612");
+                } else if(property.getName().equals("payload_parameter.CEP_PORT")) {
+                    assertEquals(property.getValue(), "7612");
+                } else if(property.getName().equals("payload_parameter.MB_PORT")) {
+                    assertEquals(property.getValue(), "61617");
+                }
+            }
+
+            boolean removed = cartridgeTest.removeCartridge("c0", endpoint,
+                    restClient);
+            assertEquals(removed, true);
+
+            CartridgeBean beanRemoved = cartridgeTest.getCartridge("c0", endpoint,
+                    restClient);
+            assertEquals(beanRemoved, null);
+
+        } catch (Exception e) {
+            log.error(e);
+            assertTrue("An error occurred while handling cartridges", false);
+        }
+    }*/
+
+
     private void runApplicationTest(String applicationId) {
         runApplicationTest(applicationId, applicationId);
     }
 
     private void runApplicationTest(String applicationFolderName, String applicationId) {
-        executeCommand(getApplicationsPath() + "/" + applicationFolderName + "/scripts/mock/deploy.sh 1");
-        assertApplicationActivation(applicationId, 1);
-        executeCommand(getApplicationsPath() + "/" + applicationFolderName + "/scripts/mock/deploy.sh 2");
-        assertApplicationActivation(applicationId, 2);
-
-        executeCommand(getApplicationsPath() + "/" + applicationFolderName + "/scripts/mock/undeploy.sh 1");
-        assertApplicationNotExists(applicationId, 1);
-        log.info("Done tenant 1: " + applicationId);
-        executeCommand(getApplicationsPath() + "/" + applicationFolderName + "/scripts/mock/undeploy.sh 2");
-        log.info("Assert tenant 2: " + applicationId);
-        assertApplicationNotExists(applicationId, 2);
-        log.info("Done tenant 2: " + applicationId);
+        executeCommand(getApplicationsPath() + "/" + applicationFolderName + "/scripts/mock/deploy.sh");
+        assertApplicationActivation(applicationId);
+        executeCommand(getApplicationsPath() + "/" + applicationFolderName + "/scripts/mock/undeploy.sh");
+        assertApplicationNotExists(applicationId);
     }
 
     /**
      * Initialize application event receiver
      */
     private void initializeApplicationEventReceiver() {
-        if(applicationsEventReceiver == null) {
+        if (applicationsEventReceiver == null) {
             applicationsEventReceiver = new ApplicationsEventReceiver();
             ExecutorService executorService = StratosThreadPool.getExecutorService("STRATOS_TEST_SERVER", 1);
             applicationsEventReceiver.setExecutorService(executorService);
@@ -99,6 +371,7 @@ public class SampleApplicationsTest extends StratosTestServerManager {
 
     /**
      * Execute shell command
+     *
      * @param commandText
      */
     private void executeCommand(String commandText) {
@@ -118,36 +391,36 @@ public class SampleApplicationsTest extends StratosTestServerManager {
 
     /**
      * Assert application activation
+     *
      * @param applicationName
      */
-    private void assertApplicationActivation(String applicationName, int tenantId) {
-	    long startTime = System.currentTimeMillis();
-	    Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName,
-                tenantId);
-	    while (!((application != null) && (application.getStatus() == ApplicationStatus.Active))) {
-		    try {
-			    Thread.sleep(1000);
-		    } catch (InterruptedException ignore) {
-		    }
-		    application = ApplicationManager.getApplications().getApplicationByTenant(applicationName, tenantId);
-		    if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
-			    break;
-		    }
-	    }
-	    assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
-	    assertEquals(String.format("Application status did not change to active: [application-id] %s", applicationName),
-	                 ApplicationStatus.Active, application.getStatus());
+    private void assertApplicationActivation(String applicationName) {
+        long startTime = System.currentTimeMillis();
+        Application application = ApplicationManager.getApplications().getApplication(applicationName);
+        while (!((application != null) && (application.getStatus() == ApplicationStatus.Active))) {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException ignore) {
+            }
+            application = ApplicationManager.getApplications().getApplication(applicationName);
+            if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
+                break;
+            }
+        }
+
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
+        assertEquals(String.format("Application status did not change to active: [application-id] %s", applicationName),
+                ApplicationStatus.Active, application.getStatus());
     }
 
-    private void assertApplicationNotExists(String applicationName, int tenantId) {
-        Application application = ApplicationManager.getApplications().getApplicationByTenant(applicationName,
-                tenantId);
-        log.info("Application not exist [application-name]: " + applicationName + " [tenant-id]: " + tenantId);
+    private void assertApplicationNotExists(String applicationName) {
+        Application application = ApplicationManager.getApplications().getApplication(applicationName);
         assertNull(String.format("Application is found in the topology : [application-id] %s", applicationName), application);
     }
 
     /**
      * Get applications folder path
+     *
      * @return
      */
     private String getApplicationsPath() {
@@ -156,10 +429,15 @@ public class SampleApplicationsTest extends StratosTestServerManager {
 
     /**
      * Get resources folder path
+     *
      * @return
      */
     private String getResourcesFolderPath() {
         String path = getClass().getResource("/").getPath();
         return StringUtils.removeEnd(path, File.separator);
     }
+
+    private String getArtifactsPath() {
+        return getResourcesFolderPath() + "/../../src/test/resources";
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosArtifactsUtils.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosArtifactsUtils.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosArtifactsUtils.java
new file mode 100644
index 0000000..9a81972
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosArtifactsUtils.java
@@ -0,0 +1,53 @@
+/*
+ * 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.stratos.integration.tests;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonParser;
+import org.apache.commons.lang.StringUtils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+
+/**
+ * Util class
+ */
+public class StratosArtifactsUtils {
+
+    public String getJsonStringFromFile(String filePath) throws FileNotFoundException {
+        JsonParser parser = new JsonParser();
+        Object object = parser.parse(new FileReader(getResourcesFolderPath() + filePath));
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        Gson gson = gsonBuilder.create();
+        String content = gson.toJson(object);
+        return content;
+
+    }
+
+    /**
+     * Get resources folder path
+     * @return
+     */
+    private String getResourcesFolderPath() {
+        String path = getClass().getResource("/").getPath();
+        return StringUtils.removeEnd(path, File.separator);
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/ErrorResponse.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/ErrorResponse.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/ErrorResponse.java
new file mode 100644
index 0000000..168713e
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/ErrorResponse.java
@@ -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.stratos.integration.tests.rest;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+/**
+ * Error response.
+ */
+@XmlRootElement(name = "errorResponse")
+public class ErrorResponse implements Serializable {
+
+    private int errorCode;
+    private String errorMessage;
+
+    public ErrorResponse() {
+    }
+
+    public ErrorResponse(int errorCode, String errorMessage) {
+        this.setErrorCode(errorCode);
+        this.setErrorMessage(errorMessage);
+    }
+
+    public int getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(int errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/HttpResponse.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/HttpResponse.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/HttpResponse.java
new file mode 100644
index 0000000..8ac5619
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/HttpResponse.java
@@ -0,0 +1,59 @@
+/*
+ * 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.stratos.integration.tests.rest;
+
+/**
+ * Created by reka on 7/28/15.
+ */
+public class HttpResponse {
+
+    private int statusCode;
+    private String content;
+    private String reason;
+
+    public int getStatusCode() {
+        return statusCode;
+    }
+
+    public void setStatusCode(int statusCode) {
+        this.statusCode = statusCode;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public String getReason() {
+        return reason;
+    }
+
+    public void setReason(String reason) {
+        this.reason = reason;
+    }
+
+    @Override
+    public String toString() {
+        return "HttpResponse [statusCode=" + statusCode + ", content=" + content
+                + ", reason=" + reason + "]";
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/HttpResponseHandler.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/HttpResponseHandler.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/HttpResponseHandler.java
new file mode 100644
index 0000000..532fc5e
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/HttpResponseHandler.java
@@ -0,0 +1,68 @@
+/*
+ * 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.stratos.integration.tests.rest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * Rest http response handler
+ */
+public class HttpResponseHandler implements ResponseHandler<HttpResponse> {
+    private static final Log log = LogFactory.getLog(HttpResponseHandler.class);
+
+    @Override
+    public HttpResponse handleResponse(org.apache.http.HttpResponse response) throws ClientProtocolException,
+            IOException {
+        StatusLine statusLine = response.getStatusLine();
+        HttpEntity entity = response.getEntity();
+        if (entity == null) {
+            throw new ClientProtocolException("Response contains no content");
+        }
+
+        BufferedReader reader = new BufferedReader(new InputStreamReader(
+                (response.getEntity().getContent())));
+
+        String output;
+        String result = "";
+
+        while ((output = reader.readLine()) != null) {
+            result += output;
+        }
+
+        HttpResponse httpResponse = new HttpResponse();
+        httpResponse.setStatusCode(statusLine.getStatusCode());
+        httpResponse.setContent(result);
+        httpResponse.setReason(statusLine.getReasonPhrase());
+
+        if (log.isDebugEnabled()) {
+            log.debug("Extracted Http Response: " + httpResponse.toString());
+        }
+
+        return httpResponse;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java
new file mode 100644
index 0000000..fb5ff51
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java
@@ -0,0 +1,133 @@
+/*
+ * 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.stratos.integration.tests.rest;
+
+
+import org.apache.http.client.methods.*;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
+
+import java.net.URI;
+
+/**
+ * Rest client to handle rest requests
+ */
+public class RestClient {
+
+    private DefaultHttpClient httpClient;
+
+    public RestClient() {
+        PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
+        // Increase max total connection to 200
+        cm.setMaxTotal(200);
+        // Increase default max connection per route to 50
+        cm.setDefaultMaxPerRoute(50);
+
+        httpClient = new DefaultHttpClient(cm);
+        httpClient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpClient);
+    }
+
+    /**
+     * Handle http post request. Return String
+     *
+     * @param resourcePath    This should be REST endpoint
+     * @param jsonParamString The json string which should be executed from the post request
+     * @return The HttpResponse
+     * @throws Exception if any errors occur when executing the request
+     */
+    public HttpResponse doPost(URI resourcePath, String jsonParamString) throws Exception {
+        HttpPost postRequest = null;
+        try {
+            postRequest = new HttpPost(resourcePath);
+            StringEntity input = new StringEntity(jsonParamString);
+            input.setContentType("application/json");
+            postRequest.setEntity(input);
+
+            String userPass = "admin" + ":" + "admin";
+            String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+            postRequest.addHeader("Authorization", basicAuth);
+
+            return httpClient.execute(postRequest, new HttpResponseHandler());
+        } finally {
+            releaseConnection(postRequest);
+        }
+    }
+
+    /**
+     * Handle http get request. Return String
+     *
+     * @param resourcePath This should be REST endpoint
+     * @return The HttpResponse
+     * @throws org.apache.http.client.ClientProtocolException and IOException
+     *                                                        if any errors occur when executing the request
+     */
+    public HttpResponse doGet(URI resourcePath) throws Exception {
+        HttpGet getRequest = null;
+        try {
+            getRequest = new HttpGet(resourcePath);
+            getRequest.addHeader("Content-Type", "application/json");
+            String userPass = "admin" + ":" + "admin";
+            String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+            getRequest.addHeader("Authorization", basicAuth);
+
+            return httpClient.execute(getRequest, new HttpResponseHandler());
+        } finally {
+            releaseConnection(getRequest);
+        }
+    }
+
+    public HttpResponse doDelete(URI resourcePath) throws Exception {
+        HttpDelete httpDelete = null;
+        try {
+            httpDelete = new HttpDelete(resourcePath);
+            httpDelete.addHeader("Content-Type", "application/json");
+            String userPass = "admin" + ":" + "admin";
+            String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+            httpDelete.addHeader("Authorization", basicAuth);
+            return httpClient.execute(httpDelete, new HttpResponseHandler());
+        } finally {
+            releaseConnection(httpDelete);
+        }
+    }
+
+    public HttpResponse doPut(URI resourcePath, String jsonParamString) throws Exception {
+
+        HttpPut putRequest = null;
+        try {
+            putRequest = new HttpPut(resourcePath);
+
+            StringEntity input = new StringEntity(jsonParamString);
+            input.setContentType("application/json");
+            putRequest.setEntity(input);
+            String userPass = "admin" + ":" + "admin";
+            String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+            putRequest.addHeader("Authorization", basicAuth);
+            return httpClient.execute(putRequest, new HttpResponseHandler());
+        } finally {
+            releaseConnection(putRequest);
+        }
+    }
+
+    private void releaseConnection(HttpRequestBase request) {
+        if (request != null) {
+            request.releaseConnection();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/WebClientWrapper.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/WebClientWrapper.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/WebClientWrapper.java
new file mode 100644
index 0000000..848f4f2
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/WebClientWrapper.java
@@ -0,0 +1,62 @@
+/*
+ * 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.stratos.integration.tests.rest;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+public class WebClientWrapper {
+    public static HttpClient wrapClient(HttpClient base) {
+        try {
+            SSLContext ctx = SSLContext.getInstance("TLS");
+            X509TrustManager tm = new X509TrustManager() {
+                public void checkClientTrusted(X509Certificate[] xcs,
+                                               String string) throws CertificateException {
+                }
+
+                public void checkServerTrusted(X509Certificate[] xcs,
+                                               String string) throws CertificateException {
+                }
+
+                public X509Certificate[] getAcceptedIssuers() {
+                    return null;
+                }
+            };
+            ctx.init(null, new TrustManager[]{tm}, null);
+            SSLSocketFactory ssf = new SSLSocketFactory(ctx);
+            ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+            ClientConnectionManager ccm = base.getConnectionManager();
+            SchemeRegistry sr = ccm.getSchemeRegistry();
+            sr.register(new Scheme("https", ssf, 443));
+            return new DefaultHttpClient(ccm, base.getParams());
+        } catch (Exception ex) {
+            return null;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/56601e6e/products/stratos/modules/integration/src/test/resources/application-policies/application-policy-1.json
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/src/test/resources/application-policies/application-policy-1.json b/products/stratos/modules/integration/src/test/resources/application-policies/application-policy-1.json
new file mode 100644
index 0000000..417b94f
--- /dev/null
+++ b/products/stratos/modules/integration/src/test/resources/application-policies/application-policy-1.json
@@ -0,0 +1,17 @@
+{
+    "id": "application-policy-1",
+    "algorithm": "one-after-another",
+    "networkPartitions": [
+        "network-partition-1"
+    ],
+    "properties": [
+        {
+            "name": "key-1",
+            "value": "value-1"
+        },
+        {
+            "name": "key-2",
+            "value": "value-2"
+        }
+    ]
+}


Mime
View raw message