http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/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
deleted file mode 100644
index f2120cf..0000000
--- 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
- * 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 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;
-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 java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.testng.Assert.*;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
-
-/**
- * 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, groups = 
{"stratos.application.deployment"})
-    public void testApplication() {
-        log.info("-------------------------------Started application test 
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);
-
-            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 = 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) 
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");
-
-            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);
-
-            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) 
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");
-
-            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);
-
-
-            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(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);
-        }
-    }
-
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = 
{"stratos.application.deployment"})
-    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);
-
-            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);
-
-            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 = 
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);
-
-            removed = restClient.removeEntity(RestConstants.APPLICATIONS, app2,
-                    RestConstants.APPLICATIONS_NAME);
-            assertTrue(removed);
-
-            beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
-                    app2, 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(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/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java
new file mode 100644
index 0000000..2dcf88f
--- /dev/null
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java
@@ -0,0 +1,404 @@
+/*
+ * 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 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;
+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 java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.testng.Assert.*;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+/**
+ * Sample application tests with application add, .
+ */
+public class SampleApplicationsTestCase extends StratosIntegrationTest {
+    private static final Log log = 
LogFactory.getLog(SampleApplicationsTestCase.class);
+    private static final String RESOURCES_PATH = "/sample-applications-test";
+
+    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = 
{"stratos.application.deployment"})
+    public void testApplication() throws Exception {
+        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);
+
+        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 = 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) 
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");
+
+        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);
+
+        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) 
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");
+
+        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);
+
+
+        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(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"));
+    }
+
+    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = 
{"stratos.application.deployment"})
+    public void testApplicationList() throws Exception {
+            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);
+
+            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);
+
+            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 = 
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);
+
+            removed = restClient.removeEntity(RestConstants.APPLICATIONS, app2,
+                    RestConstants.APPLICATIONS_NAME);
+            assertTrue(removed);
+
+            beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                    app2, 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(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"));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/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
deleted file mode 100644
index a6f842a..0000000
--- 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- * 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(SingleClusterScalingTest.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, groups = 
{"stratos.application.deployment"})
-    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 = 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 + "/" + 
"c7-single-cluster-scaling-test.json",
-                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-            assertEquals(addedC1, true);
-
-            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 = 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 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
-                            "single-cluster-scaling-test.json", 
RestConstants.APPLICATIONS,
-                    RestConstants.APPLICATIONS_NAME);
-            assertEquals(added, true);
-
-            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 = 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) 
restClient.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 = restClient.deployEntity(resourcePath,
-                    RestConstants.APPLICATIONS_NAME);
-            assertEquals(deployed, true);
-
-            //Application active handling
-            topologyHandler.assertApplicationStatus(bean.getApplicationId()
-                    , ApplicationStatus.Active);
-
-            //Cluster active handling
-            topologyHandler.assertClusterActivation(bean.getApplicationId());
-
-            //Verifying whether members got created using round robin algorithm
-            assertClusterWithScalingup(bean.getApplicationId());
-
-            //assert scale-down
-            assertClusterWithScaleDown(bean.getApplicationId());
-
-            //Check whether cluster could scale-down upto the minimum
-            assertClusterScaleDownToMinimumCount(bean.getApplicationId());
-
-            boolean removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
-            assertEquals(removedAuto, false);
-
-            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 = 
restClient.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 = 
restClient.undeployEntity(resourcePathUndeploy,
-                    RestConstants.APPLICATIONS_NAME);
-            assertEquals(unDeployed, true);
-
-            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");
-
-                restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + 
"single-cluster-scaling-test" +
-                        RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", 
RestConstants.APPLICATIONS);
-
-                boolean forceUndeployed = 
topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
-                assertEquals(forceUndeployed, true, String.format("Forceful 
undeployment failed for the application %s",
-                        "single-cluster-scaling-test"));
-            }
-
-            boolean removed = 
restClient.removeEntity(RestConstants.APPLICATIONS, 
"single-cluster-scaling-test",
-                    RestConstants.APPLICATIONS_NAME);
-            assertEquals(removed, true);
-
-            ApplicationBean beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
-                    "single-cluster-scaling-test", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
-            assertEquals(beanRemoved, null);
-
-            boolean removedC1 = 
restClient.removeEntity(RestConstants.CARTRIDGES, 
"c7-single-cluster-scaling-test",
-                    RestConstants.CARTRIDGES_NAME);
-            assertEquals(removedC1, true);
-
-
-            removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                    autoscalingPolicyId, 
RestConstants.AUTOSCALING_POLICIES_NAME);
-            assertEquals(removedAuto, true);
-
-            removedDep = 
restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                    "deployment-policy-single-cluster-scaling-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
-            assertEquals(removedDep, true);
-
-            removedNet = 
restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                    "network-partition-single-cluster-scaling-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
-            assertEquals(removedNet, false);
-
-
-            boolean removeAppPolicy = 
restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                    "application-policy-single-cluster-scaling-test", 
RestConstants.APPLICATION_POLICIES_NAME);
-            assertEquals(removeAppPolicy, true);
-
-            removedNet = 
restClient.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
-     */
-    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;
-        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 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++;
-                            }
-                        }
-                    }
-
-                    clusterScaleup = activeInstances > 
clusterDataHolder.getMinInstances();
-                    if (clusterScaleup) {
-                        activeInstancesAfterScaleup = activeInstances;
-                        break;
-                    }
-                }
-                application = 
ApplicationManager.getApplications().getApplication(applicationName);
-                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) {
-        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(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/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java
----------------------------------------------------------------------
diff --git 
a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java
 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java
new file mode 100644
index 0000000..9598df0
--- /dev/null
+++ 
b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java
@@ -0,0 +1,358 @@
+/*
+ * 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;
+
+/**
+ * This will handle the scale-up and scale-down of a particular cluster 
bursting test cases
+ */
+public class SingleClusterScalingTestCase extends StratosIntegrationTest {
+    private static final Log log = 
LogFactory.getLog(SingleClusterScalingTestCase.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, groups = 
{"stratos.application.deployment"})
+    public void testDeployApplication() throws Exception {
+        TopologyHandler topologyHandler = TopologyHandler.getInstance();
+        String autoscalingPolicyId = 
"autoscaling-policy-single-cluster-scaling-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 + "/" + 
"c7-single-cluster-scaling-test.json",
+                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertEquals(addedC1, true);
+
+        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 = 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 = restClient.addEntity(RESOURCES_PATH + 
RestConstants.APPLICATIONS_PATH + "/" +
+                        "single-cluster-scaling-test.json", 
RestConstants.APPLICATIONS,
+                RestConstants.APPLICATIONS_NAME);
+        assertEquals(added, true);
+
+        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 = 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) 
restClient.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 = restClient.deployEntity(resourcePath,
+                RestConstants.APPLICATIONS_NAME);
+        assertEquals(deployed, true);
+
+        //Application active handling
+        topologyHandler.assertApplicationStatus(bean.getApplicationId()
+                , ApplicationStatus.Active);
+
+        //Cluster active handling
+        topologyHandler.assertClusterActivation(bean.getApplicationId());
+
+        //Verifying whether members got created using round robin algorithm
+        assertClusterWithScalingup(bean.getApplicationId());
+
+        //assert scale-down
+        assertClusterWithScaleDown(bean.getApplicationId());
+
+        //Check whether cluster could scale-down upto the minimum
+        assertClusterScaleDownToMinimumCount(bean.getApplicationId());
+
+        boolean removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        assertEquals(removedAuto, false);
+
+        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 = 
restClient.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 = restClient.undeployEntity(resourcePathUndeploy,
+                RestConstants.APPLICATIONS_NAME);
+        assertEquals(unDeployed, true);
+
+        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");
+
+            restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + 
"single-cluster-scaling-test" +
+                    RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", 
RestConstants.APPLICATIONS);
+
+            boolean forceUndeployed = 
topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
+            assertEquals(forceUndeployed, true, String.format("Forceful 
undeployment failed for the application %s",
+                    "single-cluster-scaling-test"));
+        }
+
+        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, 
"single-cluster-scaling-test",
+                RestConstants.APPLICATIONS_NAME);
+        assertEquals(removed, true);
+
+        ApplicationBean beanRemoved = (ApplicationBean) 
restClient.getEntity(RestConstants.APPLICATIONS,
+                "single-cluster-scaling-test", ApplicationBean.class, 
RestConstants.APPLICATIONS_NAME);
+        assertEquals(beanRemoved, null);
+
+        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, 
"c7-single-cluster-scaling-test",
+                RestConstants.CARTRIDGES_NAME);
+        assertEquals(removedC1, true);
+
+
+        removedAuto = 
restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        assertEquals(removedAuto, true);
+
+        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+                "deployment-policy-single-cluster-scaling-test", 
RestConstants.DEPLOYMENT_POLICIES_NAME);
+        assertEquals(removedDep, true);
+
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                "network-partition-single-cluster-scaling-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
+        assertEquals(removedNet, false);
+
+
+        boolean removeAppPolicy = 
restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
+                "application-policy-single-cluster-scaling-test", 
RestConstants.APPLICATION_POLICIES_NAME);
+        assertEquals(removeAppPolicy, true);
+
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
+                "network-partition-single-cluster-scaling-test", 
RestConstants.NETWORK_PARTITIONS_NAME);
+        assertEquals(removedNet, true);
+    }
+
+    /**
+     * Assert application activation
+     *
+     * @param applicationName
+     */
+    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;
+        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 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++;
+                            }
+                        }
+                    }
+
+                    clusterScaleup = activeInstances > 
clusterDataHolder.getMinInstances();
+                    if (clusterScaleup) {
+                        activeInstancesAfterScaleup = activeInstances;
+                        break;
+                    }
+                }
+                application = 
ApplicationManager.getApplications().getApplication(applicationName);
+                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) {
+        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(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

Reply via email to