http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
index 7f4bd23..3c0cee1 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
@@ -21,6 +21,7 @@ package org.apache.stratos.integration.tests.application;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.beans.application.ApplicationBean;
+import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
 import org.apache.stratos.integration.tests.RestConstants;
 import org.apache.stratos.integration.tests.StratosTestServerManager;
 import org.apache.stratos.integration.tests.TopologyHandler;
@@ -51,38 +52,38 @@ public class PartitionRoundRobinClusterTest extends 
StratosTestServerManager {
     public void testDeployApplication() {
         try {
             log.info("-------------------------------Started application 
Bursting test case-------------------------------");
-
+            TopologyHandler topologyHandler = TopologyHandler.getInstance();
             String autoscalingPolicyId = 
"autoscaling-policy-partition-round-robin-test";
 
-            boolean addedScalingPolicy = 
restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.AUTOSCALING_POLICIES_PATH
+            boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + 
RestConstants.AUTOSCALING_POLICIES_PATH
                             + "/" + autoscalingPolicyId + ".json",
                     RestConstants.AUTOSCALING_POLICIES, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(addedScalingPolicy, true);
 
-            boolean addedC1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c7-partition-round-robin-test.json",
+            boolean addedC1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c7-partition-round-robin-test.json",
                     RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC1, true);
 
-            boolean addedN1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+            boolean addedN1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
                             
"network-partition-partition-round-robin-test.json",
                     RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(addedN1, true);
 
-            boolean addedDep = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+            boolean addedDep = restClient.addEntity(RESOURCES_PATH + 
RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
                             
"deployment-policy-partition-round-robin-test.json",
                     RestConstants.DEPLOYMENT_POLICIES, 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(addedDep, true);
 
-            boolean added = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
+            boolean added = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
                             "partition-round-robin-test.json", 
RestConstants.APPLICATIONS,
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(added, true);
 
-            ApplicationBean bean = (ApplicationBean) 
restClientTenant1.getEntity(RestConstants.APPLICATIONS,
+            ApplicationBean bean = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
                     "partition-round-robin-test", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(bean.getApplicationId(), 
"partition-round-robin-test");
 
-            boolean addAppPolicy = restClientTenant1.addEntity(RESOURCES_PATH 
+ RestConstants.APPLICATION_POLICIES_PATH + "/" +
+            boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATION_POLICIES_PATH + "/" +
                             
"application-policy-partition-round-robin-test.json", 
RestConstants.APPLICATION_POLICIES,
                     RestConstants.APPLICATION_POLICIES_NAME);
             assertEquals(addAppPolicy, true);
@@ -90,45 +91,45 @@ public class PartitionRoundRobinClusterTest extends 
StratosTestServerManager {
             //deploy the application
             String resourcePath = RestConstants.APPLICATIONS + "/" + 
"partition-round-robin-test" +
                     RestConstants.APPLICATIONS_DEPLOY + "/" + 
"application-policy-partition-round-robin-test";
-            boolean deployed = restClientTenant1.deployEntity(resourcePath,
+            boolean deployed = restClient.deployEntity(resourcePath,
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(deployed, true);
 
 
             //Application active handling
-            
TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
-                    ApplicationStatus.Active, tenant1Id);
+            topologyHandler.assertApplicationStatus(bean.getApplicationId(),
+                    ApplicationStatus.Active);
 
             //Cluster active handling
-            
TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(), 
tenant1Id);
+            topologyHandler.assertClusterActivation(bean.getApplicationId());
 
             //Verifying whether members got created using round robin algorithm
-           /* assertClusterWithRoundRobinAlgorithm(bean.getApplicationId());
+            assertClusterWithRoundRobinAlgorithm(bean.getApplicationId());
 
             //Application in-active handling
             log.info("Waiting for the faulty member detection from " +
                     "CEP as the statistics are stopped...");
-            
TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
-                    ApplicationStatus.Inactive,tenant1Id);       */
+            topologyHandler.assertApplicationStatus(bean.getApplicationId(),
+                    ApplicationStatus.Inactive);
 
             //Application active handling after application becomes active 
again
-            
TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
-                    ApplicationStatus.Active,tenant1Id);
+            topologyHandler.assertApplicationStatus(bean.getApplicationId(),
+                    ApplicationStatus.Active);
 
             //Cluster active handling
-            
TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(),tenant1Id);
+            topologyHandler.assertClusterActivation(bean.getApplicationId());
 
-            boolean removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+            boolean removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
                     autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, false);
 
-            boolean removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            boolean removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-partition-round-robin-test",
                     RestConstants.NETWORK_PARTITIONS_NAME);
             //Trying to remove the used network partition
             assertEquals(removedNet, false);
 
-            boolean removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+            boolean removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
                     "deployment-policy-partition-round-robin-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, false);
 
@@ -136,55 +137,55 @@ public class PartitionRoundRobinClusterTest extends 
StratosTestServerManager {
             String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + 
"partition-round-robin-test" +
                     RestConstants.APPLICATIONS_UNDEPLOY;
 
-            boolean unDeployed = 
restClientTenant1.undeployEntity(resourcePathUndeploy,
+            boolean unDeployed = 
restClient.undeployEntity(resourcePathUndeploy,
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(unDeployed, true);
 
-            boolean undeploy = 
TopologyHandler.getInstance().assertApplicationUndeploy("partition-round-robin-test",
 tenant1Id);
+            boolean undeploy = 
topologyHandler.assertApplicationUndeploy("partition-round-robin-test");
             if (!undeploy) {
                 //Need to forcefully undeploy the application
                 log.info("Force undeployment is going to start for the 
[application] " + "partition-round-robin-test");
 
-                restClientTenant1.undeployEntity(RestConstants.APPLICATIONS + 
"/" + "partition-round-robin-test" +
+                restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + 
"partition-round-robin-test" +
                         RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", 
RestConstants.APPLICATIONS);
 
-                boolean forceUndeployed = 
TopologyHandler.getInstance().assertApplicationUndeploy("partition-round-robin-test",
 tenant1Id);
+                boolean forceUndeployed = 
topologyHandler.assertApplicationUndeploy("partition-round-robin-test");
                 assertEquals(String.format("Forceful undeployment failed for 
the application %s",
                         "partition-round-robin-test"), forceUndeployed, true);
 
             }
 
-            boolean removed = 
restClientTenant1.removeEntity(RestConstants.APPLICATIONS, 
"partition-round-robin-test",
+            boolean removed = 
restClient.removeEntity(RestConstants.APPLICATIONS, 
"partition-round-robin-test",
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(removed, true);
 
-            ApplicationBean beanRemoved = (ApplicationBean) 
restClientTenant1.getEntity(RestConstants.APPLICATIONS,
+            ApplicationBean beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
                     "partition-round-robin-test", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(beanRemoved, null);
 
-            boolean removedC1 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c7-partition-round-robin-test",
+            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, 
"c7-partition-round-robin-test",
                     RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC1, true);
 
 
-            removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+            removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
                     autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, true);
 
-            removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+            removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
                     "deployment-policy-partition-round-robin-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, true);
 
-            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-partition-round-robin-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedNet, false);
 
 
-            boolean removeAppPolicy = 
restClientTenant1.removeEntity(RestConstants.APPLICATION_POLICIES,
+            boolean removeAppPolicy = 
restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
                     "application-policy-partition-round-robin-test", 
RestConstants.APPLICATION_POLICIES_NAME);
             assertEquals(removeAppPolicy, true);
 
-            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-partition-round-robin-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedNet, true);
 
@@ -202,35 +203,27 @@ public class PartitionRoundRobinClusterTest extends 
StratosTestServerManager {
      * @param applicationName
      */
     private void assertClusterWithRoundRobinAlgorithm(String applicationName) {
-        Application application = 
ApplicationManager.getApplications().getApplicationByTenant(applicationName, 
tenant1Id);
+        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 serviceUUid = clusterDataHolder.getServiceUuid();
+            String serviceName = clusterDataHolder.getServiceType();
             String clusterId = clusterDataHolder.getClusterId();
-            Service service = 
TopologyManager.getTopology().getService(serviceUUid);
+            Service service = 
TopologyManager.getTopology().getService(serviceName);
             assertNotNull(String.format("Service is not found: 
[application-id] %s [service] %s",
-                    applicationName, serviceUUid), service);
+                    applicationName, serviceName), service);
 
             Cluster cluster = service.getCluster(clusterId);
             assertNotNull(String.format("Cluster is not found: 
[application-id] %s [service] %s [cluster-id] %s",
-                    applicationName, serviceUUid, clusterId), cluster);
+                    applicationName, serviceName, clusterId), cluster);
 
             for (ClusterInstance instance : 
cluster.getInstanceIdToInstanceContextMap().values()) {
                 List<String> partitionsUsedInMembers = new ArrayList<String>();
                 Map<String, List<Long>> partitionIdToMembersMap = new 
HashMap<String, List<Long>>();
-                String p1 = "network-partition-11-partition-1";
-                String p2 = "network-partition-11-partition-2";
                 for (Member member : cluster.getMembers()) {
                     String partitionId = member.getPartitionId();
-                    if(p1.equals("network-partition-11-partition-1")) {
-                        p1 = partitionId;
-                    }
-                    else 
if(!p1.equals(partitionId)&&p2.equals("network-partition-11-partition-2")){
-                        p2 = partitionId;
-                    }
                     if (!partitionIdToMembersMap.containsKey(partitionId)) {
                         List<Long> members = new ArrayList<Long>();
                         members.add(member.getInitTime());
@@ -242,7 +235,8 @@ public class PartitionRoundRobinClusterTest extends 
StratosTestServerManager {
                         partitionsUsedInMembers.add(partitionId);
                     }
                 }
-
+                String p1 = "network-partition-11-partition-1";
+                String p2 = "network-partition-11-partition-2";
                 List<Long> p1InitTime = partitionIdToMembersMap.get(p1);
                 Collections.sort(p1InitTime);
 
@@ -271,7 +265,7 @@ public class PartitionRoundRobinClusterTest extends 
StratosTestServerManager {
                         p2Index++;
                         previousPartition = p2;
                         assertEquals("Partition-2 doesn't not contain correct 
values in current " +
-                                "iteration", 
allInitTime.get(allInitTime.size()-1), p2InitTime.get(p2Index));
+                                "iteration", allInitTime.get(i), 
p2InitTime.get(p2Index));
                         if (p1Index >= 0) {
                             assertEquals("Partition-1 doesn't not contain 
correct values in the " +
                                     "previous iteration", allInitTime.get(i - 
1), p1InitTime.get(p1Index));

http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
index dea1f8a..e50806b 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.stratos.integration.tests.application;
 
+import com.google.gson.reflect.TypeToken;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.beans.application.ApplicationBean;
@@ -29,6 +30,10 @@ import org.apache.stratos.integration.tests.RestConstants;
 import org.apache.stratos.integration.tests.StratosTestServerManager;
 import org.testng.annotations.Test;
 
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
 import static junit.framework.Assert.*;
 
 /**
@@ -44,54 +49,54 @@ public class SampleApplicationsTest extends 
StratosTestServerManager {
         try {
             String autoscalingPolicyId = 
"autoscaling-policy-sample-applications-test";
 
-            boolean addedScalingPolicy = 
restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.AUTOSCALING_POLICIES_PATH
+            boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + 
RestConstants.AUTOSCALING_POLICIES_PATH
                             + "/" + autoscalingPolicyId + ".json",
                     RestConstants.AUTOSCALING_POLICIES, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(addedScalingPolicy, true);
 
-            boolean addedC1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c1-sample-applications-test.json",
+            boolean addedC1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c1-sample-applications-test.json",
                     RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC1, true);
 
-            boolean addedC2 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c2-sample-applications-test.json",
+            boolean addedC2 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c2-sample-applications-test.json",
                     RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC2, true);
 
-            boolean addedC3 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c3-sample-applications-test.json",
+            boolean addedC3 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c3-sample-applications-test.json",
                     RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC3, true);
 
-            boolean addedG1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
+            boolean addedG1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
                             "/" + 
"cartrdige-nested-sample-applications-test.json", 
RestConstants.CARTRIDGE_GROUPS,
                     RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(addedG1, true);
 
-            CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClientTenant1.
+            CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
                     getEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
                             CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(beanG1.getName(), "G1-sample-applications-test");
 
-            boolean addedN1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+            boolean addedN1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
                             
"network-partition-sample-applications-test-1.json",
                     RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(addedN1, true);
 
-            boolean addedN2 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+            boolean addedN2 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
                             
"network-partition-sample-applications-test-2.json",
                     RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(addedN2, true);
 
-            boolean addedDep = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+            boolean addedDep = restClient.addEntity(RESOURCES_PATH + 
RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
                             "deployment-policy-sample-applications-test.json",
                     RestConstants.DEPLOYMENT_POLICIES, 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(addedDep, true);
 
-            boolean added = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
+            boolean added = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
                             "g-sc-G123-1-sample-applications-test.json", 
RestConstants.APPLICATIONS,
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(added, true);
 
-            ApplicationBean bean = (ApplicationBean) 
restClientTenant1.getEntity(RestConstants.APPLICATIONS,
+            ApplicationBean bean = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
                     "g-sc-G123-1-sample-applications-test", 
ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
             assertEquals(bean.getApplicationId(), 
"g-sc-G123-1-sample-applications-test");
 
@@ -129,20 +134,15 @@ public class SampleApplicationsTest extends 
StratosTestServerManager {
             assertEquals(c3.getCartridgeMin(), 1);
             assertEquals(c3.getCartridgeMax(), 2);
 
-            bean = (ApplicationBean) 
restClientTenant2.getEntity(RestConstants.APPLICATIONS,
-                    "g-sc-G123-1-sample-applications-test", 
ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
-
-            assertNull("Application found in tenant 2",bean);
-
-            boolean updated = restClientTenant1.updateEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH +
+            boolean updated = restClient.updateEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH +
                             "/g-sc-G123-1-sample-applications-test-v1.json",
                     RestConstants.APPLICATIONS, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(updated, true);
 
-            ApplicationBean updatedBean = (ApplicationBean) 
restClientTenant1.getEntity(RestConstants.APPLICATIONS,
+            ApplicationBean updatedBean = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
                     "g-sc-G123-1-sample-applications-test", 
ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
 
-            assertEquals(updatedBean.getApplicationId(), 
"g-sc-G123-1-sample-applications-test");
+            assertEquals(bean.getApplicationId(), 
"g-sc-G123-1-sample-applications-test");
 
             group1 = updatedBean.getComponents().getGroups().get(0);
             group2 = group1.getGroups().get(0);
@@ -178,69 +178,226 @@ public class SampleApplicationsTest extends 
StratosTestServerManager {
             assertEquals(c3.getCartridgeMin(), 2);
             assertEquals(c3.getCartridgeMax(), 3);
 
-            updatedBean = (ApplicationBean) 
restClientTenant2.getEntity(RestConstants.APPLICATIONS,
+
+            boolean removedGroup = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertFalse(removedGroup);
+
+            boolean removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertFalse(removedAuto);
+
+            boolean removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-sample-applications-test-1",
+                    RestConstants.NETWORK_PARTITIONS_NAME);
+            //Trying to remove the used network partition
+            assertFalse(removedNet);
+
+            boolean removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-sample-applications-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertFalse(removedDep);
+
+            boolean removed = 
restClient.removeEntity(RestConstants.APPLICATIONS, 
"g-sc-G123-1-sample-applications-test",
+                    RestConstants.APPLICATIONS_NAME);
+            assertTrue(removed);
+
+            ApplicationBean beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
                     "g-sc-G123-1-sample-applications-test", 
ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+            assertNull(beanRemoved);
+
+            removedGroup = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertEquals(removedGroup, true);
+
+            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c1-sample-applications-test",
+                    RestConstants.CARTRIDGES_NAME);
+            assertEquals(removedC1, true);
+
+            boolean removedC2 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c2-sample-applications-test",
+                    RestConstants.CARTRIDGES_NAME);
+            assertEquals(removedC2, true);
+
+            boolean removedC3 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c3-sample-applications-test",
+                    RestConstants.CARTRIDGES_NAME);
+            assertEquals(removedC3, true);
+
+            removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertEquals(removedAuto, true);
+
+            removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-sample-applications-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertEquals(removedDep, true);
+
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-sample-applications-test-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedNet, true);
+
+            boolean removedN2 = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-sample-applications-test-2", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(String.format("[Network partition] 
network-partition-sample-applications-test-2 " +
+                    "could not be removed for [application] 
g-sc-G123-1-sample-applications-test"), removedN2, true);
+
+            log.info("-------------------------------Ended application test 
case-------------------------------");
+
+        } catch (Exception e) {
+            log.error("An error occurred while handling application test 
case", e);
+            assertTrue("An error occurred while handling application test 
case", false);
+        }
+    }
+
+    @Test
+    public void testApplicationList() {
+        log.info("-------------------------------Started application listtest 
case-------------------------------");
+        try {
+            String autoscalingPolicyId = 
"autoscaling-policy-sample-applications-test";
+
+            boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + 
RestConstants.AUTOSCALING_POLICIES_PATH
+                            + "/" + autoscalingPolicyId + ".json",
+                    RestConstants.AUTOSCALING_POLICIES, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertEquals(addedScalingPolicy, true);
+
+            boolean addedC1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c1-sample-applications-test.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(addedC1, true);
+
+            boolean addedC2 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c2-sample-applications-test.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(addedC2, true);
+
+            boolean addedC3 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c3-sample-applications-test.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(addedC3, true);
+
+            boolean addedG1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
+                            "/" + 
"cartrdige-nested-sample-applications-test.json", 
RestConstants.CARTRIDGE_GROUPS,
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertEquals(addedG1, true);
+
+            CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
+                    getEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
+                            CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertEquals(beanG1.getName(), "G1-sample-applications-test");
+
+            boolean addedN1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            
"network-partition-sample-applications-test-1.json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(addedN1, true);
+
+            boolean addedN2 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            
"network-partition-sample-applications-test-2.json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(addedN2, true);
 
-            assertNull("Application found in tenant 2",updatedBean);
+            boolean addedDep = restClient.addEntity(RESOURCES_PATH + 
RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+                            "deployment-policy-sample-applications-test.json",
+                    RestConstants.DEPLOYMENT_POLICIES, 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertEquals(addedDep, true);
 
-            boolean removedGroup = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
+            String app1 = "sample-applications-test-1";
+            String app2 = "sample-applications-test-2";
+            boolean added = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
+                            app1 + ".json", RestConstants.APPLICATIONS,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(added, true);
+
+            added = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
+                            app2 + ".json", RestConstants.APPLICATIONS,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(added, true);
+
+            Type listType = new TypeToken<ArrayList<ApplicationBean>>() {
+            }.getType();
+
+            List<ApplicationBean> applicationList = (List<ApplicationBean>) 
restClient.
+                    listEntity(RestConstants.APPLICATIONS,
+                            listType, RestConstants.APPLICATIONS_NAME);
+            assertTrue(applicationList.size() >= 2);
+
+
+            ApplicationBean bean1 = null;
+            for (ApplicationBean applicationBean : applicationList) {
+                if (applicationBean.getApplicationId().equals(app1)) {
+                    bean1 = applicationBean;
+                }
+            }
+            assertNotNull(bean1);
+
+            ApplicationBean bean2 = null;
+            for (ApplicationBean applicationBean : applicationList) {
+                if (applicationBean.getApplicationId().equals(app2)) {
+                    bean2 = applicationBean;
+                }
+            }
+            assertNotNull(bean2);
+
+
+            boolean removed = 
restClient.removeEntity(RestConstants.APPLICATIONS, app1,
+                    RestConstants.APPLICATIONS_NAME);
+            assertTrue(removed);
+
+            ApplicationBean beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    app1, ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
+            assertNull(beanRemoved);
+
+            boolean removedGroup = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
             assertFalse(removedGroup);
 
-            boolean removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+            boolean removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
                     autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertFalse(removedAuto);
 
-            boolean removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            boolean removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-sample-applications-test-1",
                     RestConstants.NETWORK_PARTITIONS_NAME);
             //Trying to remove the used network partition
             assertFalse(removedNet);
 
-            boolean removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+            boolean removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
                     "deployment-policy-sample-applications-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertFalse(removedDep);
 
-            boolean removed = 
restClientTenant1.removeEntity(RestConstants.APPLICATIONS, 
"g-sc-G123-1-sample-applications-test",
+            removed = restClient.removeEntity(RestConstants.APPLICATIONS, app2,
                     RestConstants.APPLICATIONS_NAME);
             assertTrue(removed);
 
-            ApplicationBean beanRemoved = (ApplicationBean) 
restClientTenant1.getEntity(RestConstants.APPLICATIONS,
-                    "g-sc-G123-1-sample-applications-test", 
ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
-            assertEquals(beanRemoved, null);
+            beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    app2, ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
+            assertNull(beanRemoved);
 
-            removedGroup = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
+            removedGroup = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(removedGroup, true);
 
-            boolean removedC1 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c1-sample-applications-test",
+            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c1-sample-applications-test",
                     RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC1, true);
 
-            boolean removedC2 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c2-sample-applications-test",
+            boolean removedC2 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c2-sample-applications-test",
                     RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC2, true);
 
-            boolean removedC3 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c3-sample-applications-test",
+            boolean removedC3 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c3-sample-applications-test",
                     RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC3, true);
 
-            removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+            removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
                     autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, true);
 
-            removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+            removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
                     "deployment-policy-sample-applications-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, true);
 
-            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-sample-applications-test-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedNet, true);
 
-            boolean removedN2 = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            boolean removedN2 = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-sample-applications-test-2", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(String.format("[Network partition] 
network-partition-sample-applications-test-2 " +
-                    "could not be removed for [application] 
g-sc-G123-1-sample-applications-test"),removedN2, true);
+                    "could not be removed for [application] 
g-sc-G123-1-sample-applications-test"), removedN2, true);
 
             log.info("-------------------------------Ended application test 
case-------------------------------");
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
index 5f40baf..1d4c4ab 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
@@ -48,49 +48,51 @@ public class SingleClusterScalingTest extends 
StratosTestServerManager {
     private static final Log log = 
LogFactory.getLog(SampleApplicationsTest.class);
     private static final String RESOURCES_PATH = 
"/single-cluster-scaling-test";
     private static final int CLUSTER_SCALE_UP_TIMEOUT = 180000;
+    private static final int CLUSTER_SCALE_DOWN_TIMEOUT = 360000;
+    private int activeInstancesAfterScaleup = 0;
 
 
     @Test
     public void testDeployApplication() {
         try {
             log.info("-------------------------------Started application 
Bursting test case-------------------------------");
-
+            TopologyHandler topologyHandler = TopologyHandler.getInstance();
             String autoscalingPolicyId = 
"autoscaling-policy-single-cluster-scaling-test";
 
-            boolean addedScalingPolicy = 
restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.AUTOSCALING_POLICIES_PATH
+            boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + 
RestConstants.AUTOSCALING_POLICIES_PATH
                             + "/" + autoscalingPolicyId + ".json",
                     RestConstants.AUTOSCALING_POLICIES, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(addedScalingPolicy, true);
 
-            boolean addedC1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c7-single-cluster-scaling-test.json",
+            boolean addedC1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" + "c7-single-cluster-scaling-test.json",
                     RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
             assertEquals(addedC1, true);
 
-            boolean addedN1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+            boolean addedN1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
                             
"network-partition-single-cluster-scaling-test.json",
                     RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(addedN1, true);
 
-            boolean addedDep = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+            boolean addedDep = restClient.addEntity(RESOURCES_PATH + 
RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
                             
"deployment-policy-single-cluster-scaling-test.json",
                     RestConstants.DEPLOYMENT_POLICIES, 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(addedDep, true);
 
-            boolean added = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
+            boolean added = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
                             "single-cluster-scaling-test.json", 
RestConstants.APPLICATIONS,
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(added, true);
 
-            ApplicationBean bean = (ApplicationBean) 
restClientTenant1.getEntity(RestConstants.APPLICATIONS,
+            ApplicationBean bean = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
                     "single-cluster-scaling-test", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(bean.getApplicationId(), 
"single-cluster-scaling-test");
 
-            boolean addAppPolicy = restClientTenant1.addEntity(RESOURCES_PATH 
+ RestConstants.APPLICATION_POLICIES_PATH + "/" +
+            boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATION_POLICIES_PATH + "/" +
                             
"application-policy-single-cluster-scaling-test.json", 
RestConstants.APPLICATION_POLICIES,
                     RestConstants.APPLICATION_POLICIES_NAME);
             assertEquals(addAppPolicy, true);
 
-            ApplicationPolicyBean policyBean = (ApplicationPolicyBean) 
restClientTenant1.getEntity(
+            ApplicationPolicyBean policyBean = (ApplicationPolicyBean) 
restClient.getEntity(
                     RestConstants.APPLICATION_POLICIES,
                     "application-policy-single-cluster-scaling-test", 
ApplicationPolicyBean.class,
                     RestConstants.APPLICATION_POLICIES_NAME);
@@ -98,31 +100,37 @@ public class SingleClusterScalingTest extends 
StratosTestServerManager {
             //deploy the application
             String resourcePath = RestConstants.APPLICATIONS + "/" + 
"single-cluster-scaling-test" +
                     RestConstants.APPLICATIONS_DEPLOY + "/" + 
"application-policy-single-cluster-scaling-test";
-            boolean deployed = restClientTenant1.deployEntity(resourcePath,
+            boolean deployed = restClient.deployEntity(resourcePath,
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(deployed, true);
 
             //Application active handling
-            
TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId()
-                    , ApplicationStatus.Active, tenant1Id);
+            topologyHandler.assertApplicationStatus(bean.getApplicationId()
+                    , ApplicationStatus.Active);
 
             //Cluster active handling
-            
TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(), 
tenant1Id);
+            topologyHandler.assertClusterActivation(bean.getApplicationId());
 
             //Verifying whether members got created using round robin algorithm
-            assertClusterWithScalingup(bean.getApplicationId(), tenant1Id);
+            assertClusterWithScalingup(bean.getApplicationId());
+
+            //assert scale-down
+            assertClusterWithScaleDown(bean.getApplicationId());
+
+            //Check whether cluster could scale-down upto the minimum
+            assertClusterScaleDownToMinimumCount(bean.getApplicationId());
 
-            boolean removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+            boolean removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
                     autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, false);
 
-            boolean removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            boolean removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-single-cluster-scaling-test",
                     RestConstants.NETWORK_PARTITIONS_NAME);
             //Trying to remove the used network partition
             assertEquals(removedNet, false);
 
-            boolean removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+            boolean removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
                     "deployment-policy-single-cluster-scaling-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, false);
 
@@ -130,55 +138,55 @@ public class SingleClusterScalingTest extends 
StratosTestServerManager {
             String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + 
"single-cluster-scaling-test" +
                     RestConstants.APPLICATIONS_UNDEPLOY;
 
-            boolean unDeployed = 
restClientTenant1.undeployEntity(resourcePathUndeploy,
+            boolean unDeployed = 
restClient.undeployEntity(resourcePathUndeploy,
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(unDeployed, true);
 
-            boolean undeploy = 
TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test",
 tenant1Id);
+            boolean undeploy = 
topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
             if (!undeploy) {
                 //Need to forcefully undeploy the application
                 log.info("Force undeployment is going to start for the 
[application] " + "single-cluster-scaling-test");
 
-                restClientTenant1.undeployEntity(RestConstants.APPLICATIONS + 
"/" + "single-cluster-scaling-test" +
+                restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + 
"single-cluster-scaling-test" +
                         RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", 
RestConstants.APPLICATIONS);
 
-                boolean forceUndeployed = 
TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test",
 tenant1Id);
+                boolean forceUndeployed = 
topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
                 assertEquals(String.format("Forceful undeployment failed for 
the application %s",
                         "single-cluster-scaling-test"), forceUndeployed, true);
 
             }
 
-            boolean removed = 
restClientTenant1.removeEntity(RestConstants.APPLICATIONS, 
"single-cluster-scaling-test",
+            boolean removed = 
restClient.removeEntity(RestConstants.APPLICATIONS, 
"single-cluster-scaling-test",
                     RestConstants.APPLICATIONS_NAME);
             assertEquals(removed, true);
 
-            ApplicationBean beanRemoved = (ApplicationBean) 
restClientTenant1.getEntity(RestConstants.APPLICATIONS,
+            ApplicationBean beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
                     "single-cluster-scaling-test", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
             assertEquals(beanRemoved, null);
 
-            boolean removedC1 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c7-single-cluster-scaling-test",
+            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, 
"c7-single-cluster-scaling-test",
                     RestConstants.CARTRIDGES_NAME);
             assertEquals(removedC1, true);
 
 
-            removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+            removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
                     autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
             assertEquals(removedAuto, true);
 
-            removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+            removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
                     "deployment-policy-single-cluster-scaling-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
             assertEquals(removedDep, true);
 
-            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-single-cluster-scaling-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedNet, false);
 
 
-            boolean removeAppPolicy = 
restClientTenant1.removeEntity(RestConstants.APPLICATION_POLICIES,
+            boolean removeAppPolicy = 
restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
                     "application-policy-single-cluster-scaling-test", 
RestConstants.APPLICATION_POLICIES_NAME);
             assertEquals(removeAppPolicy, true);
 
-            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
                     "network-partition-single-cluster-scaling-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
             assertEquals(removedNet, true);
 
@@ -194,10 +202,9 @@ public class SingleClusterScalingTest extends 
StratosTestServerManager {
      * Assert application activation
      *
      * @param applicationName
-     * @param tenantId
      */
-    private void assertClusterWithScalingup(String applicationName, int 
tenantId) {
-        Application application = 
ApplicationManager.getApplications().getApplicationByTenant(applicationName, 
tenantId);
+    private void assertClusterWithScalingup(String applicationName) {
+        Application application = 
ApplicationManager.getApplications().getApplication(applicationName);
         assertNotNull(String.format("Application is not found: 
[application-id] %s",
                 applicationName), application);
         boolean clusterScaleup = false;
@@ -210,15 +217,15 @@ public class SingleClusterScalingTest extends 
StratosTestServerManager {
             }
             Set<ClusterDataHolder> clusterDataHolderSet = 
application.getClusterDataRecursively();
             for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
-                String serviceUuid = clusterDataHolder.getServiceUuid();
+                String serviceName = clusterDataHolder.getServiceType();
                 clusterId = clusterDataHolder.getClusterId();
-                Service service = 
TopologyManager.getTopology().getService(serviceUuid);
+                Service service = 
TopologyManager.getTopology().getService(serviceName);
                 assertNotNull(String.format("Service is not found: 
[application-id] %s [service] %s",
-                        applicationName, serviceUuid), service);
+                        applicationName, serviceName), service);
 
                 Cluster cluster = service.getCluster(clusterId);
                 assertNotNull(String.format("Cluster is not found: 
[application-id] %s [service] %s [cluster-id] %s",
-                        applicationName, serviceUuid, clusterId), cluster);
+                        applicationName, serviceName, clusterId), cluster);
                 for (ClusterInstance instance : 
cluster.getInstanceIdToInstanceContextMap().values()) {
                     int activeInstances = 0;
                     for (Member member : cluster.getMembers()) {
@@ -228,12 +235,14 @@ public class SingleClusterScalingTest extends 
StratosTestServerManager {
                             }
                         }
                     }
-                    clusterScaleup = activeInstances >= 
clusterDataHolder.getMinInstances();
+
+                    clusterScaleup = activeInstances > 
clusterDataHolder.getMinInstances();
                     if(clusterScaleup) {
+                        activeInstancesAfterScaleup = activeInstances;
                         break;
                     }
                 }
-                application = 
ApplicationManager.getApplications().getApplicationByTenant(applicationName, 
tenantId);
+                application = 
ApplicationManager.getApplications().getApplication(applicationName);
                 if ((System.currentTimeMillis() - startTime) > 
CLUSTER_SCALE_UP_TIMEOUT) {
                     break;
                 }
@@ -242,4 +251,115 @@ public class SingleClusterScalingTest extends 
StratosTestServerManager {
         assertEquals(String.format("Cluster did not get scaled up: 
[cluster-id] %s", clusterId),
                 clusterScaleup, true);
     }
+
+    /**
+     * Assert application activation
+     *
+     * @param applicationName
+     */
+    private void assertClusterWithScaleDown(String applicationName) {
+        Application application = 
ApplicationManager.getApplications().getApplication(applicationName);
+        assertNotNull(String.format("Application is not found: 
[application-id] %s",
+                applicationName), application);
+        boolean clusterScaleDown = false;
+        String clusterId = null;
+        long startTime = System.currentTimeMillis();
+        while (!clusterScaleDown) {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException ignore) {
+            }
+            Set<ClusterDataHolder> clusterDataHolderSet = 
application.getClusterDataRecursively();
+            for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
+                String serviceName = clusterDataHolder.getServiceType();
+                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);
+                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++;
+                            }
+                        }
+                    }
+
+                    if(activeInstances > activeInstancesAfterScaleup) {
+                        activeInstancesAfterScaleup = activeInstances;
+                    }
+
+                    clusterScaleDown = activeInstancesAfterScaleup - 1 == 
activeInstances;
+                    if(clusterScaleDown) {
+                        break;
+                    }
+
+                }
+
+                application = 
ApplicationManager.getApplications().getApplication(applicationName);
+                if ((System.currentTimeMillis() - startTime) > 
CLUSTER_SCALE_DOWN_TIMEOUT) {
+                    break;
+                }
+            }
+        }
+        assertEquals(String.format("Cluster did not get scaled up: 
[cluster-id] %s", clusterId),
+                clusterScaleDown, true);
+    }
+
+    /**
+     * Assert application activation
+     *
+     * @param applicationName
+     */
+    private void assertClusterScaleDownToMinimumCount(String applicationName) {
+        Application application = 
ApplicationManager.getApplications().getApplication(applicationName);
+        assertNotNull(String.format("Application is not found: 
[application-id] %s",
+                applicationName), application);
+        boolean clusterScaleDown = false;
+        String clusterId = null;
+        long startTime = System.currentTimeMillis();
+        while (!clusterScaleDown) {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException ignore) {
+            }
+            Set<ClusterDataHolder> clusterDataHolderSet = 
application.getClusterDataRecursively();
+            for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
+                String serviceName = clusterDataHolder.getServiceType();
+                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);
+                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++;
+                            }
+                        }
+                    }
+                    clusterScaleDown = activeInstances == 
clusterDataHolder.getMinInstances();
+                    if(clusterScaleDown) {
+                        break;
+                    }
+                }
+                application = 
ApplicationManager.getApplications().getApplication(applicationName);
+                if ((System.currentTimeMillis() - startTime) > 
CLUSTER_SCALE_DOWN_TIMEOUT) {
+                    break;
+                }
+            }
+        }
+        assertEquals(String.format("Cluster did not get scaled up: 
[cluster-id] %s", clusterId),
+                clusterScaleDown, true);
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
index 9b6eefe..67c71a4 100644
--- 
a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
+++ 
b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.stratos.integration.tests.group;
 
+import com.google.gson.reflect.TypeToken;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
@@ -26,9 +27,11 @@ import org.apache.stratos.integration.tests.RestConstants;
 import org.apache.stratos.integration.tests.StratosTestServerManager;
 import org.testng.annotations.Test;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import static junit.framework.Assert.*;
 
 /**
  * Test to handle Cartridge group CRUD operations
@@ -42,109 +45,222 @@ public class CartridgeGroupTest extends 
StratosTestServerManager {
         try {
             log.info("-------------------------Started Cartridge group test 
case-------------------------");
 
-            boolean addedC1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
+            boolean addedC1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
                             "/" + "c4-cartridge-group-test.json",
                     RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-            assertEquals(String.format("Cartridge did not added: 
[cartridge-name] %s",
-                    "c4-cartridge-group-test"), addedC1, true);
+            assertTrue(String.format("Cartridge did not added: 
[cartridge-name] %s",
+                    "c4-cartridge-group-test"), addedC1);
 
-            boolean addedC2 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
+            boolean addedC2 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
                             "/" + "c5-cartridge-group-test.json",
                     RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-            assertEquals(String.format("Cartridge did not added: 
[cartridge-name] %s",
-                    "c5-cartridge-group-test"), addedC2, true);
+            assertTrue(String.format("Cartridge did not added: 
[cartridge-name] %s",
+                    "c5-cartridge-group-test"), addedC2);
 
-            boolean addedC3 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
+            boolean addedC3 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
                             "/" + "c6-cartridge-group-test.json",
                     RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-            assertEquals(String.format("Cartridge did not added: 
[cartridge-name] %s",
-                    "c6-cartridge-group-test"), addedC3, true);
+            assertTrue(String.format("Cartridge did not added: 
[cartridge-name] %s",
+                    "c6-cartridge-group-test"), addedC3);
 
-            boolean added = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
+            boolean added = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
                             "/" + "g4-g5-g6-cartridge-group-test.json", 
RestConstants.CARTRIDGE_GROUPS,
                     RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge Group did not added: 
[cartridge-group-name] %s",
-                    "g4-g5-g6-cartridge-group-test"), added, true);
+            assertTrue(String.format("Cartridge Group did not added: 
[cartridge-group-name] %s",
+                    "g4-g5-g6-cartridge-group-test"), added);
 
-            CartridgeGroupBean bean = (CartridgeGroupBean) restClientTenant1.
+            CartridgeGroupBean bean = (CartridgeGroupBean) restClient.
                     getEntity(RestConstants.CARTRIDGE_GROUPS, 
"G4-cartridge-group-test",
                             CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(String.format("Cartridge Group name did not match: 
[cartridge-group-name] %s",
                     "g4-g5-g6-cartridge-group-test.json"), bean.getName(), 
"G4-cartridge-group-test");
 
-            CartridgeGroupBean tenant2Bean = (CartridgeGroupBean) 
restClientTenant2.
-                    getEntity(RestConstants.CARTRIDGE_GROUPS, 
"G4-cartridge-group-test",
-                            CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertNull(String.format("Cartridge Group name fouund in tenant 2: 
[cartridge-group-name] %s",
-                    bean.getName()),tenant2Bean);
-
-            boolean updated = restClientTenant1.updateEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
+            boolean updated = restClient.updateEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
                             "/" + "g4-g5-g6-cartridge-group-test-v1.json",
                     RestConstants.CARTRIDGE_GROUPS, 
RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge Group did not updated: 
[cartridge-group-name] %s",
-                    "g4-g5-g6-cartridge-group-test"), updated, true);
+            assertTrue(String.format("Cartridge Group did not updated: 
[cartridge-group-name] %s",
+                    "g4-g5-g6-cartridge-group-test"), updated);
 
-            CartridgeGroupBean updatedBean = (CartridgeGroupBean) 
restClientTenant1.
+            CartridgeGroupBean updatedBean = (CartridgeGroupBean) restClient.
                     getEntity(RestConstants.CARTRIDGE_GROUPS, 
"G4-cartridge-group-test",
                             CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(String.format("Updated Cartridge Group didn't match: 
[cartridge-group-name] %s",
                     "g4-g5-g6-cartridge-group-test"), updatedBean.getName(), 
"G4-cartridge-group-test");
 
-            updatedBean = (CartridgeGroupBean) restClientTenant2.
-                    getEntity(RestConstants.CARTRIDGE_GROUPS, 
"G4-cartridge-group-test",
-                            CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertNull(String.format("Updated Cartridge Group found in other 
tenant: [cartridge-group-name] %s",
-                    "g4-g5-g6-cartridge-group-test"), updatedBean);
-
-            boolean removedC1 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c4-cartridge-group-test",
+            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge can be removed while it is 
used in " +
-                    "cartridge group: [cartridge-name] %s", 
"c4-cartridge-group-test"), removedC1, false);
+            assertFalse(String.format("Cartridge can be removed while it is 
used in " +
+                    "cartridge group: [cartridge-name] %s", 
"c4-cartridge-group-test"), removedC1);
 
-            boolean removedC2 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c5-cartridge-group-test",
+            boolean removedC2 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge can be removed while it is 
used in " +
+            assertFalse(String.format("Cartridge can be removed while it is 
used in " +
                             "cartridge group: [cartridge-name] %s",
-                    "c5-cartridge-group-test"), removedC2, false);
+                    "c5-cartridge-group-test"), removedC2);
 
-            boolean removedC3 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c6-cartridge-group-test",
+            boolean removedC3 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge can be removed while it is 
used in " +
+            assertFalse(String.format("Cartridge can be removed while it is 
used in " +
                             "cartridge group: [cartridge-name] %s",
-                    "c6-cartridge-group-test"), removedC3, false);
+                    "c6-cartridge-group-test"), removedC3);
 
-            boolean removed = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G4-cartridge-group-test",
+            boolean removed = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G4-cartridge-group-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge Group did not removed: 
[cartridge-group-name] %s",
-                    "g4-g5-g6-cartridge-group-test"), removed, true);
+            assertTrue(String.format("Cartridge Group did not removed: 
[cartridge-group-name] %s",
+                    "g4-g5-g6-cartridge-group-test"), removed);
 
-            CartridgeGroupBean beanRemoved = (CartridgeGroupBean) 
restClientTenant1.
+            CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient.
                     getEntity(RestConstants.CARTRIDGE_GROUPS, 
"G4-cartridge-group-test",
                             CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
             assertEquals(String.format("Cartridge Group did not removed 
completely: " +
                             "[cartridge-group-name] %s",
                     "g4-g5-g6-cartridge-group-test"), beanRemoved, null);
 
-            removedC1 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c4-cartridge-group-test",
+            removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, 
"c4-cartridge-group-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
-                    "c4-cartridge-group-test"), removedC1, true);
+            assertTrue(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
+                    "c4-cartridge-group-test"), removedC1);
 
-            removedC2 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c5-cartridge-group-test",
+            removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, 
"c5-cartridge-group-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
-                    "c5-cartridge-group-test"), removedC2, true);
+            assertTrue(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
+                    "c5-cartridge-group-test"), removedC2);
 
-            removedC3 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c6-cartridge-group-test",
+            removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, 
"c6-cartridge-group-test",
                     RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
-                    "c6-cartridge-group-test"), removedC3, true);
+            assertTrue(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
+                    "c6-cartridge-group-test"), removedC3);
 
             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);
+            assertFalse("An error occurred while handling Cartridge group test 
case", false);
+        }
+    }
+
+    @Test
+    public void testCartridgeGroupList() {
+        try {
+            log.info("-------------------------Started Cartridge group list 
test case-------------------------");
+
+            boolean addedC1 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
+                            "/" + "c4-cartridge-group-test.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertTrue(String.format("Cartridge did not added: 
[cartridge-name] %s",
+                    "c4-cartridge-group-test"), addedC1);
+
+            boolean addedC2 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
+                            "/" + "c5-cartridge-group-test.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertTrue(String.format("Cartridge did not added: 
[cartridge-name] %s",
+                    "c5-cartridge-group-test"), addedC2);
+
+            boolean addedC3 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH +
+                            "/" + "c6-cartridge-group-test.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertTrue(String.format("Cartridge did not added: 
[cartridge-name] %s",
+                    "c6-cartridge-group-test"), addedC3);
+
+            String group1 = "group-1-cartridge-group-test";
+            String group2 = "group-2-cartridge-group-test";
+
+            boolean added = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
+                            "/" + group1 + ".json", 
RestConstants.CARTRIDGE_GROUPS,
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertTrue(String.format("Cartridge Group did not added: 
[cartridge-group-name] %s",
+                    group1), added);
+
+            added = restClient.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGE_GROUPS_PATH +
+                            "/" + group2 + ".json", 
RestConstants.CARTRIDGE_GROUPS,
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertTrue(String.format("Cartridge Group did not added: 
[cartridge-group-name] %s",
+                    group1), added);
+
+            Type listType = new TypeToken<ArrayList<CartridgeGroupBean>>() {
+            }.getType();
+
+            List<CartridgeGroupBean> cartridgeGroupList = 
(List<CartridgeGroupBean>) restClient.
+                    listEntity(RestConstants.CARTRIDGE_GROUPS,
+                            listType, RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertTrue(cartridgeGroupList.size() >= 2);
+
+            CartridgeGroupBean bean1 = null;
+            for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) {
+                if (cartridgeGroupBean.getName().equals(group1)) {
+                    bean1 = cartridgeGroupBean;
+                }
+            }
+            assertNotNull(bean1);
+
+            CartridgeGroupBean bean2 = null;
+            for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) {
+                if (cartridgeGroupBean.getName().equals(group2)) {
+                    bean2 = cartridgeGroupBean;
+                }
+            }
+            assertNotNull(bean2);
+
+            boolean removed = 
restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, group1,
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertTrue(String.format("Cartridge Group did not removed: 
[cartridge-group-name] %s",
+                    group1), removed);
+
+            CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient.
+                    getEntity(RestConstants.CARTRIDGE_GROUPS, group1,
+                            CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertNull(String.format("Cartridge Group did not removed 
completely: " +
+                            "[cartridge-group-name] %s",
+                    group1), beanRemoved);
+
+            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertFalse(String.format("Cartridge can be removed while it is 
used in " +
+                    "cartridge group: [cartridge-name] %s", 
"c4-cartridge-group-test"), removedC1);
+
+            boolean removedC2 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertFalse(String.format("Cartridge can be removed while it is 
used in " +
+                            "cartridge group: [cartridge-name] %s",
+                    "c5-cartridge-group-test"), removedC2);
+
+            boolean removedC3 = 
restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertFalse(String.format("Cartridge can be removed while it is 
used in " +
+                            "cartridge group: [cartridge-name] %s",
+                    "c6-cartridge-group-test"), removedC3);
+
+            removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
group2,
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertTrue(String.format("Cartridge Group did not removed: 
[cartridge-group-name] %s",
+                    group2), removed);
+
+            beanRemoved = (CartridgeGroupBean) restClient.
+                    getEntity(RestConstants.CARTRIDGE_GROUPS, group2,
+                            CartridgeGroupBean.class, 
RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertNull(String.format("Cartridge Group did not removed 
completely: " +
+                            "[cartridge-group-name] %s",
+                    group2), beanRemoved);
+
+            removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, 
"c4-cartridge-group-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertTrue(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
+                    "c4-cartridge-group-test"), removedC1);
+
+            removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, 
"c5-cartridge-group-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertTrue(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
+                    "c5-cartridge-group-test"), removedC2);
+
+            removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, 
"c6-cartridge-group-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertTrue(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
+                    "c6-cartridge-group-test"), removedC3);
+
+            log.info("-------------------------Ended Cartridge group list test 
case-------------------------");
+        } catch (Exception e) {
+            log.error("An error occurred while handling Cartridge list group 
test case", e);
+            assertFalse("An error occurred while handling Cartridge list group 
test case", false);
         }
     }
 }

Reply via email to