http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
new file mode 100644
index 0000000..5b07fc7
--- /dev/null
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTest.java
@@ -0,0 +1,312 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.integration.tests.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.integration.common.RestConstants;
+import org.apache.stratos.integration.common.TopologyHandler;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.apache.stratos.messaging.domain.application.Application;
+import org.apache.stratos.messaging.domain.application.ApplicationStatus;
+import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
+import org.apache.stratos.messaging.domain.instance.ClusterInstance;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.Member;
+import org.apache.stratos.messaging.domain.topology.Service;
+import 
org.apache.stratos.messaging.message.receiver.application.ApplicationManager;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+import org.testng.annotations.Test;
+
+import java.util.*;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+/**
+ * This will handle the scale-up and scale-down of a particular cluster 
bursting test cases
+ */
+public class PartitionRoundRobinClusterTest extends StratosIntegrationTest {
+    private static final Log log = 
LogFactory.getLog(SampleApplicationsTest.class);
+    private static final String RESOURCES_PATH = 
"/partition-round-robin-cluster-test";
+
+    @Test(timeOut = APPLICATION_TEST_TIMEOUT)
+    public void testDeployApplication() {
+        try {
+            log.info("----------------------Started application Bursting test 
case-------------------------");
+
+            String autoscalingPolicyId = 
"autoscaling-policy-partition-round-robin-test";
+
+            boolean addedScalingPolicy =
+                    restClientTenant1.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",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(addedC1, true);
+
+            boolean addedN1 = restClientTenant1.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 + "/" +
+                                    
"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 + "/" +
+                            "partition-round-robin-test.json", 
RestConstants.APPLICATIONS,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(added, true);
+
+            ApplicationBean bean = (ApplicationBean) 
restClientTenant1.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 + "/" +
+                                    
"application-policy-partition-round-robin-test.json",
+                            RestConstants.APPLICATION_POLICIES,
+                            RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(addAppPolicy, true);
+
+            //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,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(deployed, true);
+
+
+            //Application active handling
+            
TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+                    ApplicationStatus.Active, tenant1Id);
+
+            //Cluster active handling
+            
TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(), 
tenant1Id);
+
+            //Verifying whether members got created using round robin algorithm
+           /* 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);       */
+
+            //Application active handling after application becomes active 
again
+            
TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+                    ApplicationStatus.Active, tenant1Id);
+
+            //Cluster active handling
+            
TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(), 
tenant1Id);
+
+            boolean removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertEquals(removedAuto, false);
+
+            boolean removedNet = 
restClientTenant1.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,
+                    "deployment-policy-partition-round-robin-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertEquals(removedDep, false);
+
+            //Un-deploying the application
+            String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + 
"partition-round-robin-test" +
+                    RestConstants.APPLICATIONS_UNDEPLOY;
+
+            boolean unDeployed = 
restClientTenant1.undeployEntity(resourcePathUndeploy,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(unDeployed, true);
+
+            boolean undeploy =
+                    
TopologyHandler.getInstance().assertApplicationUndeploy("partition-round-robin-test",
 tenant1Id);
+            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" +
+                        RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", 
RestConstants.APPLICATIONS);
+
+                boolean forceUndeployed = TopologyHandler.getInstance()
+                        
.assertApplicationUndeploy("partition-round-robin-test", tenant1Id);
+                assertEquals(forceUndeployed, true, String.format("Forceful 
undeployment failed for the application %s",
+                        "partition-round-robin-test"));
+
+            }
+
+            boolean removed = 
restClientTenant1.removeEntity(RestConstants.APPLICATIONS, 
"partition-round-robin-test",
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(removed, true);
+
+            ApplicationBean beanRemoved = (ApplicationBean) 
restClientTenant1.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",
+                            RestConstants.CARTRIDGES_NAME);
+            assertEquals(removedC1, true);
+
+
+            removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertEquals(removedAuto, true);
+
+            removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-partition-round-robin-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertEquals(removedDep, true);
+
+            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-partition-round-robin-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedNet, false);
+
+
+            boolean removeAppPolicy = 
restClientTenant1.removeEntity(RestConstants.APPLICATION_POLICIES,
+                    "application-policy-partition-round-robin-test", 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(removeAppPolicy, true);
+
+            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-partition-round-robin-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedNet, true);
+
+            log.info("--------------------Ended application bursting test 
case---------------------------");
+
+        }
+        catch (Exception e) {
+            log.error("An error occurred while handling  application 
bursting", e);
+            assertTrue("An error occurred while handling  application 
bursting", false);
+        }
+    }
+
+    /**
+     * Assert application activation
+     *
+     * @param applicationName
+     */
+    private void assertClusterWithRoundRobinAlgorithm(String applicationName) {
+        Application application =
+                
ApplicationManager.getApplications().getApplicationByTenant(applicationName, 
tenant1Id);
+        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 clusterId = clusterDataHolder.getClusterId();
+            Service service = 
TopologyManager.getTopology().getService(serviceUUid);
+            assertNotNull(String.format("Service is not found: 
[application-id] %s [service] %s",
+                    applicationName, serviceUUid), 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);
+
+            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());
+                        partitionIdToMembersMap.put(partitionId, members);
+                    } else {
+                        
partitionIdToMembersMap.get(partitionId).add(member.getInitTime());
+                    }
+                    if (!partitionsUsedInMembers.contains(partitionId)) {
+                        partitionsUsedInMembers.add(partitionId);
+                    }
+                }
+
+                List<Long> p1InitTime = partitionIdToMembersMap.get(p1);
+                Collections.sort(p1InitTime);
+
+                List<Long> p2InitTime = partitionIdToMembersMap.get(p2);
+                Collections.sort(p2InitTime);
+
+                List<Long> allInitTime = new ArrayList<Long>();
+                allInitTime.addAll(p1InitTime);
+                allInitTime.addAll(p2InitTime);
+                Collections.sort(allInitTime);
+
+                int p1Index = -1;
+                int p2Index = -1;
+                String previousPartition = null;
+                for (int i = 0; i < allInitTime.size(); i++) {
+                    if (previousPartition == null) {
+                        if (p1InitTime.get(0) == allInitTime.get(i)) {
+                            previousPartition = p1;
+                            p1Index++;
+                        } else if (p2InitTime.get(0) == allInitTime.get(i)) {
+                            previousPartition = p2;
+                            p2Index++;
+
+                        }
+                    } else if (previousPartition.equals(p1)) {
+                        p2Index++;
+                        previousPartition = p2;
+                        assertEquals(allInitTime.get(allInitTime.size() - 1), 
p2InitTime.get(p2Index),
+                                "Partition-2 doesn't not contain correct 
values in current iteration");
+                        if (p1Index >= 0) {
+                            assertEquals(allInitTime.get(i - 1), 
p1InitTime.get(p1Index),
+                                    "Partition-1 doesn't not contain correct 
values in the previous iteration");
+                            if (p1Index + 1 <= (p1InitTime.size() - 1) && i + 
1 <= (allInitTime.size() - 1)) {
+                                assertEquals(allInitTime.get(i + 1), 
p1InitTime.get(p1Index + 1),
+                                        "Partition-1 doesn't not contain 
correct values in the next iteration");
+
+                            }
+                        }
+                    } else {
+                        p1Index++;
+                        previousPartition = p1;
+                        assertEquals(allInitTime.get(i), 
p1InitTime.get(p1Index),
+                                "Partition-1 doesn't not contain correct 
values in current iteration");
+                        if (p2Index >= 0) {
+                            assertEquals(allInitTime.get(i - 1), 
p2InitTime.get(p2Index),
+                                    "Partition-2 doesn't not contain correct 
values in the previous iteration");
+                            if ((p2Index + 1) <= (p2InitTime.size() - 1) && (i 
+ 1) <= (allInitTime.size() - 1)) {
+                                assertEquals(allInitTime.get(i + 1), 
p2InitTime.get(p2Index + 1),
+                                        "Partition-2 doesn't not contain 
correct values in the next iteration");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
new file mode 100644
index 0000000..064da7f
--- /dev/null
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.integration.tests.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.cartridge.CartridgeGroupBean;
+import org.apache.stratos.common.beans.cartridge.CartridgeGroupReferenceBean;
+import org.apache.stratos.common.beans.cartridge.CartridgeReferenceBean;
+import org.apache.stratos.integration.common.RestConstants;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.*;
+
+/**
+ * Sample application tests with application add, .
+ */
+public class SampleApplicationsTest extends StratosIntegrationTest {
+    private static final Log log = 
LogFactory.getLog(SampleApplicationsTest.class);
+    private static final String RESOURCES_PATH = "/sample-applications-test";
+
+    @Test(timeOut = APPLICATION_TEST_TIMEOUT)
+    public void testApplication() {
+        log.info("-------------------------------Started application test 
case-------------------------------");
+        try {
+            String autoscalingPolicyId = 
"autoscaling-policy-sample-applications-test";
+
+            boolean addedScalingPolicy =
+                    restClientTenant1.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",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(addedC1, true);
+
+            boolean addedC2 = restClientTenant1.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",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(addedC3, true);
+
+            boolean addedG1 = restClientTenant1.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.
+                    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 + "/" +
+                            
"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 + "/" +
+                            
"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 + "/" +
+                                    
"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 + "/" +
+                            "g-sc-G123-1-sample-applications-test.json", 
RestConstants.APPLICATIONS,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(added, true);
+
+            ApplicationBean bean = (ApplicationBean) 
restClientTenant1.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");
+
+            CartridgeGroupReferenceBean group1 = 
bean.getComponents().getGroups().get(0);
+            CartridgeGroupReferenceBean group2 = group1.getGroups().get(0);
+            CartridgeGroupReferenceBean group3 = group2.getGroups().get(0);
+            CartridgeReferenceBean c1 = group1.getCartridges().get(0);
+            CartridgeReferenceBean c2 = group2.getCartridges().get(0);
+            CartridgeReferenceBean c3 = group3.getCartridges().get(0);
+
+            assertEquals(group1.getName(), "G1-sample-applications-test");
+            assertEquals(group1.getAlias(), "group1-sample-applications-test");
+            assertEquals(group1.getGroupMaxInstances(), 1);
+            assertEquals(group1.getGroupMinInstances(), 1);
+
+            assertEquals(c1.getType(), "c1-sample-applications-test");
+            assertEquals(c1.getCartridgeMin(), 1);
+            assertEquals(c1.getCartridgeMax(), 2);
+
+            assertEquals(group2.getAlias(), "group2-sample-applications-test");
+            assertEquals(group2.getName(), "G2-sample-applications-test");
+            assertEquals(group2.getGroupMaxInstances(), 1);
+            assertEquals(group2.getGroupMinInstances(), 1);
+
+            assertEquals(c2.getType(), "c2-sample-applications-test");
+            assertEquals(c2.getCartridgeMin(), 1);
+            assertEquals(c2.getCartridgeMax(), 2);
+
+            assertEquals(group3.getAlias(), "group3-sample-applications-test");
+            assertEquals(group3.getName(), "G3-sample-applications-test");
+            assertEquals(group3.getGroupMaxInstances(), 2);
+            assertEquals(group3.getGroupMinInstances(), 1);
+
+            assertEquals(c3.getType(), "c3-sample-applications-test");
+            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 +
+                            "/g-sc-G123-1-sample-applications-test-v1.json",
+                    RestConstants.APPLICATIONS, 
RestConstants.APPLICATIONS_NAME);
+            assertEquals(updated, true);
+
+            ApplicationBean updatedBean = (ApplicationBean) 
restClientTenant1.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");
+
+            group1 = updatedBean.getComponents().getGroups().get(0);
+            group2 = group1.getGroups().get(0);
+            group3 = group2.getGroups().get(0);
+            c1 = group1.getCartridges().get(0);
+            c2 = group2.getCartridges().get(0);
+            c3 = group3.getCartridges().get(0);
+
+            assertEquals(group1.getName(), "G1-sample-applications-test");
+            assertEquals(group1.getAlias(), "group1-sample-applications-test");
+            assertEquals(group1.getGroupMaxInstances(), 1);
+            assertEquals(group1.getGroupMinInstances(), 1);
+
+            assertEquals(c1.getType(), "c1-sample-applications-test");
+            assertEquals(c1.getCartridgeMin(), 2);
+            assertEquals(c1.getCartridgeMax(), 3);
+
+            assertEquals(group2.getAlias(), "group2-sample-applications-test");
+            assertEquals(group2.getName(), "G2-sample-applications-test");
+            assertEquals(group2.getGroupMaxInstances(), 1);
+            assertEquals(group2.getGroupMinInstances(), 1);
+
+            assertEquals(c2.getType(), "c2-sample-applications-test");
+            assertEquals(c2.getCartridgeMin(), 2);
+            assertEquals(c2.getCartridgeMax(), 4);
+
+            assertEquals(group3.getAlias(), "group3-sample-applications-test");
+            assertEquals(group3.getName(), "G3-sample-applications-test");
+            assertEquals(group3.getGroupMaxInstances(), 3);
+            assertEquals(group3.getGroupMinInstances(), 2);
+
+            assertEquals(c3.getType(), "c3-sample-applications-test");
+            assertEquals(c3.getCartridgeMin(), 2);
+            assertEquals(c3.getCartridgeMax(), 3);
+
+            updatedBean = (ApplicationBean) 
restClientTenant2.getEntity(RestConstants.APPLICATIONS,
+                    "g-sc-G123-1-sample-applications-test", 
ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+
+            assertNull("Application found in tenant 2", updatedBean);
+
+            boolean removedGroup =
+                    
restClientTenant1.removeEntity(RestConstants.CARTRIDGE_GROUPS, 
"G1-sample-applications-test",
+                            RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertFalse(removedGroup);
+
+            boolean removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertFalse(removedAuto);
+
+            boolean removedNet = 
restClientTenant1.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,
+                    "deployment-policy-sample-applications-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertFalse(removedDep);
+
+            boolean removed =
+                    restClientTenant1.removeEntity(RestConstants.APPLICATIONS, 
"g-sc-G123-1-sample-applications-test",
+                            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);
+
+            removedGroup = 
restClientTenant1.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",
+                    RestConstants.CARTRIDGES_NAME);
+            assertEquals(removedC1, true);
+
+            boolean removedC2 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c2-sample-applications-test",
+                    RestConstants.CARTRIDGES_NAME);
+            assertEquals(removedC2, true);
+
+            boolean removedC3 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c3-sample-applications-test",
+                    RestConstants.CARTRIDGES_NAME);
+            assertEquals(removedC3, true);
+
+            removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertEquals(removedAuto, true);
+
+            removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-sample-applications-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertEquals(removedDep, true);
+
+            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-sample-applications-test-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedNet, true);
+
+            boolean removedN2 = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-sample-applications-test-2", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedN2, true, String.format(
+                    "[Network partition] 
network-partition-sample-applications-test-2 could not be removed for " +
+                            "[application] 
g-sc-G123-1-sample-applications-test"));
+
+            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);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
new file mode 100644
index 0000000..0cbacc6
--- /dev/null
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.integration.tests.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.common.RestConstants;
+import org.apache.stratos.integration.common.TopologyHandler;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.apache.stratos.messaging.domain.application.Application;
+import org.apache.stratos.messaging.domain.application.ApplicationStatus;
+import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
+import org.apache.stratos.messaging.domain.instance.ClusterInstance;
+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.topology.TopologyManager;
+import org.testng.annotations.Test;
+
+import java.util.Set;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+/**
+ * This will handle the scale-up and scale-down of a particular cluster 
bursting test cases
+ */
+public class SingleClusterScalingTest extends StratosIntegrationTest {
+    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(timeOut = APPLICATION_TEST_TIMEOUT)
+    public void testDeployApplication() {
+        try {
+            log.info("----------------------Started application Bursting test 
case---------------------------");
+
+            String autoscalingPolicyId = 
"autoscaling-policy-single-cluster-scaling-test";
+
+            boolean addedScalingPolicy =
+                    restClientTenant1.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",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(addedC1, true);
+
+            boolean addedN1 = restClientTenant1.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 + "/" +
+                                    
"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 + "/" +
+                            "single-cluster-scaling-test.json", 
RestConstants.APPLICATIONS,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(added, true);
+
+            ApplicationBean bean = (ApplicationBean) 
restClientTenant1.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 + "/" +
+                                    
"application-policy-single-cluster-scaling-test.json",
+                            RestConstants.APPLICATION_POLICIES,
+                            RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(addAppPolicy, true);
+
+            ApplicationPolicyBean policyBean = (ApplicationPolicyBean) 
restClientTenant1.getEntity(
+                    RestConstants.APPLICATION_POLICIES,
+                    "application-policy-single-cluster-scaling-test", 
ApplicationPolicyBean.class,
+                    RestConstants.APPLICATION_POLICIES_NAME);
+
+            //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,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(deployed, true);
+
+            //Application active handling
+            
TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId()
+                    , ApplicationStatus.Active, tenant1Id);
+
+            //Cluster active handling
+            
TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(), 
tenant1Id);
+
+            //Verifying whether members got created using round robin algorithm
+            assertClusterWithScalingup(bean.getApplicationId(), tenant1Id);
+
+            boolean removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertEquals(removedAuto, false);
+
+            boolean removedNet = 
restClientTenant1.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,
+                    "deployment-policy-single-cluster-scaling-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertEquals(removedDep, false);
+
+            //Un-deploying the application
+            String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + 
"single-cluster-scaling-test" +
+                    RestConstants.APPLICATIONS_UNDEPLOY;
+
+            boolean unDeployed = 
restClientTenant1.undeployEntity(resourcePathUndeploy,
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(unDeployed, true);
+
+            boolean undeploy =
+                    
TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test",
 tenant1Id);
+            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" +
+                        RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", 
RestConstants.APPLICATIONS);
+
+                boolean forceUndeployed = TopologyHandler.getInstance()
+                        
.assertApplicationUndeploy("single-cluster-scaling-test", tenant1Id);
+                assertEquals(forceUndeployed, true, String.format("Forceful 
undeployment failed for the application %s",
+                        "single-cluster-scaling-test"));
+
+            }
+
+            boolean removed = 
restClientTenant1.removeEntity(RestConstants.APPLICATIONS, 
"single-cluster-scaling-test",
+                    RestConstants.APPLICATIONS_NAME);
+            assertEquals(removed, true);
+
+            ApplicationBean beanRemoved = (ApplicationBean) 
restClientTenant1.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",
+                            RestConstants.CARTRIDGES_NAME);
+            assertEquals(removedC1, true);
+
+
+            removedAuto = 
restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
+            assertEquals(removedAuto, true);
+
+            removedDep = 
restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                    "deployment-policy-single-cluster-scaling-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+            assertEquals(removedDep, true);
+
+            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-single-cluster-scaling-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedNet, false);
+
+
+            boolean removeAppPolicy = 
restClientTenant1.removeEntity(RestConstants.APPLICATION_POLICIES,
+                    "application-policy-single-cluster-scaling-test", 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(removeAppPolicy, true);
+
+            removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-single-cluster-scaling-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedNet, true);
+
+            log.info("-------------------------Ended application bursting test 
case-------------------------");
+
+        }
+        catch (Exception e) {
+            log.error("An error occurred while handling  application 
bursting", e);
+            assertTrue("An error occurred while handling  application 
bursting", false);
+        }
+    }
+
+    /**
+     * Assert application activation
+     *
+     * @param applicationName
+     * @param tenantId
+     */
+    private void assertClusterWithScalingup(String applicationName, int 
tenantId) {
+        Application application =
+                
ApplicationManager.getApplications().getApplicationByTenant(applicationName, 
tenantId);
+        assertNotNull(String.format("Application is not found: 
[application-id] %s",
+                applicationName), application);
+        boolean clusterScaleup = false;
+        String clusterId = null;
+        long startTime = System.currentTimeMillis();
+        while (!clusterScaleup) {
+            try {
+                Thread.sleep(1000);
+            }
+            catch (InterruptedException ignore) {
+            }
+            Set<ClusterDataHolder> clusterDataHolderSet = 
application.getClusterDataRecursively();
+            for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
+                String serviceUuid = clusterDataHolder.getServiceUuid();
+                clusterId = clusterDataHolder.getClusterId();
+                Service service = 
TopologyManager.getTopology().getService(serviceUuid);
+                assertNotNull(String.format("Service is not found: 
[application-id] %s [service] %s",
+                        applicationName, serviceUuid), 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);
+                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++;
+                            }
+                        }
+                    }
+                    clusterScaleup = activeInstances >= 
clusterDataHolder.getMinInstances();
+                    if (clusterScaleup) {
+                        activeInstancesAfterScaleup = activeInstances;
+                        break;
+                    }
+                }
+                application = 
ApplicationManager.getApplications().getApplicationByTenant(applicationName, 
tenantId);
+                if ((System.currentTimeMillis() - startTime) > 
CLUSTER_SCALE_UP_TIMEOUT) {
+                    break;
+                }
+            }
+        }
+        assertEquals(true, clusterScaleup, String.format("Cluster did not get 
scaled up: [cluster-id] %s", clusterId));
+    }
+
+    /**
+     * Assert application activation
+     *
+     * @param applicationName
+     */
+    private void assertClusterWithScaleDown(String applicationName, int 
tenantId) {
+        Application application =
+                
ApplicationManager.getApplications().getApplicationByTenant(applicationName, 
tenantId);
+        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.getServiceUuid();
+                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().getApplicationByTenant(applicationName, 
tenantId);
+                if ((System.currentTimeMillis() - startTime) > 
CLUSTER_SCALE_DOWN_TIMEOUT) {
+                    break;
+                }
+            }
+        }
+        assertEquals(clusterScaleDown, true,
+                String.format("Cluster did not get scaled up: [cluster-id] 
%s", clusterId));
+    }
+
+    /**
+     * 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(clusterScaleDown, true,
+                String.format("Cluster did not get scaled up: [cluster-id] 
%s", clusterId));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
new file mode 100644
index 0000000..6c1af4f
--- /dev/null
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.integration.tests.group;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
+import org.apache.stratos.integration.common.RestConstants;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.testng.annotations.Test;
+
+import static org.testng.AssertJUnit.*;
+
+/**
+ * Test to handle Cartridge group CRUD operations
+ */
+public class CartridgeGroupTest extends StratosIntegrationTest {
+    private static final Log log = LogFactory.getLog(CartridgeGroupTest.class);
+    private static final String RESOURCES_PATH = "/cartridge-group-test";
+
+    @Test(timeOut = GLOBAL_TEST_TIMEOUT)
+    public void testCartridgeGroup() {
+        try {
+            log.info("-------------------------Started Cartridge group test 
case-------------------------");
+
+            boolean addedC1 = restClientTenant1.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);
+
+            boolean addedC2 = restClientTenant1.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);
+
+            boolean addedC3 = restClientTenant1.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);
+
+            boolean added = restClientTenant1.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);
+
+            CartridgeGroupBean bean = (CartridgeGroupBean) restClientTenant1.
+                    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 +
+                            "/" + "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);
+
+            CartridgeGroupBean updatedBean = (CartridgeGroupBean) 
restClientTenant1.
+                    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",
+                    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);
+
+            boolean removedC2 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c5-cartridge-group-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertEquals(String.format("Cartridge can be removed while it is 
used in " +
+                            "cartridge group: [cartridge-name] %s",
+                    "c5-cartridge-group-test"), removedC2, false);
+
+            boolean removedC3 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, 
"c6-cartridge-group-test",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertEquals(String.format("Cartridge can be removed while it is 
used in " +
+                            "cartridge group: [cartridge-name] %s",
+                    "c6-cartridge-group-test"), removedC3, false);
+
+            boolean removed = 
restClientTenant1.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);
+
+            CartridgeGroupBean beanRemoved = (CartridgeGroupBean) 
restClientTenant1.
+                    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",
+                    RestConstants.CARTRIDGE_GROUPS_NAME);
+            assertEquals(String.format("Cartridge can not be removed : 
[cartridge-name] %s",
+                    "c4-cartridge-group-test"), removedC1, true);
+
+            removedC2 = 
restClientTenant1.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);
+
+            removedC3 = 
restClientTenant1.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);
+
+            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);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java
new file mode 100644
index 0000000..84a2ae7
--- /dev/null
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.integration.tests.group;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.beans.PropertyBean;
+import org.apache.stratos.common.beans.cartridge.CartridgeBean;
+import org.apache.stratos.integration.common.RestConstants;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.*;
+
+/**
+ * Test to handle Cartridge CRUD operations
+ */
+public class CartridgeTest extends StratosIntegrationTest {
+    private static final Log log = LogFactory.getLog(CartridgeTest.class);
+    private static final String RESOURCES_PATH = "/cartridge-test";
+
+    @Test(timeOut = GLOBAL_TEST_TIMEOUT)
+    public void testCartridge() {
+        log.info("--------------------Started Cartridge test 
case-----------------------------");
+
+        try {
+            String cartridgeType = "c0-cartridge-test";
+            boolean added = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" +
+                            cartridgeType + ".json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(added, true);
+            CartridgeBean bean = (CartridgeBean) restClientTenant1.
+                    getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                            CartridgeBean.class, 
RestConstants.CARTRIDGES_NAME);
+            assertEquals(bean.getCategory(), "Application");
+
+            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");
+                }
+            }
+            bean = (CartridgeBean) restClientTenant2.
+                    getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                            CartridgeBean.class, 
RestConstants.CARTRIDGES_NAME);
+            assertNull("Cartridge exists in other tenant", bean);
+            boolean updated = restClientTenant1.updateEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" +
+                            cartridgeType + "-v1.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(updated, true);
+            CartridgeBean updatedBean = (CartridgeBean) restClientTenant1.
+                    getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                            CartridgeBean.class, 
RestConstants.CARTRIDGES_NAME);
+            assertEquals(updatedBean.getType(), "c0-cartridge-test");
+            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");
+                }
+            }
+
+            bean = (CartridgeBean) restClientTenant2.
+                    getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                            CartridgeBean.class, 
RestConstants.CARTRIDGES_NAME);
+            assertNull("Cartridge exists in other tenant", bean);
+
+            added = restClientTenant2.addEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" +
+                            cartridgeType + ".json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(added, true);
+
+            updated = restClientTenant2.updateEntity(RESOURCES_PATH + 
RestConstants.CARTRIDGES_PATH + "/" +
+                            cartridgeType + "-v1.json",
+                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+            assertEquals(updated, true);
+
+            updatedBean = (CartridgeBean) restClientTenant2.
+                    getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                            CartridgeBean.class, 
RestConstants.CARTRIDGES_NAME);
+            assertEquals(updatedBean.getType(), "c0-cartridge-test");
+            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 = 
restClientTenant1.removeEntity(RestConstants.CARTRIDGES, cartridgeType,
+                    RestConstants.CARTRIDGES_NAME);
+            assertEquals(removed, true);
+
+            bean = (CartridgeBean) restClientTenant2.
+                    getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                            CartridgeBean.class, 
RestConstants.CARTRIDGES_NAME);
+            assertNotNull("Cartridge not exists in other tenant", bean);
+
+            CartridgeBean beanRemoved = (CartridgeBean) restClientTenant1.
+                    getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                            CartridgeBean.class, 
RestConstants.CARTRIDGES_NAME);
+            assertEquals(beanRemoved, null);
+
+            removed = restClientTenant2.removeEntity(RestConstants.CARTRIDGES, 
cartridgeType,
+                    RestConstants.CARTRIDGES_NAME);
+            assertEquals(removed, true);
+
+            beanRemoved = (CartridgeBean) restClientTenant2.
+                    getEntity(RestConstants.CARTRIDGES, cartridgeType,
+                            CartridgeBean.class, 
RestConstants.CARTRIDGES_NAME);
+            assertEquals(beanRemoved, null);
+
+
+            log.info("---------------------------Ended Cartridge test 
case-------------------------");
+        }
+        catch (Exception e) {
+            log.error("An error occurred while handling 
RESTConstants.CARTRIDGES_PATH", e);
+            assertTrue("An error occurred while handling 
RESTConstants.CARTRIDGES_PATH", false);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java
new file mode 100644
index 0000000..b7daa65
--- /dev/null
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.integration.tests.policies;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.beans.PropertyBean;
+import org.apache.stratos.common.beans.partition.NetworkPartitionBean;
+import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
+import org.apache.stratos.integration.common.RestConstants;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.*;
+
+/**
+ * Test to handle Network partition CRUD operations
+ */
+public class ApplicationPolicyTest extends StratosIntegrationTest {
+    private static final Log log = 
LogFactory.getLog(ApplicationPolicyTest.class);
+    private static final String RESOURCES_PATH = "/application-policy-test";
+
+    @Test(timeOut = GLOBAL_TEST_TIMEOUT)
+    public void testApplicationPolicy() {
+        try {
+            String applicationPolicyId = 
"application-policy-application-policy-test";
+            log.info("-------------------------Started Application policy test 
case-------------------------");
+
+            boolean addedN1 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            "network-partition-application-policy-test-1" + 
".json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(addedN1, true);
+
+            boolean addedN2 = restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            "network-partition-application-policy-test-2" + 
".json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(addedN2, true);
+
+            boolean addedDep =
+                    restClientTenant1.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATION_POLICIES_PATH + "/" +
+                                    applicationPolicyId + ".json",
+                            RestConstants.APPLICATION_POLICIES, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(addedDep, true);
+
+            ApplicationPolicyBean bean = (ApplicationPolicyBean) 
restClientTenant1.
+                    getEntity(RestConstants.APPLICATION_POLICIES, 
applicationPolicyId,
+                            ApplicationPolicyBean.class, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(bean.getId(), applicationPolicyId);
+            assertEquals(bean.getAlgorithm(), "one-after-another",
+                    String.format("The expected algorithm %s is not found in 
%s", "one-after-another",
+                            applicationPolicyId));
+            assertEquals(bean.getId(), applicationPolicyId,
+                    String.format("The expected id %s is not found", 
applicationPolicyId));
+            assertEquals(bean.getNetworkPartitions().length, 2,
+                    String.format("The expected networkpartitions size %s is 
not found in %s", 2, applicationPolicyId));
+            assertEquals(bean.getNetworkPartitions()[0], 
"network-partition-application-policy-test-1",
+                    String.format("The first network partition is not %s in 
%s",
+                            "network-partition-application-policy-test-1", 
applicationPolicyId));
+            assertEquals(bean.getNetworkPartitions()[1], 
"network-partition-application-policy-test-2",
+                    String.format("The Second network partition is not %s in 
%s",
+                            "network-partition-application-policy-test-2", 
applicationPolicyId));
+            boolean algoFound = false;
+            for (PropertyBean propertyBean : bean.getProperties()) {
+                if (propertyBean.getName().equals("networkPartitionGroups")) {
+                    assertEquals(propertyBean.getValue(),
+                            
"network-partition-application-policy-test-1,network-partition-application-policy-test-2",
+                            String.format("The networkPartitionGroups 
algorithm %s is not found in %s",
+                                    
"network-partition-application-policy-test-1,network-partition-application-policy-test-2",
+                                    applicationPolicyId));
+                    algoFound = true;
+
+                }
+            }
+            if (!algoFound) {
+                assertTrue(String.format("The networkPartitionGroups property 
is not found in %s",
+                        applicationPolicyId), false);
+            }
+
+            bean = (ApplicationPolicyBean) restClientTenant2.
+                    getEntity(RestConstants.APPLICATION_POLICIES, 
applicationPolicyId,
+                            ApplicationPolicyBean.class, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertNull("Application policy bean found in tenant 2", bean);
+
+            addedN1 = restClientTenant2.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            "network-partition-application-policy-test-1" + 
".json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(addedN1, true);
+
+            addedN2 = restClientTenant2.addEntity(RESOURCES_PATH + 
RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                            "network-partition-application-policy-test-2" + 
".json",
+                    RestConstants.NETWORK_PARTITIONS, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(addedN2, true);
+
+            boolean addedTenant2Dep =
+                    restClientTenant2.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATION_POLICIES_PATH + "/" +
+                                    applicationPolicyId + ".json",
+                            RestConstants.APPLICATION_POLICIES, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(addedTenant2Dep, true);
+
+            ApplicationPolicyBean tenant2bean = (ApplicationPolicyBean) 
restClientTenant2.
+                    getEntity(RestConstants.APPLICATION_POLICIES, 
applicationPolicyId,
+                            ApplicationPolicyBean.class, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertNotNull("Application is not exist in tenant 2", tenant2bean);
+
+
+            boolean removedNet = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-application-policy-test-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            //Trying to remove the used network partition
+            assertEquals(removedNet, false);
+
+            boolean removedDep = 
restClientTenant1.removeEntity(RestConstants.APPLICATION_POLICIES,
+                    applicationPolicyId, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(removedDep, true);
+
+            ApplicationPolicyBean beanRemovedDep = (ApplicationPolicyBean) 
restClientTenant1.
+                    getEntity(RestConstants.APPLICATION_POLICIES, 
applicationPolicyId,
+                            ApplicationPolicyBean.class, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(beanRemovedDep, null);
+
+            boolean removedN1 = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-application-policy-test-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedN1, true);
+
+            NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) 
restClientTenant1.
+                    getEntity(RestConstants.NETWORK_PARTITIONS, 
"network-partition-application-policy-test-1",
+                            NetworkPartitionBean.class, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(beanRemovedN1, null);
+
+            boolean removedN2 = 
restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-application-policy-test-2", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedN2, true);
+
+            NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) 
restClientTenant1.
+                    getEntity(RestConstants.NETWORK_PARTITIONS, 
"network-partition-application-policy-test-2",
+                            NetworkPartitionBean.class, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(beanRemovedN2, null);
+
+            tenant2bean = (ApplicationPolicyBean) restClientTenant2.
+                    getEntity(RestConstants.APPLICATION_POLICIES, 
applicationPolicyId,
+                            ApplicationPolicyBean.class, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertNotNull("Application is not exist in tenant 2", tenant2bean);
+
+            removedDep = 
restClientTenant2.removeEntity(RestConstants.APPLICATION_POLICIES,
+                    applicationPolicyId, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(removedDep, true);
+
+            beanRemovedDep = (ApplicationPolicyBean) restClientTenant2.
+                    getEntity(RestConstants.APPLICATION_POLICIES, 
applicationPolicyId,
+                            ApplicationPolicyBean.class, 
RestConstants.APPLICATION_POLICIES_NAME);
+            assertEquals(beanRemovedDep, null);
+
+            removedN1 = 
restClientTenant2.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-application-policy-test-1", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedN1, true);
+
+            beanRemovedN1 = (NetworkPartitionBean) restClientTenant2.
+                    getEntity(RestConstants.NETWORK_PARTITIONS, 
"network-partition-application-policy-test-1",
+                            NetworkPartitionBean.class, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(beanRemovedN1, null);
+
+            removedN2 = 
restClientTenant2.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                    "network-partition-application-policy-test-2", 
RestConstants.NETWORK_PARTITIONS_NAME);
+            assertEquals(removedN2, true);
+
+            beanRemovedN2 = (NetworkPartitionBean) restClientTenant2.
+                    getEntity(RestConstants.NETWORK_PARTITIONS, 
"network-partition-application-policy-test-2",
+                            NetworkPartitionBean.class, 
RestConstants.NETWORK_PARTITIONS_NAME);
+            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);
+        }
+    }
+}
\ No newline at end of file

Reply via email to