http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/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 096dd60..7641b18 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
@@ -19,266 +19,78 @@
 
 package org.apache.stratos.integration.tests;
 
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.DefaultExecutor;
-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.autoscaler.stub.pojo.ApplicationContext;
-import org.apache.stratos.common.beans.PropertyBean;
 import org.apache.stratos.common.beans.application.ApplicationBean;
-import org.apache.stratos.common.beans.cartridge.CartridgeBean;
 import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
-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.ApplicationPolicyBean;
-import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean;
-import org.apache.stratos.common.client.AutoscalerServiceClient;
-import org.apache.stratos.common.threading.StratosThreadPool;
-import org.apache.stratos.integration.tests.rest.RestClient;
-import org.apache.stratos.messaging.domain.application.*;
-import org.apache.stratos.messaging.domain.instance.ClusterInstance;
-import org.apache.stratos.messaging.domain.instance.GroupInstance;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.Member;
-import org.apache.stratos.messaging.domain.topology.MemberStatus;
-import org.apache.stratos.messaging.domain.topology.Service;
-import 
org.apache.stratos.messaging.message.receiver.application.ApplicationManager;
-import 
org.apache.stratos.messaging.message.receiver.application.ApplicationsEventReceiver;
-import 
org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.rmi.RemoteException;
-import java.util.Collection;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-
-import static junit.framework.Assert.*;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
 
 /**
- * Sample application tests.
+ * Sample application tests with application add, .
  */
 public class SampleApplicationsTest extends StratosTestServerManager {
+    private static final Log log = 
LogFactory.getLog(SampleApplicationsTest.class);
 
-    private static final Log log = 
LogFactory.getLog(StratosTestServerManager.class);
-
-    public static final int APPLICATION_ACTIVATION_TIMEOUT = 120000;
-    public static final String APPLICATION_STATUS_CREATED = "Created";
-    public static final String APPLICATION_STATUS_UNDEPLOYING = "Undeploying";
-    private String endpoint = "https://localhost:9443";;
-
-    private ApplicationsEventReceiver applicationsEventReceiver;
-    private TopologyEventReceiver topologyEventReceiver;
-    private RestClient restClient;
-    private AutoscalingPolicyTest autoscalingPolicyTest;
-    private NetworkPartitionTest networkPartitionTest;
-    private CartridgeTest cartridgeTest;
-    private DeploymentPolicyTest deploymentPolicyTest;
-    private CartridgeGroupTest cartridgeGroupTest;
-    private ApplicationTest applicationTest;
-    private ApplicationPolicyTest applicationPolicyTest;
-
-
-    @BeforeClass
-    public void setUp() {
-        // Set jndi.properties.dir system property for initializing event 
receivers
-        System.setProperty("jndi.properties.dir", getResourcesFolderPath());
-        System.setProperty("autoscaler.service.url", 
"https://localhost:9443/services/AutoscalerService";);
-        restClient = new RestClient(endpoint, "admin", "admin");
-        autoscalingPolicyTest = new AutoscalingPolicyTest();
-        networkPartitionTest = new NetworkPartitionTest();
-        cartridgeTest = new CartridgeTest();
-        deploymentPolicyTest = new DeploymentPolicyTest();
-        cartridgeGroupTest = new CartridgeGroupTest();
-        applicationTest = new ApplicationTest();
-        applicationPolicyTest = new ApplicationPolicyTest();
-    }
-
-    @Test
-    public void testSingleCartridgeApplication() {
-        try {
-            initializeApplicationEventReceiver();
-            //runApplicationTest("simple/single-cartridge-app", 
"single-cartridge-app");
-        } catch (Exception e) {
-            log.error(e);
-            assertTrue("An error occurred", false);
-        }
-    }
-
-    @Test
-    public void testAutoscalingPolicy() {
-        log.info("Started autoscaling policy test 
case**************************************");
-        String policyId = "autoscaling-policy-c0";
-        try {
-            boolean added = 
autoscalingPolicyTest.addAutoscalingPolicy(policyId + ".json",
-                    restClient);
-            assertEquals(String.format("Autoscaling policy did not added: 
[autoscaling-policy-id] %s", policyId), added, true);
-            AutoscalePolicyBean bean = 
autoscalingPolicyTest.getAutoscalingPolicy(policyId,
-                    restClient);
-            assertEquals(String.format("[autoscaling-policy-id] %s is not 
correct", bean.getId()),
-                    bean.getId(), policyId);
-            assertEquals(String.format("[autoscaling-policy-id] %s RIF is not 
correct", policyId),
-                    
bean.getLoadThresholds().getRequestsInFlight().getThreshold(), 35.0, 0.0);
-            assertEquals(String.format("[autoscaling-policy-id] %s Memory is 
not correct", policyId),
-                    
bean.getLoadThresholds().getMemoryConsumption().getThreshold(), 45.0, 0.0);
-            assertEquals(String.format("[autoscaling-policy-id] %s Load is not 
correct", policyId),
-                    bean.getLoadThresholds().getLoadAverage().getThreshold(), 
25.0, 0.0);
-
-            boolean updated = 
autoscalingPolicyTest.updateAutoscalingPolicy(policyId + ".json",
-                    restClient);
-            assertEquals(String.format("[autoscaling-policy-id] %s update 
failed", policyId), updated, true);
-            AutoscalePolicyBean updatedBean = 
autoscalingPolicyTest.getAutoscalingPolicy(policyId,
-                    restClient);
-            assertEquals(String.format("[autoscaling-policy-id] %s RIF is not 
correct", policyId),
-                    
updatedBean.getLoadThresholds().getRequestsInFlight().getThreshold(), 30.0, 
0.0);
-            assertEquals(String.format("[autoscaling-policy-id] %s Load is not 
correct", policyId),
-                    
updatedBean.getLoadThresholds().getMemoryConsumption().getThreshold(), 40.0, 
0.0);
-            assertEquals(String.format("[autoscaling-policy-id] %s Memory is 
not correct", policyId),
-                    
updatedBean.getLoadThresholds().getLoadAverage().getThreshold(), 20.0, 0.0);
-
-            boolean removed = 
autoscalingPolicyTest.removeAutoscalingPolicy(policyId,
-                    restClient);
-            assertEquals(String.format("[autoscaling-policy-id] %s couldn't be 
removed", policyId),
-                    removed, true);
-
-            AutoscalePolicyBean beanRemoved = 
autoscalingPolicyTest.getAutoscalingPolicy(policyId,
-                    restClient);
-            assertEquals(String.format("[autoscaling-policy-id] %s didn't get 
removed successfully",
-                    policyId), beanRemoved, null);
-            log.info("Ended autoscaling policy test 
case**************************************");
-        } catch (Exception e) {
-            log.error("An error occurred while handling [autoscaling policy] " 
+ policyId, e);
-            assertTrue("An error occurred while handling [autoscaling policy] 
" + policyId, false);
-        }
-    }
-
-    @Test
-    public void testCartridgeGroup() {
-        try {
-            log.info("Started Cartridge group test 
case**************************************");
-
-            boolean addedC1 = cartridgeTest.addCartridge("c1.json", 
restClient);
-            assertEquals(String.format("Cartridge did not added: 
[cartridge-name] %s", "c1"), addedC1, true);
-
-            boolean addedC2 = cartridgeTest.addCartridge("c2.json", 
restClient);
-            assertEquals(String.format("Cartridge did not added: 
[cartridge-name] %s", "c2"), addedC2, true);
-
-            boolean addedC3 = cartridgeTest.addCartridge("c3.json", 
restClient);
-            assertEquals(String.format("Cartridge did not added: 
[cartridge-name] %s", "c3"), addedC3, true);
-
-            boolean added = 
cartridgeGroupTest.addCartridgeGroup("cartrdige-nested.json",
-                    restClient);
-            assertEquals(String.format("Cartridge Group did not added: 
[cartridge-group-name] %s",
-                    "cartrdige-nested"), added, true);
-            CartridgeGroupBean bean = 
cartridgeGroupTest.getCartridgeGroup("G1",
-                    restClient);
-            assertEquals(String.format("Cartridge Group name did not match: 
[cartridge-group-name] %s",
-                    "cartrdige-nested"), bean.getName(), "G1");
-
-            boolean updated = 
cartridgeGroupTest.updateCartridgeGroup("cartrdige-nested.json",
-                    restClient);
-            assertEquals(String.format("Cartridge Group did not updated: 
[cartridge-group-name] %s",
-                    "cartrdige-nested"), updated, true);
-            CartridgeGroupBean updatedBean = 
cartridgeGroupTest.getCartridgeGroup("G1",
-                    restClient);
-            assertEquals(String.format("Updated Cartridge Group didn't match: 
[cartridge-group-name] %s",
-                    "cartrdige-nested"), updatedBean.getName(), "G1");
-
-            boolean removedC1 = cartridgeTest.removeCartridge("c1",
-                    restClient);
-            assertEquals(String.format("Cartridge can be removed while it is 
used in cartridge group: [cartridge-name] %s",
-                    "c1"), removedC1, false);
-
-            boolean removedC2 = cartridgeTest.removeCartridge("c2",
-                    restClient);
-            assertEquals(String.format("Cartridge can be removed while it is 
used in cartridge group: [cartridge-name] %s",
-                    "c2"), removedC2, false);
-
-            boolean removedC3 = cartridgeTest.removeCartridge("c3",
-                    restClient);
-            assertEquals(String.format("Cartridge can be removed while it is 
used in cartridge group: [cartridge-name] %s",
-                    "c2"), removedC3, false);
-
-            boolean removed = cartridgeGroupTest.removeCartridgeGroup("G1",
-                    restClient);
-            assertEquals(String.format("Cartridge Group did not removed: 
[cartridge-group-name] %s",
-                    "cartrdige-nested"), removed, true);
-
-            CartridgeGroupBean beanRemoved = 
cartridgeGroupTest.getCartridgeGroup("G1",
-                    restClient);
-            assertEquals(String.format("Cartridge Group did not removed 
completely: [cartridge-group-name] %s",
-                    "cartrdige-nested"), beanRemoved, null);
-
-            removedC1 = cartridgeTest.removeCartridge("c1",
-                    restClient);
-            assertEquals(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
-                    "c1"), removedC1, true);
-
-            removedC2 = cartridgeTest.removeCartridge("c2",
-                    restClient);
-            assertEquals(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
-                    "c2"), removedC2, true);
-
-            removedC3 = cartridgeTest.removeCartridge("c3",
-                    restClient);
-            assertEquals(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
-                    "c3"), removedC3, true);
-
-            log.info("Ended Cartridge group test 
case**************************************");
-
-        } catch (Exception e) {
-            log.error("An error occurred while handling Cartridge group test 
case", e);
-            assertTrue("An error occurred while handling Cartridge group test 
case", false);
-        }
-    }
 
     @Test
     public void testApplication() {
         log.info("Started application test 
case**************************************");
+        String autoscalingPolicyId = "autoscaling-policy-1";
 
         try {
-            boolean addedScalingPolicy = 
autoscalingPolicyTest.addAutoscalingPolicy("autoscaling-policy-1.json",
-                    restClient);
+            boolean addedScalingPolicy = 
restClient.addEntity(RestConstants.AUTOSCALING_POLICIES_PATH
+                            + "/" + autoscalingPolicyId + ".json",
+                    RestConstants.AUTOSCALING_POLICIES, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(addedScalingPolicy, true);
 
-            boolean addedC1 = cartridgeTest.addCartridge("c1.json", 
restClient);
+            boolean addedC1 = 
restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c1.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC1, true);
 
-            boolean addedC2 = cartridgeTest.addCartridge("c2.json", 
restClient);
+            boolean addedC2 = 
restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c2.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC2, true);
 
-            boolean addedC3 = cartridgeTest.addCartridge("c3.json", 
restClient);
+            boolean addedC3 = 
restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c3.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC3, true);
 
-            boolean addedG1 = 
cartridgeGroupTest.addCartridgeGroup("cartrdige-nested.json",
-                    restClient);
+            boolean addedG1 = 
restClient.addEntity(RestConstants.CARTRIDGE_GROUPS_PATH +
+                            "/" + "cartrdige-nested.json", 
RestConstants.CARTRIDGE_GROUPS,
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(addedG1, true);
-            CartridgeGroupBean beanG1 = 
cartridgeGroupTest.getCartridgeGroup("G1",
-                    restClient);
+
+            CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
+                    getEntity(RestConstants.CARTRIDGE_GROUPS, "G1",
+                            CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(beanG1.getName(), "G1");
 
-            boolean addedN1 = 
networkPartitionTest.addNetworkPartition("network-partition-1.json",
-                    restClient);
+            boolean addedN1 = 
restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            "network-partition-1.json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(addedN1, true);
 
-            boolean addedN2 = 
networkPartitionTest.addNetworkPartition("network-partition-2.json",
-                    restClient);
+            boolean addedN2 = 
restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            "network-partition-2.json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(addedN2, true);
 
-            boolean addedDep = 
deploymentPolicyTest.addDeploymentPolicy("deployment-policy-1.json",
-                    restClient);
+            boolean addedDep = 
restClient.addEntity(RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+                            "deployment-policy-1.json",
+                    RestConstants.DEPLOYMENT_POLICIES, 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(addedDep, true);
 
-            boolean added = applicationTest.addApplication("g-sc-G123-1.json",
-                    restClient);
+            boolean added = 
restClient.addEntity(RestConstants.APPLICATIONS_PATH + "/" +
+                            "g-sc-G123-1.json", RestConstants.APPLICATIONS,
+                    RestConstants.APPLICATIONS_NAME);
             assertEquals(added, true);
-            ApplicationBean bean = 
applicationTest.getApplication("g-sc-G123-1",
-                    restClient);
+
+            ApplicationBean bean = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    "g-sc-G123-1", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(bean.getApplicationId(), "g-sc-G123-1");
 
             assertEquals(bean.getComponents().getGroups().get(0).getName(), 
"G1");
@@ -308,12 +120,12 @@ public class SampleApplicationsTest extends 
StratosTestServerManager {
             
assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMin(),
 1);
             
assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMax(),
 2);
 
-            boolean updated = 
applicationTest.updateApplication("g-sc-G123-1.json",
-                    restClient);
+            boolean updated = 
restClient.updateEntity(RestConstants.APPLICATIONS_PATH + 
"/g-sc-G123-1-v1.json",
+                    RestConstants.APPLICATIONS, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(updated, true);
 
-            ApplicationBean updatedBean = 
applicationTest.getApplication("g-sc-G123-1",
-                    restClient);
+            ApplicationBean updatedBean = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    "g-sc-G123-1", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
 
             assertEquals(bean.getApplicationId(), "g-sc-G123-1");
             
assertEquals(updatedBean.getComponents().getGroups().get(0).getName(), "G1");
@@ -344,61 +156,62 @@ public class SampleApplicationsTest extends 
StratosTestServerManager {
             
assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMax(),
 3);
 
 
-            boolean removedGroup = 
cartridgeGroupTest.removeCartridgeGroup("G1",
-                    restClient);
+            boolean removedGroup = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(removedGroup, false);
 
-            boolean removedAuto = 
autoscalingPolicyTest.removeAutoscalingPolicy("autoscaling-policy-1",
-                    restClient);
+            boolean removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, false);
 
-            boolean removedNet = 
networkPartitionTest.removeNetworkPartition("network-partition-1",
-                    restClient);
+            boolean removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-1",
+                    RestConstants.NETWORK_PARTITIONS_NAME);
             //Trying to remove the used network partition
             assertEquals(removedNet, false);
 
-            boolean removedDep = 
deploymentPolicyTest.removeDeploymentPolicy("deployment-policy-1",
-                    restClient);
+            boolean removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-1", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, false);
 
-            boolean removed = applicationTest.removeApplication("g-sc-G123-1",
-                    restClient);
+            boolean removed = 
restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1",
+                    RestConstants.APPLICATIONS_NAME);
             assertEquals(removed, true);
 
-            ApplicationBean beanRemoved = 
applicationTest.getApplication("g-sc-G123-1",
-                    restClient);
+            ApplicationBean beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    "g-sc-G123-1", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(beanRemoved, null);
 
-            removedGroup = cartridgeGroupTest.removeCartridgeGroup("G1",
-                    restClient);
+            removedGroup = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(removedGroup, true);
 
-            boolean removedC1 = cartridgeTest.removeCartridge("c1",
-                    restClient);
+            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c1",
+                    RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC1, true);
 
-            boolean removedC2 = cartridgeTest.removeCartridge("c2",
-                    restClient);
+            boolean removedC2 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c2",
+                    RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC2, true);
 
-            boolean removedC3 = cartridgeTest.removeCartridge("c3",
-                    restClient);
+            boolean removedC3 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c3",
+                    RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC3, true);
 
-            removedAuto = 
autoscalingPolicyTest.removeAutoscalingPolicy("autoscaling-policy-1",
-                    restClient);
+            removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, true);
 
-            removedDep = 
deploymentPolicyTest.removeDeploymentPolicy("deployment-policy-1",
-                    restClient);
+            removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-1", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, true);
 
-            removedNet = 
networkPartitionTest.removeNetworkPartition("network-partition-1",
-                    restClient);
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedNet, true);
 
-            boolean removedN2 = 
networkPartitionTest.removeNetworkPartition("network-partition-2",
-                    restClient);
+            boolean removedN2 = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-2", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedN2, true);
 
             log.info("Ended application test 
case**************************************");
@@ -409,167 +222,194 @@ public class SampleApplicationsTest extends 
StratosTestServerManager {
         }
     }
 
-    @Test
+    @Test(dependsOnMethods = {"testApplication"})
     public void testDeployApplication() {
         try {
             log.info("Started application deploy/undeploy test 
case**************************************");
 
-            //Initializing event Receivers
-            initializeApplicationEventReceiver();
-            initializeTopologyEventReceiver();
-
-            //Verifying whether the relevant Topologies are initialized
-            assertApplicationTopologyInitialized();
-            assertTopologyInitialized();
+            String autoscalingPolicyId = "autoscaling-policy-1";
 
-            boolean addedScalingPolicy = 
autoscalingPolicyTest.addAutoscalingPolicy("autoscaling-policy-1.json",
-                    restClient);
+            boolean addedScalingPolicy = 
restClient.addEntity(RestConstants.AUTOSCALING_POLICIES_PATH
+                            + "/" + autoscalingPolicyId + ".json",
+                    RestConstants.AUTOSCALING_POLICIES, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(addedScalingPolicy, true);
 
-            boolean addedC1 = cartridgeTest.addCartridge("c1.json", 
restClient);
+            boolean addedC1 = 
restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c1.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC1, true);
 
-            boolean addedC2 = cartridgeTest.addCartridge("c2.json", 
restClient);
+            boolean addedC2 = 
restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c2.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC2, true);
 
-            boolean addedC3 = cartridgeTest.addCartridge("c3.json", 
restClient);
+            boolean addedC3 = 
restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c3.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC3, true);
 
-            boolean addedG1 = 
cartridgeGroupTest.addCartridgeGroup("cartrdige-nested.json",
-                    restClient);
+            boolean addedG1 = 
restClient.addEntity(RestConstants.CARTRIDGE_GROUPS_PATH +
+                            "/" + "cartrdige-nested.json", 
RestConstants.CARTRIDGE_GROUPS,
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(addedG1, true);
-            CartridgeGroupBean beanG1 = 
cartridgeGroupTest.getCartridgeGroup("G1",
-                    restClient);
+
+            CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
+                    getEntity(RestConstants.CARTRIDGE_GROUPS, "G1",
+                            CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(beanG1.getName(), "G1");
 
-            boolean addedN1 = 
networkPartitionTest.addNetworkPartition("network-partition-1.json",
-                    restClient);
+            boolean addedN1 = 
restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            "network-partition-1.json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(addedN1, true);
 
-            boolean addedN2 = 
networkPartitionTest.addNetworkPartition("network-partition-2.json",
-                    restClient);
+            boolean addedN2 = 
restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            "network-partition-2.json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(addedN2, true);
 
-            boolean addedDep = 
deploymentPolicyTest.addDeploymentPolicy("deployment-policy-1.json",
-                    restClient);
+            boolean addedDep = 
restClient.addEntity(RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+                            "deployment-policy-1.json",
+                    RestConstants.DEPLOYMENT_POLICIES, 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(addedDep, true);
 
-            boolean added = applicationTest.addApplication("g-sc-G123-1.json",
-                    restClient);
+            boolean added = 
restClient.addEntity(RestConstants.APPLICATIONS_PATH + "/" +
+                            "g-sc-G123-1.json", RestConstants.APPLICATIONS,
+                    RestConstants.APPLICATIONS_NAME);
             assertEquals(added, true);
-            ApplicationBean bean = 
applicationTest.getApplication("g-sc-G123-1",
-                    restClient);
+
+            ApplicationBean bean = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    "g-sc-G123-1", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(bean.getApplicationId(), "g-sc-G123-1");
 
-            boolean addAppPolicy = applicationPolicyTest.addApplicationPolicy(
-                    "application-policy-1.json", restClient);
+            boolean addAppPolicy = 
restClient.addEntity(RestConstants.APPLICATION_POLICIES_PATH + "/" +
+                            "application-policy-1.json", 
RestConstants.APPLICATION_POLICIES,
+                    RestConstants.APPLICATION_POLICIES_NAME);
             assertEquals(addAppPolicy, true);
 
-            ApplicationPolicyBean policyBean = 
applicationPolicyTest.getApplicationPolicy(
-                    "application-policy-1", restClient);
+            ApplicationPolicyBean policyBean = (ApplicationPolicyBean) 
restClient.getEntity(
+                    RestConstants.APPLICATION_POLICIES,
+                    "application-policy-1", ApplicationPolicyBean.class,
+                    RestConstants.APPLICATION_POLICIES_NAME);
 
             //deploy the application
-            boolean deployed = 
applicationTest.deployApplication(bean.getApplicationId(),
-                    policyBean.getId(), restClient);
+            String resourcePath = RestConstants.APPLICATIONS + "/" + 
"g-sc-G123-1" +
+                    RestConstants.APPLICATIONS_DEPLOY + "/" + 
"application-policy-1";
+            boolean deployed = restClient.deployEntity(resourcePath,
+                    RestConstants.APPLICATIONS_NAME);
             assertEquals(deployed, true);
 
             //Application active handling
-            assertApplicationActivation(bean.getApplicationId());
+            
TopologyHandler.getInstance().assertApplicationActivation(bean.getApplicationId());
 
             //Group active handling
-            assertGroupActivation(bean.getApplicationId());
+            
TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId());
 
             //Cluster active handling
-            assertClusterActivation(bean.getApplicationId());
+            
TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId());
 
             //Updating application
-            boolean updated = 
applicationTest.updateApplication("g-sc-G123-1.json",
-                    restClient);
+            boolean updated = 
restClient.updateEntity(RestConstants.APPLICATIONS_PATH + "/" +
+                            "g-sc-G123-1-v1.json", RestConstants.APPLICATIONS,
+                    RestConstants.APPLICATIONS_NAME);
             assertEquals(updated, true);
 
-            assertGroupInstanceCount(bean.getApplicationId(), "group3", 2);
+            
TopologyHandler.getInstance().assertGroupInstanceCount(bean.getApplicationId(), 
"group3", 2);
 
-            assertClusterMinMemberCount(bean.getApplicationId(), 2);
+            
TopologyHandler.getInstance().assertClusterMinMemberCount(bean.getApplicationId(),
 2);
 
-            ApplicationBean updatedBean = 
applicationTest.getApplication("g-sc-G123-1",
-                    restClient);
+            ApplicationBean updatedBean = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    "g-sc-G123-1", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(updatedBean.getApplicationId(), "g-sc-G123-1");
 
-            boolean removedGroup = 
cartridgeGroupTest.removeCartridgeGroup("G1",
-                    restClient);
+            boolean removedGroup = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(removedGroup, false);
 
-            boolean removedAuto = 
autoscalingPolicyTest.removeAutoscalingPolicy("autoscaling-policy-1",
-                    restClient);
+            boolean removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, false);
 
-            boolean removedNet = 
networkPartitionTest.removeNetworkPartition("network-partition-1",
-                    restClient);
+            boolean removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-1",
+                    RestConstants.NETWORK_PARTITIONS_NAME);
             //Trying to remove the used network partition
             assertEquals(removedNet, false);
 
-            boolean removedDep = 
deploymentPolicyTest.removeDeploymentPolicy("deployment-policy-1",
-                    restClient);
+            boolean removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-1", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, false);
 
             //Un-deploying the application
-            boolean unDeployed = 
applicationTest.undeployApplication("g-sc-G123-1",
-                    restClient);
+            String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + 
"g-sc-G123-1" +
+                    RestConstants.APPLICATIONS_UNDEPLOY;
+
+            boolean unDeployed = 
restClient.undeployEntity(resourcePathUndeploy,
+                    RestConstants.APPLICATIONS_NAME);
             assertEquals(unDeployed, true);
 
-            assertApplicationUndeploy("g-sc-G123-1");
+            boolean undeploy = 
TopologyHandler.getInstance().assertApplicationUndeploy("g-sc-G123-1");
+            if (!undeploy) {
+                //Need to forcefully undeploy the application
+                log.info("Force undeployment is going to start for the 
[application] " + "g-sc-G123-1");
+
+                restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + 
"g-sc-G123-1" +
+                        RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", 
RestConstants.APPLICATIONS);
+
+                boolean forceUndeployed = 
TopologyHandler.getInstance().assertApplicationUndeploy("g-sc-G123-1");
+                assertEquals(String.format("Forceful undeployment failed for 
the application %s",
+                        "g-sc-G123-1"), forceUndeployed, true);
 
-            boolean removed = applicationTest.removeApplication("g-sc-G123-1",
-                    restClient);
+            }
+
+            boolean removed = 
restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1",
+                    RestConstants.APPLICATIONS_NAME);
             assertEquals(removed, true);
 
-            ApplicationBean beanRemoved = 
applicationTest.getApplication("g-sc-G123-1",
-                    restClient);
+            ApplicationBean beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    "g-sc-G123-1", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(beanRemoved, null);
 
-            removedGroup = cartridgeGroupTest.removeCartridgeGroup("G1",
-                    restClient);
+            removedGroup = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(removedGroup, true);
 
-            boolean removedC1 = cartridgeTest.removeCartridge("c1",
-                    restClient);
+            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c1",
+                    RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC1, true);
 
-            boolean removedC2 = cartridgeTest.removeCartridge("c2",
-                    restClient);
+            boolean removedC2 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c2",
+                    RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC2, true);
 
-            boolean removedC3 = cartridgeTest.removeCartridge("c3",
-                    restClient);
+            boolean removedC3 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c3",
+                    RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC3, true);
 
-            removedAuto = 
autoscalingPolicyTest.removeAutoscalingPolicy("autoscaling-policy-1",
-                    restClient);
+            removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, true);
 
-            removedDep = 
deploymentPolicyTest.removeDeploymentPolicy("deployment-policy-1",
-                    restClient);
+            removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-1", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, true);
 
-            //Remove network partition used by application policy
-            removedNet = 
networkPartitionTest.removeNetworkPartition("network-partition-1",
-                    restClient);
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedNet, false);
 
-            boolean removedN2 = 
networkPartitionTest.removeNetworkPartition("network-partition-2",
-                    restClient);
+            boolean removedN2 = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-2", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedN2, false);
 
-            boolean removeAppPolicy = 
applicationPolicyTest.removeApplicationPolicy("application-policy-1",
-                    restClient);
+            boolean removeAppPolicy = 
restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
+                    "application-policy-1", 
RestConstants.APPLICATION_POLICIES_NAME);
             assertEquals(removeAppPolicy, true);
 
-            removedNet = 
networkPartitionTest.removeNetworkPartition("network-partition-1",
-                    restClient);
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedNet, true);
 
-            removedN2 = 
networkPartitionTest.removeNetworkPartition("network-partition-2",
-                    restClient);
+            removedN2 = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-2", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedN2, true);
 
             log.info("Ended application deploy/undeploy test 
case**************************************");
@@ -580,604 +420,5 @@ public class SampleApplicationsTest extends 
StratosTestServerManager {
         }
     }
 
-    @Test
-    public void testNetworkPartition() {
-        try {
-            log.info("Started network partition test 
case**************************************");
-
-            boolean added = 
networkPartitionTest.addNetworkPartition("network-partition-1.json",
-                    restClient);
-            assertEquals(added, true);
-            NetworkPartitionBean bean = 
networkPartitionTest.getNetworkPartition("network-partition-1",
-                    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",
-                    restClient);
-            assertEquals(updated, true);
-            NetworkPartitionBean updatedBean = 
networkPartitionTest.getNetworkPartition("network-partition-1",
-                    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",
-                    restClient);
-            assertEquals(removed, true);
-
-            NetworkPartitionBean beanRemoved = 
networkPartitionTest.getNetworkPartition("network-partition-1",
-                    restClient);
-            assertEquals(beanRemoved, null);
-
-            log.info("Ended network partition test 
case**************************************");
-        } catch (Exception e) {
-            log.error("An error occurred while handling network partitions",e);
-            assertTrue("An error occurred while handling network partitions", 
false);
-        }
-    }
-
-    @Test
-    public void testDeploymentPolicy() {
-        try {
-            log.info("Started deployment policy test 
case**************************************");
-
-            boolean addedN1 = 
networkPartitionTest.addNetworkPartition("network-partition-1.json",
-                    restClient);
-            assertEquals(addedN1, true);
-
-            boolean addedN2 = 
networkPartitionTest.addNetworkPartition("network-partition-2.json",
-                    restClient);
-            assertEquals(addedN2, true);
-
-            boolean addedDep = 
deploymentPolicyTest.addDeploymentPolicy("deployment-policy-1.json",
-                    restClient);
-            assertEquals(addedDep, true);
-
-            DeploymentPolicyBean bean = 
deploymentPolicyTest.getDeploymentPolicy(
-                    "deployment-policy-1", 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",
-                    restClient);
-            assertEquals(updated, true);
-
-            //update deployment policy with new partition and max values
-            boolean updatedDep = 
deploymentPolicyTest.updateDeploymentPolicy("deployment-policy-1.json",
-                    restClient);
-            assertEquals(updatedDep, true);
-
-            DeploymentPolicyBean updatedBean = 
deploymentPolicyTest.getDeploymentPolicy(
-                    "deployment-policy-1", 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",
-                    restClient);
-            //Trying to remove the used network partition
-            assertEquals(removedNet, false);
-
-            boolean removedDep = 
deploymentPolicyTest.removeDeploymentPolicy("deployment-policy-1",
-                    restClient);
-            assertEquals(removedDep, true);
-
-            DeploymentPolicyBean beanRemovedDep = 
deploymentPolicyTest.getDeploymentPolicy("deployment-policy-1",
-                    restClient);
-            assertEquals(beanRemovedDep, null);
-
-            boolean removedN1 = 
networkPartitionTest.removeNetworkPartition("network-partition-1",
-                    restClient);
-            assertEquals(removedN1, true);
-
-            NetworkPartitionBean beanRemovedN1 = 
networkPartitionTest.getNetworkPartition("network-partition-1",
-                    restClient);
-            assertEquals(beanRemovedN1, null);
-
-            boolean removedN2 = 
networkPartitionTest.removeNetworkPartition("network-partition-2",
-                    restClient);
-            assertEquals(removedN2, true);
-
-            NetworkPartitionBean beanRemovedN2 = 
networkPartitionTest.getNetworkPartition("network-partition-2",
-                    restClient);
-            assertEquals(beanRemovedN2, null);
-
-            log.info("Ended deployment policy test 
case**************************************");
-
-        } catch (Exception e) {
-            log.error("An error occurred while handling deployment policy", e);
-            assertTrue("An error occurred while handling deployment policy", 
false);
-        }
-    }
-
-    @Test
-    public void testCartridge() {
-        log.info("Started Cartridge test 
case**************************************");
-
-        try {
-            boolean added = cartridgeTest.addCartridge("c0.json", restClient);
-            assertEquals(added, true);
-            CartridgeBean bean = cartridgeTest.getCartridge("c0", 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",
-                    restClient);
-            assertEquals(updated, true);
-            CartridgeBean updatedBean = cartridgeTest.getCartridge("c0",
-                    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",
-                    restClient);
-            assertEquals(removed, true);
-
-            CartridgeBean beanRemoved = cartridgeTest.getCartridge("c0",
-                    restClient);
-            assertEquals(beanRemoved, null);
-
-            log.info("Ended Cartridge test 
case**************************************");
-        } catch (Exception e) {
-            log.error("An error occurred while handling cartridges", 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");
-        assertApplicationActivation(applicationId);
-        executeCommand(getApplicationsPath() + "/" + applicationFolderName + 
"/scripts/mock/undeploy.sh");
-        assertApplicationNotExists(applicationId);
-    }
-
-    /**
-     * Initialize application event receiver
-     */
-    private void initializeApplicationEventReceiver() {
-        if (applicationsEventReceiver == null) {
-            applicationsEventReceiver = new ApplicationsEventReceiver();
-            ExecutorService executorService = 
StratosThreadPool.getExecutorService("STRATOS_TEST_SERVER", 1);
-            applicationsEventReceiver.setExecutorService(executorService);
-            applicationsEventReceiver.execute();
-        }
-    }
-
-    /**
-     * Initialize Topology event receiver
-     */
-    private void initializeTopologyEventReceiver() {
-        if (topologyEventReceiver == null) {
-            topologyEventReceiver = new TopologyEventReceiver();
-            ExecutorService executorService = 
StratosThreadPool.getExecutorService("STRATOS_TEST_SERVER1", 1);
-            topologyEventReceiver.setExecutorService(executorService);
-            topologyEventReceiver.execute();
-        }
-    }
-
-    /**
-     * Execute shell command
-     *
-     * @param commandText
-     */
-    private void executeCommand(String commandText) {
-        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-        try {
-            CommandLine commandline = CommandLine.parse(commandText);
-            DefaultExecutor exec = new DefaultExecutor();
-            PumpStreamHandler streamHandler = new 
PumpStreamHandler(outputStream);
-            exec.setStreamHandler(streamHandler);
-            exec.execute(commandline);
-            log.info(outputStream.toString());
-        } catch (Exception e) {
-            log.error(outputStream.toString(), e);
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Assert application Topology initialization
-     *
-     */
-    private void assertApplicationTopologyInitialized() {
-        long startTime = System.currentTimeMillis();
-        boolean applicationTopologyInitialized = 
ApplicationManager.getApplications().isInitialized();
-        while (!applicationTopologyInitialized) {
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
-            }
-            applicationTopologyInitialized = 
ApplicationManager.getApplications().isInitialized();
-            if ((System.currentTimeMillis() - startTime) > 
APPLICATION_ACTIVATION_TIMEOUT) {
-                break;
-            }
-        }
-        assertEquals(String.format("Application Topology didn't get 
initialized "), applicationTopologyInitialized, true);
-    }
-
-    /**
-     * Assert Topology initialization
-     *
-     */
-    private void assertTopologyInitialized() {
-        long startTime = System.currentTimeMillis();
-        boolean topologyInitialized = 
TopologyManager.getTopology().isInitialized();
-        while (!topologyInitialized) {
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
-            }
-            topologyInitialized = 
TopologyManager.getTopology().isInitialized();
-            if ((System.currentTimeMillis() - startTime) > 
APPLICATION_ACTIVATION_TIMEOUT) {
-                break;
-            }
-        }
-        assertEquals(String.format("Topology didn't get initialized "), 
topologyInitialized, true);
-    }
-
-    /**
-     * Assert application activation
-     *
-     * @param applicationName
-     */
-    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());
-    }
-
-    /**
-     * Assert application activation
-     *
-     * @param applicationName
-     */
-    private void assertGroupActivation(String applicationName) {
-        Application application = 
ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: 
[application-id] %s",
-                applicationName), application);
-
-        Collection<Group> groups = application.getAllGroupsRecursively();
-        for (Group group : groups) {
-            assertEquals(group.getInstanceContextCount() >= 
group.getGroupMinInstances(), true);
-        }
-    }
-
-    /**
-     * Assert application activation
-     *
-     * @param applicationName
-     */
-    private void assertClusterActivation(String applicationName) {
-        Application application = 
ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: 
[application-id] %s",
-                applicationName), application);
-
-        Set<ClusterDataHolder> clusterDataHolderSet = 
application.getClusterDataRecursively();
-        for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
-            String serviceName = clusterDataHolder.getServiceType();
-            String clusterId = clusterDataHolder.getClusterId();
-            Service service = 
TopologyManager.getTopology().getService(serviceName);
-            assertNotNull(String.format("Service is not found: 
[application-id] %s [service] %s",
-                    applicationName, serviceName), service);
-
-            Cluster cluster = service.getCluster(clusterId);
-            assertNotNull(String.format("Cluster is not found: 
[application-id] %s [service] %s [cluster-id] %s",
-                    applicationName, serviceName, clusterId), cluster);
-            boolean clusterActive = false;
-
-            for (ClusterInstance instance : 
cluster.getInstanceIdToInstanceContextMap().values()) {
-                int activeInstances = 0;
-                for (Member member : cluster.getMembers()) {
-                    if 
(member.getClusterInstanceId().equals(instance.getInstanceId())) {
-                        if (member.getStatus().equals(MemberStatus.Active)) {
-                            activeInstances++;
-                        }
-                    }
-                }
-                clusterActive = activeInstances >= 
clusterDataHolder.getMinInstances();
-
-                if (!clusterActive) {
-                    break;
-                }
-            }
-            assertEquals(String.format("Cluster status did not change to 
active: [cluster-id] %s", clusterId),
-                    clusterActive, true);
-        }
-
-    }
-
-    private void assertClusterMinMemberCount(String applicationName, int 
minMembers) {
-        long startTime = System.currentTimeMillis();
-
-        Application application = 
ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: 
[application-id] %s",
-                applicationName), application);
-
-        Set<ClusterDataHolder> clusterDataHolderSet = 
application.getClusterDataRecursively();
-        for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
-            String serviceName = clusterDataHolder.getServiceType();
-            String clusterId = clusterDataHolder.getClusterId();
-            Service service = 
TopologyManager.getTopology().getService(serviceName);
-            assertNotNull(String.format("Service is not found: 
[application-id] %s [service] %s",
-                    applicationName, serviceName), service);
-
-            Cluster cluster = service.getCluster(clusterId);
-            assertNotNull(String.format("Cluster is not found: 
[application-id] %s [service] %s [cluster-id] %s",
-                    applicationName, serviceName, clusterId), cluster);
-            boolean clusterActive = false;
-
-            for (ClusterInstance instance : 
cluster.getInstanceIdToInstanceContextMap().values()) {
-                int activeInstances = 0;
-                for (Member member : cluster.getMembers()) {
-                    if 
(member.getClusterInstanceId().equals(instance.getInstanceId())) {
-                        if (member.getStatus().equals(MemberStatus.Active)) {
-                            activeInstances++;
-                        }
-                    }
-                }
-                clusterActive = activeInstances >= minMembers;
-
-                while (!clusterActive) {
-                    try {
-                        Thread.sleep(1000);
-                    } catch (InterruptedException ignore) {
-                    }
-                    service = 
TopologyManager.getTopology().getService(serviceName);
-                    assertNotNull(String.format("Service is not found: 
[application-id] %s [service] %s",
-                            applicationName, serviceName), service);
-
-                    cluster = service.getCluster(clusterId);
-                    activeInstances = 0;
-                    for (Member member : cluster.getMembers()) {
-                        if 
(member.getClusterInstanceId().equals(instance.getInstanceId())) {
-                            if 
(member.getStatus().equals(MemberStatus.Active)) {
-                                activeInstances++;
-                            }
-                        }
-                    }
-                    clusterActive = activeInstances >= minMembers;
-                    assertNotNull(String.format("Cluster is not found: 
[application-id] %s [service] %s [cluster-id] %s",
-                            applicationName, serviceName, clusterId), cluster);
-
-                    if ((System.currentTimeMillis() - startTime) > 
APPLICATION_ACTIVATION_TIMEOUT) {
-                        break;
-                    }
-                }
-            }
-            assertEquals(String.format("Cluster status did not change to 
active: [cluster-id] %s", clusterId),
-                    clusterActive, true);
-        }
-
-    }
-
-
-    /**
-     * Assert application activation
-     *
-     * @param applicationName
-     */
-    private void assertApplicationUndeploy(String applicationName) {
-        long startTime = System.currentTimeMillis();
-        Application application = 
ApplicationManager.getApplications().getApplication(applicationName);
-        ApplicationContext applicationContext = null;
-        try {
-            applicationContext = 
AutoscalerServiceClient.getInstance().getApplication(applicationName);
-        } catch (RemoteException e) {
-            log.error("Error while getting the application context for 
[application] " + applicationName);
-        }
-        while (((application != null) && application.getInstanceContextCount() 
> 0) ||
-                (applicationContext == null || 
applicationContext.getStatus().equals(APPLICATION_STATUS_UNDEPLOYING))) {
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
-            }
-            application = 
ApplicationManager.getApplications().getApplication(applicationName);
-            try {
-                applicationContext = 
AutoscalerServiceClient.getInstance().getApplication(applicationName);
-            } catch (RemoteException e) {
-                log.error("Error while getting the application context for 
[application] " + applicationName);
-            }
-            if ((System.currentTimeMillis() - startTime) > 
APPLICATION_ACTIVATION_TIMEOUT) {
-                break;
-            }
-        }
-
-        assertNotNull(String.format("Application is not found: 
[application-id] %s",
-                applicationName), application);
-        assertNotNull(String.format("Application Context is not found: 
[application-id] %s",
-                applicationName), applicationContext);
-
-        //Force undeployment after the graceful deployment
-        if (application.getInstanceContextCount() > 0 ||
-                
applicationContext.getStatus().equals(APPLICATION_STATUS_UNDEPLOYING)) {
-            log.info("Force undeployment is going to start for the 
[application] " + applicationName);
-
-            applicationTest.forceUndeployApplication(applicationName, 
restClient);
-            while (application.getInstanceContextCount() > 0 ||
-                    
applicationContext.getStatus().equals(APPLICATION_STATUS_UNDEPLOYING)) {
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException ignore) {
-                }
-                application = 
ApplicationManager.getApplications().getApplication(applicationName);
-                if ((System.currentTimeMillis() - startTime) > 
APPLICATION_ACTIVATION_TIMEOUT) {
-                    break;
-                }
-            }
-        }
-        assertEquals(String.format("Application status did not change to 
Created: [application-id] %s", applicationName),
-                APPLICATION_STATUS_CREATED, applicationContext.getStatus());
-
-    }
-
-    /**
-     * Assert application activation
-     *
-     * @param applicationName
-     */
-    private void assertGroupInstanceCount(String applicationName, String 
groupAlias, int count) {
-        long startTime = System.currentTimeMillis();
-        Application application = 
ApplicationManager.getApplications().getApplication(applicationName);
-        if (application != null) {
-            Group group = application.getGroupRecursively(groupAlias);
-            while (group.getInstanceContextCount() != count) {
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException ignore) {
-                }
-                if ((System.currentTimeMillis() - startTime) > 
APPLICATION_ACTIVATION_TIMEOUT) {
-                    break;
-                }
-            }
-            for (GroupInstance instance : 
group.getInstanceIdToInstanceContextMap().values()) {
-                while (!instance.getStatus().equals(GroupStatus.Active)) {
-                    try {
-                        Thread.sleep(1000);
-                    } catch (InterruptedException ignore) {
-                    }
-                    if ((System.currentTimeMillis() - startTime) > 
APPLICATION_ACTIVATION_TIMEOUT) {
-                        break;
-                    }
-                }
-            }
-            assertEquals(String.format("Application status did not change to 
active: [application-id] %s", applicationName),
-                    group.getInstanceContextCount(), count);
-        }
-        assertNotNull(String.format("Application is not found: 
[application-id] %s", applicationName), application);
-
-    }
-
-    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() {
-        return getResourcesFolderPath() + 
"/../../../../../../samples/applications";
-    }
-
-    /**
-     * 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/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
index 020ce41..5453bbd 100755
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/StratosTestServerManager.java
@@ -26,6 +26,9 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.apache.stratos.common.test.TestLogAppender;
+import org.apache.stratos.integration.tests.rest.RestClient;
+import 
org.apache.stratos.messaging.message.receiver.application.ApplicationsEventReceiver;
+import 
org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver;
 import org.testng.annotations.AfterSuite;
 import org.testng.annotations.BeforeSuite;
 import org.wso2.carbon.integration.framework.TestServerManager;
@@ -53,6 +56,8 @@ public class StratosTestServerManager extends 
TestServerManager {
     private static final String MOCK_IAAS_XML_FILE = "mock-iaas.xml";
     private static final String JNDI_PROPERTIES_FILE = "jndi.properties";
     private static final String JMS_OUTPUT_ADAPTER_FILE = 
"JMSOutputAdaptor.xml";
+    protected RestClient restClient;
+    private String endpoint = "https://localhost:9443";;
 
     private BrokerService broker = new BrokerService();
     private TestLogAppender testLogAppender = new TestLogAppender();
@@ -62,6 +67,7 @@ public class StratosTestServerManager extends 
TestServerManager {
     public StratosTestServerManager() {
         super(CARBON_ZIP, PORT_OFFSET);
         serverUtils = new ServerUtils();
+        restClient = new RestClient(endpoint, "admin", "admin");
     }
 
     @Override

Reply via email to