http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java index 2dad064..a6b6095 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTest.java @@ -23,13 +23,12 @@ 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.policy.deployment.ApplicationPolicyBean; import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; -import org.apache.stratos.integration.tests.TopologyHandler; import org.testng.annotations.Test; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; /** @@ -42,162 +41,162 @@ public class SampleApplicationsTest extends StratosTestServerManager { @Test public void testApplication() { log.info("Started application test case**************************************"); - String autoscalingPolicyId = "autoscaling-policy-1"; - try { + String autoscalingPolicyId = "autoscaling-policy-sample-applications-test"; + boolean addedScalingPolicy = restClient.addEntity(TEST_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json", RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); assertEquals(addedScalingPolicy, true); - boolean addedC1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1.json", + boolean addedC1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-sample-applications-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); assertEquals(addedC1, true); - boolean addedC2 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2.json", + boolean addedC2 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-sample-applications-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); assertEquals(addedC2, true); - boolean addedC3 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3.json", + boolean addedC3 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-sample-applications-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); assertEquals(addedC3, true); boolean addedG1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + "cartrdige-nested.json", RestConstants.CARTRIDGE_GROUPS, + "/" + "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", + getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test", CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(beanG1.getName(), "G1"); + assertEquals(beanG1.getName(), "G1-sample-applications-test"); boolean addedN1 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-1.json", + "network-partition-sample-applications-test-1.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(addedN1, true); boolean addedN2 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-2.json", + "network-partition-sample-applications-test-2.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(addedN2, true); boolean addedDep = restClient.addEntity(TEST_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - "deployment-policy-1.json", + "deployment-policy-sample-applications-test.json", RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); assertEquals(addedDep, true); boolean added = restClient.addEntity(TEST_PATH + RestConstants.APPLICATIONS_PATH + "/" + - "g-sc-G123-1.json", RestConstants.APPLICATIONS, + "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", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(bean.getApplicationId(), "g-sc-G123-1"); + "g-sc-G123-1-sample-applications-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(bean.getApplicationId(), "g-sc-G123-1-sample-applications-test"); - assertEquals(bean.getComponents().getGroups().get(0).getName(), "G1"); - assertEquals(bean.getComponents().getGroups().get(0).getAlias(), "group1"); + assertEquals(bean.getComponents().getGroups().get(0).getName(), "G1-sample-applications-test"); + assertEquals(bean.getComponents().getGroups().get(0).getAlias(), "group1-sample-applications-test"); assertEquals(bean.getComponents().getGroups().get(0).getGroupMaxInstances(), 1); assertEquals(bean.getComponents().getGroups().get(0).getGroupMinInstances(), 1); - assertEquals(bean.getComponents().getGroups().get(0).getCartridges().get(0).getType(), "c1"); + assertEquals(bean.getComponents().getGroups().get(0).getCartridges().get(0).getType(), "c1-sample-applications-test"); assertEquals(bean.getComponents().getGroups().get(0).getCartridges().get(0).getCartridgeMin(), 1); assertEquals(bean.getComponents().getGroups().get(0).getCartridges().get(0).getCartridgeMax(), 2); - assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getAlias(), "group2"); - assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getName(), "G2"); + assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getAlias(), "group2-sample-applications-test"); + assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getName(), "G2-sample-applications-test"); assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroupMaxInstances(), 1); assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroupMinInstances(), 1); - assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getCartridges().get(0).getType(), "c2"); + assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getCartridges().get(0).getType(), "c2-sample-applications-test"); assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMin(), 1); assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMax(), 2); - assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getAlias(), "group3"); - assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getName(), "G3"); + assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getAlias(), "group3-sample-applications-test"); + assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getName(), "G3-sample-applications-test"); assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getGroupMaxInstances(), 2); assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getGroupMinInstances(), 1); - assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getType(), "c3"); + assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getType(), "c3-sample-applications-test"); assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMin(), 1); assertEquals(bean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMax(), 2); - boolean updated = restClient.updateEntity(TEST_PATH + RestConstants.APPLICATIONS_PATH + "/g-sc-G123-1-v1.json", + boolean updated = restClient.updateEntity(TEST_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", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + "g-sc-G123-1-sample-applications-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(bean.getApplicationId(), "g-sc-G123-1"); - assertEquals(updatedBean.getComponents().getGroups().get(0).getName(), "G1"); - assertEquals(updatedBean.getComponents().getGroups().get(0).getAlias(), "group1"); + assertEquals(bean.getApplicationId(), "g-sc-G123-1-sample-applications-test"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getName(), "G1-sample-applications-test"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getAlias(), "group1-sample-applications-test"); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroupMaxInstances(), 1); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroupMinInstances(), 1); - assertEquals(updatedBean.getComponents().getGroups().get(0).getCartridges().get(0).getType(), "c1"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getCartridges().get(0).getType(), "c1-sample-applications-test"); assertEquals(updatedBean.getComponents().getGroups().get(0).getCartridges().get(0).getCartridgeMin(), 2); assertEquals(updatedBean.getComponents().getGroups().get(0).getCartridges().get(0).getCartridgeMax(), 3); - assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getAlias(), "group2"); - assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getName(), "G2"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getAlias(), "group2-sample-applications-test"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getName(), "G2-sample-applications-test"); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroupMaxInstances(), 1); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroupMinInstances(), 1); - assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getCartridges().get(0).getType(), "c2"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getCartridges().get(0).getType(), "c2-sample-applications-test"); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMin(), 2); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMax(), 4); - assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getAlias(), "group3"); - assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getName(), "G3"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getAlias(), "group3-sample-applications-test"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getName(), "G3-sample-applications-test"); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getGroupMaxInstances(), 3); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getGroupMinInstances(), 2); - assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getType(), "c3"); + assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getType(), "c3-sample-applications-test"); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMin(), 2); assertEquals(updatedBean.getComponents().getGroups().get(0).getGroups().get(0).getGroups().get(0).getCartridges().get(0).getCartridgeMax(), 3); - boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1", + boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test", RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(removedGroup, false); + assertFalse(removedGroup); boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertEquals(removedAuto, false); + assertFalse(removedAuto); boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-1", + "network-partition-sample-applications-test-1", RestConstants.NETWORK_PARTITIONS_NAME); //Trying to remove the used network partition - assertEquals(removedNet, false); + assertFalse(removedNet); boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - "deployment-policy-1", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(removedDep, false); + "deployment-policy-sample-applications-test", RestConstants.DEPLOYMENT_POLICIES_NAME); + assertFalse(removedDep); - boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1", + boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-sample-applications-test", RestConstants.APPLICATIONS_NAME); - assertEquals(removed, true); + assertTrue(removed); ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + "g-sc-G123-1-sample-applications-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); assertEquals(beanRemoved, null); - removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1", + removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(removedGroup, true); - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1", + boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1-sample-applications-test", RestConstants.CARTRIDGES_NAME); assertEquals(removedC1, true); - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2", + boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2-sample-applications-test", RestConstants.CARTRIDGES_NAME); assertEquals(removedC2, true); - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3", + boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3-sample-applications-test", RestConstants.CARTRIDGES_NAME); assertEquals(removedC3, true); @@ -206,16 +205,17 @@ public class SampleApplicationsTest extends StratosTestServerManager { assertEquals(removedAuto, true); removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - "deployment-policy-1", RestConstants.DEPLOYMENT_POLICIES_NAME); + "deployment-policy-sample-applications-test", RestConstants.DEPLOYMENT_POLICIES_NAME); assertEquals(removedDep, true); removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-1", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-sample-applications-test-1", RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(removedNet, true); boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, true); + "network-partition-sample-applications-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(String.format("[Network partition] network-partition-sample-applications-test-2 " + + "could not be removed for [application] g-sc-G123-1-sample-applications-test"),removedN2, true); log.info("Ended application test case**************************************"); @@ -224,204 +224,4 @@ public class SampleApplicationsTest extends StratosTestServerManager { assertTrue("An error occurred while handling application test case", false); } } - - @Test(dependsOnMethods = {"testApplication"}) - public void testDeployApplication() { - try { - log.info("Started application deploy/undeploy test case**************************************"); - - String autoscalingPolicyId = "autoscaling-policy-1"; - - boolean addedScalingPolicy = restClient.addEntity(TEST_PATH + RestConstants.AUTOSCALING_POLICIES_PATH - + "/" + autoscalingPolicyId + ".json", - RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - assertEquals(addedScalingPolicy, true); - - boolean addedC1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC1, true); - - boolean addedC2 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC2, true); - - boolean addedC3 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC3, true); - - boolean addedG1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + "cartrdige-nested.json", RestConstants.CARTRIDGE_GROUPS, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(addedG1, true); - - CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, "G1", - CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(beanG1.getName(), "G1"); - - boolean addedN1 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-1.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(addedN1, true); - - boolean addedN2 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-2.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(addedN2, true); - - boolean addedDep = restClient.addEntity(TEST_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - "deployment-policy-1.json", - RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(addedDep, true); - - boolean added = restClient.addEntity(TEST_PATH + RestConstants.APPLICATIONS_PATH + "/" + - "g-sc-G123-1.json", RestConstants.APPLICATIONS, - RestConstants.APPLICATIONS_NAME); - assertEquals(added, true); - - ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(bean.getApplicationId(), "g-sc-G123-1"); - - boolean addAppPolicy = restClient.addEntity(TEST_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + - "application-policy-1.json", RestConstants.APPLICATION_POLICIES, - RestConstants.APPLICATION_POLICIES_NAME); - assertEquals(addAppPolicy, true); - - ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity( - RestConstants.APPLICATION_POLICIES, - "application-policy-1", ApplicationPolicyBean.class, - RestConstants.APPLICATION_POLICIES_NAME); - - //deploy the application - String resourcePath = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1" + - RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-1"; - boolean deployed = restClient.deployEntity(resourcePath, - RestConstants.APPLICATIONS_NAME); - assertEquals(deployed, true); - - //Application active handling - TopologyHandler.getInstance().assertApplicationActivation(bean.getApplicationId()); - - //Group active handling - TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId()); - - //Cluster active handling - TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId()); - - //Updating application - boolean updated = restClient.updateEntity(TEST_PATH + RestConstants.APPLICATIONS_PATH + "/" + - "g-sc-G123-1-v1.json", RestConstants.APPLICATIONS, - RestConstants.APPLICATIONS_NAME); - assertEquals(updated, true); - - TopologyHandler.getInstance().assertGroupInstanceCount(bean.getApplicationId(), "group3", 2); - - TopologyHandler.getInstance().assertClusterMinMemberCount(bean.getApplicationId(), 2); - - ApplicationBean updatedBean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(updatedBean.getApplicationId(), "g-sc-G123-1"); - - boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(removedGroup, false); - - boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertEquals(removedAuto, false); - - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-1", - RestConstants.NETWORK_PARTITIONS_NAME); - //Trying to remove the used network partition - assertEquals(removedNet, false); - - boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - "deployment-policy-1", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(removedDep, false); - - //Un-deploying the application - String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1" + - RestConstants.APPLICATIONS_UNDEPLOY; - - boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, - RestConstants.APPLICATIONS_NAME); - assertEquals(unDeployed, true); - - boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("g-sc-G123-1"); - if (!undeploy) { - //Need to forcefully undeploy the application - log.info("Force undeployment is going to start for the [application] " + "g-sc-G123-1"); - - restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "g-sc-G123-1" + - RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); - - boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("g-sc-G123-1"); - assertEquals(String.format("Forceful undeployment failed for the application %s", - "g-sc-G123-1"), forceUndeployed, true); - - } - - boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1", - RestConstants.APPLICATIONS_NAME); - assertEquals(removed, true); - - ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(beanRemoved, null); - - removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(removedGroup, true); - - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC1, true); - - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC2, true); - - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3", - 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-1", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(removedDep, true); - - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedNet, false); - - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, false); - - boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, - "application-policy-1", RestConstants.APPLICATION_POLICIES_NAME); - assertEquals(removeAppPolicy, true); - - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedNet, true); - - removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, true); - - log.info("Ended application deploy/undeploy test case**************************************"); - - } catch (Exception e) { - log.error("An error occurred while handling application deployment/undeployment", e); - assertTrue("An error occurred while handling application deployment/undeployment", false); - } - } - - }
http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java index 2fd4100..c42be16 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTest.java @@ -21,22 +21,33 @@ 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.policy.deployment.ApplicationPolicyBean; import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; import org.apache.stratos.integration.tests.TopologyHandler; +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 static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; +import java.util.Set; + +import static junit.framework.Assert.*; /** * This will handle the scale-up and scale-down of a particular cluster bursting test cases */ public class SingleClusterScalingTest extends StratosTestServerManager { private static final Log log = LogFactory.getLog(SampleApplicationsTest.class); - private static final String TEST_PATH = "/application-bursting-test"; + private static final String TEST_PATH = "/single-cluster-scaling-test"; + private static final int CLUSTER_SCALE_UP_TIMEOUT = 180000; @Test @@ -44,177 +55,133 @@ public class SingleClusterScalingTest extends StratosTestServerManager { try { log.info("Started application Bursting test case**************************************"); - String autoscalingPolicyId = "autoscaling-policy-2"; + String autoscalingPolicyId = "autoscaling-policy-single-cluster-scaling-test"; boolean addedScalingPolicy = restClient.addEntity(TEST_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json", RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); assertEquals(addedScalingPolicy, true); - boolean addedC1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "esb.json", + boolean addedC1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c7-single-cluster-scaling-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); assertEquals(addedC1, true); - boolean addedC2 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "php.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC2, true); - - boolean addedC3 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "tomcat.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC3, true); - - boolean addedG1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + "esb-php-group.json", RestConstants.CARTRIDGE_GROUPS, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(addedG1, true); - - CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group", - CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(beanG1.getName(), "esb-php-group"); - boolean addedN1 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-9.json", + "network-partition-single-cluster-scaling-test.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(addedN1, true); - boolean addedN2 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-10.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(addedN2, true); - boolean addedDep = restClient.addEntity(TEST_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - "deployment-policy-4.json", + "deployment-policy-single-cluster-scaling-test.json", RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); assertEquals(addedDep, true); boolean added = restClient.addEntity(TEST_PATH + RestConstants.APPLICATIONS_PATH + "/" + - "app-bursting-single-cartriddge-group.json", RestConstants.APPLICATIONS, + "single-cluster-scaling-test.json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME); assertEquals(added, true); ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "cartridge-group-app", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(bean.getApplicationId(), "cartridge-group-app"); + "single-cluster-scaling-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(bean.getApplicationId(), "single-cluster-scaling-test"); boolean addAppPolicy = restClient.addEntity(TEST_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + - "application-policy-3.json", RestConstants.APPLICATION_POLICIES, + "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-3", ApplicationPolicyBean.class, + "application-policy-single-cluster-scaling-test", ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); //deploy the application - String resourcePath = RestConstants.APPLICATIONS + "/" + "cartridge-group-app" + - RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-3"; + 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.getInstance().assertApplicationActivation(bean.getApplicationId()); - - //Group active handling - TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId()); + TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId() + , ApplicationStatus.Active); //Cluster active handling TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId()); - boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(removedGroup, false); + //Verifying whether members got created using round robin algorithm + assertClusterWithScalingup(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-9", + "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-4", RestConstants.DEPLOYMENT_POLICIES_NAME); + "deployment-policy-single-cluster-scaling-test", RestConstants.DEPLOYMENT_POLICIES_NAME); assertEquals(removedDep, false); //Un-deploying the application - String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "cartridge-group-app" + + 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.getInstance().assertApplicationUndeploy("cartridge-group-app"); + boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test"); if (!undeploy) { //Need to forcefully undeploy the application - log.info("Force undeployment is going to start for the [application] " + "cartridge-group-app"); + log.info("Force undeployment is going to start for the [application] " + "single-cluster-scaling-test"); - restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "cartridge-group-app" + + restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "single-cluster-scaling-test" + RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); - boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("cartridge-group-app"); + boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy("single-cluster-scaling-test"); assertEquals(String.format("Forceful undeployment failed for the application %s", - "cartridge-group-app"), forceUndeployed, true); + "single-cluster-scaling-test"), forceUndeployed, true); } - boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "cartridge-group-app", + boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "single-cluster-scaling-test", RestConstants.APPLICATIONS_NAME); assertEquals(removed, true); ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "cartridge-group-app", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + "single-cluster-scaling-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); assertEquals(beanRemoved, null); - removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(removedGroup, true); - - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "esb", + boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c7-single-cluster-scaling-test", RestConstants.CARTRIDGES_NAME); assertEquals(removedC1, true); - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "php", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC2, true); - - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "tomcat", - 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-4", RestConstants.DEPLOYMENT_POLICIES_NAME); + "deployment-policy-single-cluster-scaling-test", RestConstants.DEPLOYMENT_POLICIES_NAME); assertEquals(removedDep, true); removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-9", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-single-cluster-scaling-test", RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(removedNet, false); - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-10", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, false); boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, - "application-policy-3", RestConstants.APPLICATION_POLICIES_NAME); + "application-policy-single-cluster-scaling-test", RestConstants.APPLICATION_POLICIES_NAME); assertEquals(removeAppPolicy, true); removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-9", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-single-cluster-scaling-test", RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(removedNet, true); - removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-10", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, true); - log.info("Ended application bursting test case**************************************"); } catch (Exception e) { @@ -223,11 +190,55 @@ public class SingleClusterScalingTest extends StratosTestServerManager { } } - @Test(dependsOnMethods = {"testApplication"}) - public void testClusterScalingUp() { - + /** + * 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) { + break; + } + } + application = ApplicationManager.getApplications().getApplication(applicationName); + if ((System.currentTimeMillis() - startTime) > CLUSTER_SCALE_UP_TIMEOUT) { + break; + } + } + } + assertEquals(String.format("Cluster did not get scaled up: [cluster-id] %s", clusterId), + clusterScaleup, true); } - - - } http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/config/ApplicationBean.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/config/ApplicationBean.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/config/ApplicationBean.java deleted file mode 100644 index ce23728..0000000 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/config/ApplicationBean.java +++ /dev/null @@ -1,25 +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.config; - -/** - * Created by reka on 5/7/15. - */ -public class ApplicationBean { -} http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/config/ApplicationConfigParser.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/config/ApplicationConfigParser.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/config/ApplicationConfigParser.java deleted file mode 100644 index ace17e6..0000000 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/config/ApplicationConfigParser.java +++ /dev/null @@ -1,25 +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.config; - -/** - * Created by reka on 5/7/15. - */ -public class ApplicationConfigParser { -} http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java index 4cd3235..ef73974 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java @@ -41,83 +41,91 @@ public class CartridgeGroupTest extends StratosTestServerManager { try { log.info("Started Cartridge group test case**************************************"); - boolean addedC1 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c4.json", + boolean addedC1 = restClient.addEntity(TEST_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"), addedC1, true); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", + "c4-cartridge-group-test"), addedC1, true); - boolean addedC2 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c5.json", + boolean addedC2 = restClient.addEntity(TEST_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"), addedC2, true); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", + "c5-cartridge-group-test"), addedC2, true); - boolean addedC3 = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c6.json", + boolean addedC3 = restClient.addEntity(TEST_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"), addedC3, true); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", + "c6-cartridge-group-test"), addedC3, true); boolean added = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + "g4-g5-g6.json", RestConstants.CARTRIDGE_GROUPS, + "/" + "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"), added, true); + "g4-g5-g6-cartridge-group-test"), added, true); + CartridgeGroupBean bean = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, "G4", + 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.json"), bean.getName(), "G4"); + "g4-g5-g6-cartridge-group-test.json"), bean.getName(), "G4-cartridge-group-test"); boolean updated = restClient.updateEntity(TEST_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + "g4-g5-g6-v1.json", + "/" + "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"), updated, true); + "g4-g5-g6-cartridge-group-test"), updated, true); + CartridgeGroupBean updatedBean = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, "G4", + 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"), updatedBean.getName(), "G4"); + "g4-g5-g6-cartridge-group-test"), updatedBean.getName(), "G4-cartridge-group-test"); - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4", + boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge can be removed while it is used in " + - "cartridge group: [cartridge-name] %s", "c4"), removedC1, false); + "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1, false); - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5", + boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s", - "c5"), removedC2, false); + "c5-cartridge-group-test"), removedC2, false); - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6", + boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s", - "c6"), removedC3, false); + "c6-cartridge-group-test"), removedC3, false); - boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G4", + boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge Group did not removed: [cartridge-group-name] %s", - "g4-g5-g6"), removed, true); + "g4-g5-g6-cartridge-group-test"), removed, true); CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, "G4", + 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"), beanRemoved, null); + "g4-g5-g6-cartridge-group-test"), beanRemoved, null); - removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4", + removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c4"), removedC1, true); + "c4-cartridge-group-test"), removedC1, true); - removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5", + removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c5"), removedC2, true); + "c5-cartridge-group-test"), removedC2, true); - removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6", + removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c6"), removedC3, true); + "c6-cartridge-group-test"), removedC3, true); log.info("Ended Cartridge group test case**************************************"); http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java index e861e12..aec70a3 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java @@ -43,7 +43,7 @@ public class CartridgeTest extends StratosTestServerManager { log.info("Started Cartridge test case**************************************"); try { - String cartridgeType = "c0"; + String cartridgeType = "c0-cartridge-test"; boolean added = restClient.addEntity(TEST_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeType + ".json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); @@ -85,7 +85,7 @@ public class CartridgeTest extends StratosTestServerManager { CartridgeBean updatedBean = (CartridgeBean) restClient. getEntity(RestConstants.CARTRIDGES, cartridgeType, CartridgeBean.class, RestConstants.CARTRIDGES_NAME); - assertEquals(updatedBean.getType(), "c0"); + assertEquals(updatedBean.getType(), "c0-cartridge-test"); assertEquals(updatedBean.getCategory(), "Data"); assertEquals(updatedBean.getHost(), "qmog.cisco.com12"); for (PropertyBean property : updatedBean.getProperty()) { http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java index 4ed2a2e..5da3d4c 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java @@ -42,16 +42,16 @@ public class ApplicationPolicyTest extends StratosTestServerManager { @Test public void testApplicationPolicy() { try { - String applicationPolicyId = "application-policy-2"; + String applicationPolicyId = "application-policy-application-policy-test"; log.info("Started Application policy test case**************************************"); boolean addedN1 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-7" + ".json", + "network-partition-application-policy-test-1" + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(addedN1, true); boolean addedN2 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-8" + ".json", + "network-partition-application-policy-test-2" + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(addedN2, true); @@ -71,17 +71,17 @@ public class ApplicationPolicyTest extends StratosTestServerManager { assertEquals(String.format("The expected networkpartitions size %s is not found in %s", 2, applicationPolicyId), bean.getNetworkPartitions().length, 2); assertEquals(String.format("The first network partition is not %s in %s", - "network-partition-7", applicationPolicyId), bean.getNetworkPartitions()[0], - "network-partition-7"); + "network-partition-application-policy-test-1", applicationPolicyId), bean.getNetworkPartitions()[0], + "network-partition-application-policy-test-1"); assertEquals(String.format("The Second network partition is not %s in %s", - "network-partition-8", applicationPolicyId), bean.getNetworkPartitions()[1], - "network-partition-8"); + "network-partition-application-policy-test-2", applicationPolicyId), bean.getNetworkPartitions()[1], + "network-partition-application-policy-test-2"); boolean algoFound = false; for (PropertyBean propertyBean : bean.getProperties()) { if (propertyBean.getName().equals("networkPartitionGroups")) { assertEquals(String.format("The networkPartitionGroups algorithm %s is not found in %s", - "network-partition-7,network-partition-8", applicationPolicyId), - propertyBean.getValue(), "network-partition-7,network-partition-8"); + "network-partition-application-policy-test-1,network-partition-application-policy-test-2", applicationPolicyId), + propertyBean.getValue(), "network-partition-application-policy-test-1,network-partition-application-policy-test-2"); algoFound = true; } @@ -92,7 +92,7 @@ public class ApplicationPolicyTest extends StratosTestServerManager { } boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-7", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); //Trying to remove the used network partition assertEquals(removedNet, false); @@ -106,20 +106,20 @@ public class ApplicationPolicyTest extends StratosTestServerManager { assertEquals(beanRemovedDep, null); boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-7", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(removedN1, true); NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-7", + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1", NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(beanRemovedN1, null); boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-8", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-application-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(removedN2, true); NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-8", + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-2", NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(beanRemovedN2, null); http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java index 96b8a57..e7f49b0 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java @@ -39,7 +39,7 @@ public class AutoscalingPolicyTest extends StratosTestServerManager { @Test public void testAutoscalingPolicy() { log.info("Started autoscaling policy test case**************************************"); - String policyId = "autoscaling-policy-c0"; + String policyId = "autoscaling-policy-autoscaling-policy-test"; try { boolean added = restClient.addEntity(TEST_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId + ".json", RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java index 9d13ca4..6f93fdc 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java @@ -41,16 +41,16 @@ public class DeploymentPolicyTest extends StratosTestServerManager { @Test public void testDeploymentPolicy() { try { - String deploymentPolicyId = "deployment-policy-2"; + String deploymentPolicyId = "deployment-policy-deployment-policy-test"; log.info("Started deployment policy test case**************************************"); boolean addedN1 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-5" + ".json", + "network-partition-deployment-policy-test-1" + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(addedN1, true); boolean addedN2 = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-6" + ".json", + "network-partition-deployment-policy-test-2" + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(addedN2, true); @@ -62,15 +62,15 @@ public class DeploymentPolicyTest extends StratosTestServerManager { DeploymentPolicyBean bean = (DeploymentPolicyBean) restClient. getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(bean.getId(), "deployment-policy-2"); + assertEquals(bean.getId(), "deployment-policy-deployment-policy-test"); assertEquals(bean.getNetworkPartitions().size(), 2); - assertEquals(bean.getNetworkPartitions().get(0).getId(), "network-partition-5"); + assertEquals(bean.getNetworkPartitions().get(0).getId(), "network-partition-deployment-policy-test-1"); assertEquals(bean.getNetworkPartitions().get(0).getPartitionAlgo(), "one-after-another"); assertEquals(bean.getNetworkPartitions().get(0).getPartitions().size(), 1); assertEquals(bean.getNetworkPartitions().get(0).getPartitions().get(0).getId(), "partition-1"); assertEquals(bean.getNetworkPartitions().get(0).getPartitions().get(0).getPartitionMax(), 20); - assertEquals(bean.getNetworkPartitions().get(1).getId(), "network-partition-6"); + assertEquals(bean.getNetworkPartitions().get(1).getId(), "network-partition-deployment-policy-test-2"); assertEquals(bean.getNetworkPartitions().get(1).getPartitionAlgo(), "round-robin"); assertEquals(bean.getNetworkPartitions().get(1).getPartitions().size(), 2); assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(0).getId(), @@ -82,7 +82,7 @@ public class DeploymentPolicyTest extends StratosTestServerManager { //update network partition boolean updated = restClient.updateEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-5-v1.json", + "network-partition-deployment-policy-test-1-v1.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(updated, true); @@ -95,9 +95,9 @@ public class DeploymentPolicyTest extends StratosTestServerManager { DeploymentPolicyBean updatedBean = (DeploymentPolicyBean) restClient. getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(updatedBean.getId(), "deployment-policy-2"); + assertEquals(updatedBean.getId(), "deployment-policy-deployment-policy-test"); assertEquals(updatedBean.getNetworkPartitions().size(), 2); - assertEquals(updatedBean.getNetworkPartitions().get(0).getId(), "network-partition-5"); + assertEquals(updatedBean.getNetworkPartitions().get(0).getId(), "network-partition-deployment-policy-test-1"); assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitionAlgo(), "one-after-another"); assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().size(), 2); assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(0).getId(), "partition-1"); @@ -105,7 +105,7 @@ public class DeploymentPolicyTest extends StratosTestServerManager { assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(1).getId(), "partition-2"); assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(1).getPartitionMax(), 20); - assertEquals(updatedBean.getNetworkPartitions().get(1).getId(), "network-partition-6"); + assertEquals(updatedBean.getNetworkPartitions().get(1).getId(), "network-partition-deployment-policy-test-2"); assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitionAlgo(), "round-robin"); assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().size(), 2); assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(0).getId(), @@ -116,7 +116,7 @@ public class DeploymentPolicyTest extends StratosTestServerManager { assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(1).getPartitionMax(), 5); boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-5", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); //Trying to remove the used network partition assertEquals(removedNet, false); @@ -130,20 +130,20 @@ public class DeploymentPolicyTest extends StratosTestServerManager { assertEquals(beanRemovedDep, null); boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-5", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(removedN1, true); NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-5", + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(beanRemovedN1, null); boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-6", RestConstants.NETWORK_PARTITIONS_NAME); + "network-partition-deployment-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(removedN2, true); NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-6", + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-2", NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); assertEquals(beanRemovedN2, null); http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java index 5df2313..dce4f0c 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java @@ -40,7 +40,7 @@ public class NetworkPartitionTest extends StratosTestServerManager { @Test public void testNetworkPartition() { try { - String networkPartitionId = "network-partition-3"; + String networkPartitionId = "network-partition-network-partition-test"; log.info("Started network partition test case**************************************"); boolean added = restClient.addEntity(TEST_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + @@ -52,7 +52,7 @@ public class NetworkPartitionTest extends StratosTestServerManager { getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(bean.getId(), "network-partition-3"); + assertEquals(bean.getId(), "network-partition-network-partition-test"); assertEquals(bean.getPartitions().size(), 1); assertEquals(bean.getPartitions().get(0).getId(), "partition-1"); assertEquals(bean.getPartitions().get(0).getProperty().get(0).getName(), "region"); @@ -66,7 +66,7 @@ public class NetworkPartitionTest extends StratosTestServerManager { NetworkPartitionBean updatedBean = (NetworkPartitionBean) restClient. getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(updatedBean.getId(), "network-partition-3"); + assertEquals(updatedBean.getId(), "network-partition-network-partition-test"); assertEquals(updatedBean.getPartitions().size(), 2); assertEquals(updatedBean.getPartitions().get(1).getId(), "partition-2"); assertEquals(updatedBean.getPartitions().get(1).getProperty().get(0).getName(), "region"); http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/IntegrationMockClient.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/IntegrationMockClient.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/IntegrationMockClient.java new file mode 100644 index 0000000..dbe21cb --- /dev/null +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/IntegrationMockClient.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.integration.tests.rest; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.stratos.mock.iaas.client.MockIaasApiClient; +import org.apache.stratos.mock.iaas.client.rest.*; +import org.apache.stratos.mock.iaas.client.rest.HttpResponse; +import org.apache.stratos.mock.iaas.client.rest.HttpResponseHandler; +import org.apache.stratos.mock.iaas.client.rest.RestClient; +import org.apache.stratos.mock.iaas.domain.*; + +import java.net.URI; + +/** + * Mock client + */ +public class IntegrationMockClient extends MockIaasApiClient { + private static final Log log = LogFactory.getLog(IntegrationMockClient.class); + private static final String INSTANCES_CONTEXT = "/instances/"; + private DefaultHttpClient httpClient; + private String endpoint; + + public IntegrationMockClient(String endpoint) { + super(endpoint); + this.endpoint = endpoint; + PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); + // Increase max total connection to 200 + cm.setMaxTotal(200); + // Increase default max connection per route to 50 + cm.setDefaultMaxPerRoute(50); + + httpClient = new DefaultHttpClient(cm); + httpClient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpClient); + } + + public void terminateInstance(String instanceId) { + try { + if (log.isDebugEnabled()) { + log.debug(String.format("Terminate instance: [instance-id] %s", instanceId)); + } + URI uri = new URIBuilder(endpoint + INSTANCES_CONTEXT + instanceId).build(); + org.apache.stratos.mock.iaas.client.rest.HttpResponse response = doDelete(uri); + if (response != null) { + if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { + return; + } else { + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + org.apache.stratos.mock.iaas.domain.ErrorResponse errorResponse = gson.fromJson(response.getContent(), org.apache.stratos.mock.iaas.domain.ErrorResponse.class); + if (errorResponse != null) { + throw new RuntimeException(errorResponse.getErrorMessage()); + } + } + } + throw new RuntimeException("An unknown error occurred"); + } catch (Exception e) { + String message = "Could not start mock instance"; + throw new RuntimeException(message, e); + } + } + + public HttpResponse doDelete(URI resourcePath) throws Exception { + HttpDelete httpDelete = null; + try { + httpDelete = new HttpDelete(resourcePath); + httpDelete.addHeader("Content-Type", "application/json"); + + return httpClient.execute(httpDelete, new HttpResponseHandler()); + } finally { + releaseConnection(httpDelete); + } + } + + private void releaseConnection(HttpRequestBase request) { + if (request != null) { + request.releaseConnection(); + } + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/f78ab824/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java index 34a9d75..79e41a2 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/rest/RestClient.java @@ -158,6 +158,7 @@ public class RestClient { HttpResponse response = doPost(uri, content); if (response != null) { + Thread.sleep(5000); if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { return true; } else {
