Introducing stratos integration test suite for the artifacts
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/5b844043 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/5b844043 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/5b844043 Branch: refs/heads/data-publisher-integration Commit: 5b844043cd0572fd2dff3e31fd7ac525ac69beac Parents: 08b9696 Author: reka <[email protected]> Authored: Thu Aug 6 16:45:23 2015 +0530 Committer: reka <[email protected]> Committed: Thu Aug 6 19:33:43 2015 +0530 ---------------------------------------------------------------------- products/stratos/modules/integration/pom.xml | 3 + .../tests/ApplicationBurstingTest.java | 37 + .../tests/ApplicationPolicyTest.java | 111 +- .../integration/tests/ApplicationTest.java | 55 +- .../tests/AutoscalingPolicyTest.java | 70 +- .../integration/tests/CartridgeGroupTest.java | 110 +- .../integration/tests/CartridgeTest.java | 116 +- .../integration/tests/DeploymentPolicyTest.java | 139 ++- .../integration/tests/NetworkPartitionTest.java | 74 +- .../integration/tests/RestConstants.java | 15 + .../tests/SampleApplicationsTest.java | 1111 +++--------------- .../tests/StratosTestServerManager.java | 6 + .../integration/tests/TopologyHandler.java | 394 +++++++ .../tests/config/ApplicationBean.java | 25 + .../tests/config/ApplicationConfigParser.java | 25 + .../integration/tests/rest/RestClient.java | 2 +- .../application-policy-2.json | 18 + .../single-cartridge-app/g-sc-G123-1-v1.json | 86 ++ .../single-cartridge-app/g-sc-G123-1-v2.json | 86 ++ .../single-cartridge-app/g-sc-G123-1-v3.json | 86 ++ .../update/g-sc-G123-1-v1.json | 86 -- .../update/g-sc-G123-1.json | 86 -- .../autoscaling-policy-c0-v1.json | 14 + .../update/autoscaling-policy-c0.json | 14 - .../cartridges-groups/cartrdige-nested-v1.json | 50 + .../cartridges-groups/g4-g5-g6-v1.json | 50 + .../resources/cartridges-groups/g4-g5-g6.json | 50 + .../update/cartrdige-nested.json | 50 - .../test/resources/cartridges/mock/c0-v1.json | 124 ++ .../src/test/resources/cartridges/mock/c4.json | 45 + .../src/test/resources/cartridges/mock/c5.json | 124 ++ .../src/test/resources/cartridges/mock/c6.json | 45 + .../resources/cartridges/mock/update/c0.json | 124 -- .../deployment-policy-1-v1.json | 36 + .../deployment-policy-2-v1.json | 36 + .../deployment-policy-2.json | 32 + .../deployment-policy-3.json | 32 + .../update/deployment-policy-1.json | 36 - .../ec2/network-partition-1.json | 19 - .../ec2/network-partition-2.json | 19 - .../gce/network-partition-1.json | 15 - .../kubernetes/network-partition-1.json | 15 - .../kubernetes/network-partition-2.json | 15 - .../kubernetes/network-partition-3.json | 15 - .../mock/network-partition-1-v1.json | 28 + .../mock/network-partition-3-v1.json | 28 + .../mock/network-partition-4.json | 15 - .../mock/network-partition-5-v1.json | 28 + .../mock/network-partition-5.json | 15 + .../mock/network-partition-6.json | 24 + .../mock/network-partition-7.json | 15 + .../mock/network-partition-8.json | 24 + .../mock/update/network-partition-1.json | 28 - .../multi/ap-southeast-1-nw-partition.json | 19 - .../multi/ap-southeast-2-nw-partition.json | 25 - .../multi/openstack-nw-partition.json | 21 - .../openstack/network-partition-1.json | 15 - .../openstack/network-partition-2.json | 15 - .../integration/src/test/resources/testng.xml | 61 + 59 files changed, 2317 insertions(+), 1745 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/pom.xml ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/pom.xml b/products/stratos/modules/integration/pom.xml index bf2c684..ca92a8b 100755 --- a/products/stratos/modules/integration/pom.xml +++ b/products/stratos/modules/integration/pom.xml @@ -117,6 +117,9 @@ <extracted.dir>stratos-parent-${project.version}</extracted.dir> <emma.home>${basedir}/target/emma</emma.home> </systemProperties> + <suiteXmlFiles> + <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> + </suiteXmlFiles> <workingDirectory>${basedir}/target</workingDirectory> </configuration> </plugin> http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationBurstingTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationBurstingTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationBurstingTest.java new file mode 100644 index 0000000..cefd786 --- /dev/null +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationBurstingTest.java @@ -0,0 +1,37 @@ +/* + * 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; + +import org.apache.stratos.common.beans.application.ApplicationBean; +import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + +/** + * This will handle the application bursting test cases + */ +public class ApplicationBurstingTest extends StratosTestServerManager { + + @Test + public void testApplication() { + assertTrue("test passes", true); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java index dafa36e..b727e82 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationPolicyTest.java @@ -21,38 +21,109 @@ package org.apache.stratos.integration.tests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.PropertyBean; +import org.apache.stratos.common.beans.partition.NetworkPartitionBean; import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean; -import org.apache.stratos.integration.tests.rest.RestClient; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; /** * Test to handle Network partition CRUD operations */ -public class ApplicationPolicyTest { +public class ApplicationPolicyTest extends StratosTestServerManager { private static final Log log = LogFactory.getLog(ApplicationPolicyTest.class); - private static final String applicationPolicies = "/application-policies/"; - private static final String applicationPoliciesUpdate = "/application-policies/update/"; - private static final String entityName = "applicationPolicy"; + @Test + public void testApplicationPolicy() { + try { + String applicationPolicyId = "application-policy-2"; + log.info("Started Application policy test case**************************************"); - public boolean addApplicationPolicy(String applicationPolicyId, RestClient restClient) { - return restClient.addEntity(applicationPolicies + "/" + applicationPolicyId, - RestConstants.APPLICATION_POLICIES, entityName); - } + boolean addedN1 = restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-7" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN1, true); - public ApplicationPolicyBean getApplicationPolicy(String applicationPolicyId, RestClient restClient) { + boolean addedN2 = restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-8" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN2, true); - return (ApplicationPolicyBean) restClient. - getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, - ApplicationPolicyBean.class, entityName); - } + boolean addedDep = restClient.addEntity(RestConstants.APPLICATION_POLICIES_PATH + "/" + + applicationPolicyId + ".json", + RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(addedDep, true); - public boolean updateApplicationPolicy(String applicationPolicyId, RestClient restClient) { - return restClient.updateEntity(applicationPoliciesUpdate + "/" + applicationPolicyId, - RestConstants.APPLICATION_POLICIES, entityName); + ApplicationPolicyBean bean = (ApplicationPolicyBean) restClient. + getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, + ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(bean.getId(), applicationPolicyId); + assertEquals(String.format("The expected algorithm %s is not found in %s", + "one-after-another", applicationPolicyId), bean.getAlgorithm(), "one-after-another"); + assertEquals(String.format("The expected id %s is not found", + applicationPolicyId), bean.getId(), applicationPolicyId); + 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"); + assertEquals(String.format("The Second network partition is not %s in %s", + "network-partition-8", applicationPolicyId), bean.getNetworkPartitions()[1], + "network-partition-8"); + 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"); + algoFound = true; - } + } + } + if (!algoFound) { + assertTrue(String.format("The networkPartitionGroups property is not found in %s", + applicationPolicyId), false); + } + + boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-7", RestConstants.NETWORK_PARTITIONS_NAME); + //Trying to remove the used network partition + assertEquals(removedNet, false); + + boolean removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, + applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(removedDep, true); + + ApplicationPolicyBean beanRemovedDep = (ApplicationPolicyBean) restClient. + getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, + ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(beanRemovedDep, null); + + boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-7", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedN1, true); + + NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-7", + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemovedN1, null); + + boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-8", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedN2, true); + + NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-8", + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemovedN2, null); + + log.info("Ended deployment policy test case**************************************"); - public boolean removeApplicationPolicy(String applicationPolicyId, RestClient restClient) { - return restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, entityName); + } catch (Exception e) { + log.error("An error occurred while handling deployment policy", e); + assertTrue("An error occurred while handling deployment policy", false); + } } } http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java index c886644..8ceec4d 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/ApplicationTest.java @@ -16,61 +16,14 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.stratos.integration.tests; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.common.beans.application.ApplicationBean; -import org.apache.stratos.integration.tests.rest.RestClient; +import org.apache.stratos.messaging.message.receiver.application.ApplicationsEventReceiver; +import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver; /** - * Test to handle application CRUD operations, deploy and undeploy + * Super class for application test cases */ -public class ApplicationTest { - private static final Log log = LogFactory.getLog(ApplicationTest.class); - String applications = "/applications/simple/single-cartridge-app/"; - String applicationsUpdate = "/applications/simple/single-cartridge-app/update/"; - private static final String entityName = "application"; - - public boolean addApplication(String applicationId, RestClient restClient) { - return restClient.addEntity(applications + "/" + applicationId, - RestConstants.APPLICATIONS, entityName); - } - - public ApplicationBean getApplication(String applicationId, - RestClient restClient) { - return (ApplicationBean) restClient. - getEntity(RestConstants.APPLICATIONS, applicationId, - ApplicationBean.class, entityName); - } - - public boolean updateApplication(String applicationId, RestClient restClient) { - return restClient.updateEntity(applicationsUpdate + "/" + applicationId, - RestConstants.APPLICATIONS, entityName); - } - - public boolean removeApplication(String applicationId, RestClient restClient) { - return restClient.removeEntity(RestConstants.APPLICATIONS, applicationId, entityName); - - } - - public boolean deployApplication(String applicationId, String applicationPolicyId, - RestClient restClient) { - return restClient.deployEntity(RestConstants.APPLICATIONS + "/" + applicationId + - RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId, entityName); - } - - public boolean undeployApplication(String applicationId, - RestClient restClient) { - return restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + applicationId + - RestConstants.APPLICATIONS_UNDEPLOY, entityName); - } - - public boolean forceUndeployApplication(String applicationId, - RestClient restClient) { - return restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + applicationId + - RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", entityName); - } +public class ApplicationTest extends StratosTestServerManager { } http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java index 1c99cad..d841552 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/AutoscalingPolicyTest.java @@ -21,37 +21,67 @@ package org.apache.stratos.integration.tests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.beans.policy.autoscale.AutoscalePolicyBean; -import org.apache.stratos.integration.tests.rest.RestClient; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; /** * Test to handle autoscaling policy CRUD operations */ -public class AutoscalingPolicyTest { +public class AutoscalingPolicyTest extends StratosTestServerManager { private static final Log log = LogFactory.getLog(AutoscalingPolicyTest.class); - private static final String autoscalingPolicy = "/autoscaling-policies/"; - private static final String autoscalingPolicyUpdate = "/autoscaling-policies/update/"; - private static final String entityName = "autoscalingPolicy"; - public boolean addAutoscalingPolicy(String autoscalingPolicyName, RestClient restClient) { - return restClient.addEntity(autoscalingPolicy + "/" + autoscalingPolicyName, - RestConstants.AUTOSCALING_POLICIES, entityName); + @Test + public void testAutoscalingPolicy() { + log.info("Started autoscaling policy test case**************************************"); + String policyId = "autoscaling-policy-c0"; + try { + boolean added = restClient.addEntity(RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId + ".json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - } + assertEquals(String.format("Autoscaling policy did not added: [autoscaling-policy-id] %s", policyId), added, true); + AutoscalePolicyBean bean = (AutoscalePolicyBean) restClient. + getEntity(RestConstants.AUTOSCALING_POLICIES, policyId, + AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); - public AutoscalePolicyBean getAutoscalingPolicy(String autoscalingPolicyName, RestClient restClient) { - return (AutoscalePolicyBean) restClient. - getEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyName, - AutoscalePolicyBean.class, entityName); - } + assertEquals(String.format("[autoscaling-policy-id] %s is not correct", bean.getId()), + bean.getId(), policyId); + assertEquals(String.format("[autoscaling-policy-id] %s RIF is not correct", policyId), + bean.getLoadThresholds().getRequestsInFlight().getThreshold(), 35.0, 0.0); + assertEquals(String.format("[autoscaling-policy-id] %s Memory is not correct", policyId), + bean.getLoadThresholds().getMemoryConsumption().getThreshold(), 45.0, 0.0); + assertEquals(String.format("[autoscaling-policy-id] %s Load is not correct", policyId), + bean.getLoadThresholds().getLoadAverage().getThreshold(), 25.0, 0.0); - public boolean updateAutoscalingPolicy(String autoscalingPolicyName, RestClient restClient) { - return restClient.updateEntity(autoscalingPolicyUpdate + "/" + autoscalingPolicyName, - RestConstants.AUTOSCALING_POLICIES, entityName); + boolean updated = restClient.updateEntity(RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId + "-v1.json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - } + assertEquals(String.format("[autoscaling-policy-id] %s update failed", policyId), updated, true); + AutoscalePolicyBean updatedBean = (AutoscalePolicyBean) restClient.getEntity( + RestConstants.AUTOSCALING_POLICIES, policyId, + AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(String.format("[autoscaling-policy-id] %s RIF is not correct", policyId), + updatedBean.getLoadThresholds().getRequestsInFlight().getThreshold(), 30.0, 0.0); + assertEquals(String.format("[autoscaling-policy-id] %s Load is not correct", policyId), + updatedBean.getLoadThresholds().getMemoryConsumption().getThreshold(), 40.0, 0.0); + assertEquals(String.format("[autoscaling-policy-id] %s Memory is not correct", policyId), + updatedBean.getLoadThresholds().getLoadAverage().getThreshold(), 20.0, 0.0); - public boolean removeAutoscalingPolicy(String autoscalingPolicyName, RestClient restClient) { - return restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyName, entityName); + boolean removed = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + policyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(String.format("[autoscaling-policy-id] %s couldn't be removed", policyId), + removed, true); + AutoscalePolicyBean beanRemoved = (AutoscalePolicyBean) restClient.getEntity( + RestConstants.AUTOSCALING_POLICIES, policyId, + AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(String.format("[autoscaling-policy-id] %s didn't get removed successfully", + policyId), beanRemoved, null); + log.info("Ended autoscaling policy test case**************************************"); + } catch (Exception e) { + log.error("An error occurred while handling [autoscaling policy] " + policyId, e); + assertTrue("An error occurred while handling [autoscaling policy] " + policyId, false); + } } } http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java index 9aae646..8bc3a9e 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeGroupTest.java @@ -22,35 +22,105 @@ package org.apache.stratos.integration.tests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean; -import org.apache.stratos.integration.tests.rest.RestClient; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; /** * Test to handle Cartridge group CRUD operations */ -public class CartridgeGroupTest { +public class CartridgeGroupTest extends StratosTestServerManager { private static final Log log = LogFactory.getLog(CartridgeGroupTest.class); - private static final String cartridgeGroups = "/cartridges-groups/"; - private static final String cartridgeGroupsUpdate = "/cartridges-groups/update/"; - private static final String entityName = "cartridgeGroup"; - public boolean addCartridgeGroup(String groupName, RestClient restClient) { - return restClient.addEntity(cartridgeGroups + "/" + groupName, - RestConstants.CARTRIDGE_GROUPS, entityName); - } + @Test + public void testCartridgeGroup() { + try { + log.info("Started Cartridge group test case**************************************"); - public CartridgeGroupBean getCartridgeGroup(String groupName, RestClient restClient) { - return (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, groupName, - CartridgeGroupBean.class, entityName); - } + boolean addedC1 = restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c4.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", "c4"), addedC1, true); - public boolean updateCartridgeGroup(String groupName, RestClient restClient) { - return restClient.updateEntity(cartridgeGroupsUpdate + "/" + groupName, - RestConstants.CARTRIDGE_GROUPS, entityName); - } + boolean addedC2 = restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c5.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", "c5"), addedC2, true); + + boolean addedC3 = restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + "c6.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", "c6"), addedC3, true); + + boolean added = restClient.addEntity(RestConstants.CARTRIDGE_GROUPS_PATH + + "/" + "g4-g5-g6.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); + CartridgeGroupBean bean = (CartridgeGroupBean) restClient. + getEntity(RestConstants.CARTRIDGE_GROUPS, "G4", + 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"); + + boolean updated = restClient.updateEntity(RestConstants.CARTRIDGE_GROUPS_PATH + + "/" + "g4-g5-g6-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); + CartridgeGroupBean updatedBean = (CartridgeGroupBean) restClient. + getEntity(RestConstants.CARTRIDGE_GROUPS, "G4", + 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"); + + boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(String.format("Cartridge can be removed while it is used in " + + "cartridge group: [cartridge-name] %s", "c4"), removedC1, false); + + boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(String.format("Cartridge can be removed while it is used in " + + "cartridge group: [cartridge-name] %s", + "c5"), removedC2, false); + + boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(String.format("Cartridge can be removed while it is used in " + + "cartridge group: [cartridge-name] %s", + "c6"), removedC3, false); + + boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G4", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(String.format("Cartridge Group did not removed: [cartridge-group-name] %s", + "g4-g5-g6"), removed, true); + + CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient. + getEntity(RestConstants.CARTRIDGE_GROUPS, "G4", + CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(String.format("Cartridge Group did not removed completely: " + + "[cartridge-group-name] %s", + "g4-g5-g6"), beanRemoved, null); + + removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", + "c4"), removedC1, true); + + removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", + "c5"), removedC2, true); + + removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", + "c6"), removedC3, true); - public boolean removeCartridgeGroup(String groupName, RestClient restClient) { - return restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, groupName, entityName); + log.info("Ended Cartridge group test case**************************************"); + } catch (Exception e) { + log.error("An error occurred while handling Cartridge group test case", e); + assertTrue("An error occurred while handling Cartridge group test case", false); + } } } http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java index 1d135dd..26eb881 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/CartridgeTest.java @@ -21,38 +21,106 @@ package org.apache.stratos.integration.tests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.PropertyBean; import org.apache.stratos.common.beans.cartridge.CartridgeBean; -import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean; -import org.apache.stratos.integration.tests.rest.RestClient; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; /** * Test to handle Cartridge CRUD operations */ -public class CartridgeTest { +public class CartridgeTest extends StratosTestServerManager { private static final Log log = LogFactory.getLog(CartridgeTest.class); - private static final String cartridges = "/cartridges/mock/"; - private static final String cartridgesUpdate = "/cartridges/mock/update/"; - private static final String entityName = "cartridge"; - - - public boolean addCartridge(String cartridgeType, RestClient restClient) { - return restClient.addEntity(cartridges + "/" + cartridgeType, - RestConstants.CARTRIDGES, entityName); - } - public CartridgeBean getCartridge(String cartridgeType, - RestClient restClient) { - return (CartridgeBean) restClient. - getEntity(RestConstants.CARTRIDGES, cartridgeType, - CartridgeBean.class, entityName); - } + @Test + public void testCartridge() { + log.info("Started Cartridge test case**************************************"); - public boolean updateCartridge(String cartridgeType, RestClient restClient) { - return restClient.updateEntity(cartridgesUpdate + "/" + cartridgeType, - RestConstants.CARTRIDGES, entityName); - } + try { + String cartridgeType = "c0"; + boolean added = restClient.addEntity(RestConstants.CARTRIDGES_PATH + "/" + + cartridgeType + ".json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(added, true); + CartridgeBean bean = (CartridgeBean) restClient. + getEntity(RestConstants.CARTRIDGES, cartridgeType, + CartridgeBean.class, RestConstants.CARTRIDGES_NAME); + assertEquals(bean.getCategory(), "Application"); + assertEquals(bean.getHost(), "qmog.cisco.com"); + for (PropertyBean property : bean.getProperty()) { + if (property.getName().equals("payload_parameter.CEP_IP")) { + assertEquals(property.getValue(), "octl.qmog.cisco.com"); + } else if (property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) { + assertEquals(property.getValue(), "admin"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) { + assertEquals(property.getValue(), "octl.qmog.cisco.com"); + } else if (property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) { + assertEquals(property.getValue(), "1"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) { + assertEquals(property.getValue(), "admin"); + } else if (property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) { + assertEquals(property.getValue(), "test"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) { + assertEquals(property.getValue(), "7711"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) { + assertEquals(property.getValue(), "7611"); + } else if (property.getName().equals("payload_parameter.CEP_PORT")) { + assertEquals(property.getValue(), "7611"); + } else if (property.getName().equals("payload_parameter.MB_PORT")) { + assertEquals(property.getValue(), "61616"); + } + } + + + boolean updated = restClient.updateEntity(RestConstants.CARTRIDGES_PATH + "/" + + cartridgeType + "-v1.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(updated, true); + CartridgeBean updatedBean = (CartridgeBean) restClient. + getEntity(RestConstants.CARTRIDGES, cartridgeType, + CartridgeBean.class, RestConstants.CARTRIDGES_NAME); + assertEquals(updatedBean.getType(), "c0"); + assertEquals(updatedBean.getCategory(), "Data"); + assertEquals(updatedBean.getHost(), "qmog.cisco.com12"); + for (PropertyBean property : updatedBean.getProperty()) { + if (property.getName().equals("payload_parameter.CEP_IP")) { + assertEquals(property.getValue(), "octl.qmog.cisco.com123"); + } else if (property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) { + assertEquals(property.getValue(), "admin123"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) { + assertEquals(property.getValue(), "octl.qmog.cisco.com123"); + } else if (property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) { + assertEquals(property.getValue(), "3"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) { + assertEquals(property.getValue(), "admin123"); + } else if (property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) { + assertEquals(property.getValue(), "test123"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) { + assertEquals(property.getValue(), "7712"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) { + assertEquals(property.getValue(), "7612"); + } else if (property.getName().equals("payload_parameter.CEP_PORT")) { + assertEquals(property.getValue(), "7612"); + } else if (property.getName().equals("payload_parameter.MB_PORT")) { + assertEquals(property.getValue(), "61617"); + } + } + + boolean removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType, + RestConstants.CARTRIDGES_NAME); + assertEquals(removed, true); + + CartridgeBean beanRemoved = (CartridgeBean) restClient. + getEntity(RestConstants.CARTRIDGES, cartridgeType, + CartridgeBean.class, RestConstants.CARTRIDGES_NAME); + assertEquals(beanRemoved, null); - public boolean removeCartridge(String cartridgeType, RestClient restClient) { - return restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType, entityName); + log.info("Ended Cartridge test case**************************************"); + } catch (Exception e) { + log.error("An error occurred while handling RESTConstants.CARTRIDGES_PATH", e); + assertTrue("An error occurred while handling RESTConstants.CARTRIDGES_PATH", false); + } } } http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java index eeb3ed9..6c1f4e0 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/DeploymentPolicyTest.java @@ -21,36 +21,133 @@ package org.apache.stratos.integration.tests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.partition.NetworkPartitionBean; import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean; -import org.apache.stratos.integration.tests.rest.RestClient; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; /** * Test to handle Deployment policy CRUD operations */ -public class DeploymentPolicyTest { +public class DeploymentPolicyTest extends StratosTestServerManager { private static final Log log = LogFactory.getLog(DeploymentPolicyTest.class); - private static final String deploymentPolicies = "/deployment-policies/"; - private static final String deploymentPoliciesUpdate = "/deployment-policies/update/"; - private static final String entityName = "deploymentPolicy"; - public boolean addDeploymentPolicy(String deploymentPolicyId, RestClient restClient) { - return restClient.addEntity(deploymentPolicies + "/" + deploymentPolicyId, - RestConstants.DEPLOYMENT_POLICIES, entityName); - } + @Test + public void testDeploymentPolicy() { + try { + String deploymentPolicyId = "deployment-policy-2"; + log.info("Started deployment policy test case**************************************"); - public DeploymentPolicyBean getDeploymentPolicy(String deploymentPolicyId, - RestClient restClient) { - return (DeploymentPolicyBean) restClient. - getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, - DeploymentPolicyBean.class, entityName); - } + boolean addedN1 = restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-5" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN1, true); - public boolean updateDeploymentPolicy(String deploymentPolicyId, RestClient restClient) { - return restClient.updateEntity(deploymentPoliciesUpdate + "/" + deploymentPolicyId, - RestConstants.DEPLOYMENT_POLICIES, entityName); - } + boolean addedN2 = restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-6" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN2, true); + + boolean addedDep = restClient.addEntity(RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + deploymentPolicyId + ".json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(addedDep, true); + + DeploymentPolicyBean bean = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(bean.getId(), "deployment-policy-2"); + assertEquals(bean.getNetworkPartitions().size(), 2); + assertEquals(bean.getNetworkPartitions().get(0).getId(), "network-partition-5"); + 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).getPartitionAlgo(), "round-robin"); + assertEquals(bean.getNetworkPartitions().get(1).getPartitions().size(), 2); + assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(0).getId(), + "network-partition-6-partition-1"); + assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(0).getPartitionMax(), 10); + assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(1).getId(), + "network-partition-6-partition-2"); + assertEquals(bean.getNetworkPartitions().get(1).getPartitions().get(1).getPartitionMax(), 9); + + //update network partition + boolean updated = restClient.updateEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-5-v1.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(updated, true); + + //update deployment policy with new partition and max values + boolean updatedDep = restClient.updateEntity(RestConstants.DEPLOYMENT_POLICIES_PATH + + "/" + deploymentPolicyId + "-v1.json", RestConstants.DEPLOYMENT_POLICIES, + RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(updatedDep, true); + + DeploymentPolicyBean updatedBean = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(updatedBean.getId(), "deployment-policy-2"); + assertEquals(updatedBean.getNetworkPartitions().size(), 2); + assertEquals(updatedBean.getNetworkPartitions().get(0).getId(), "network-partition-5"); + assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitionAlgo(), "one-after-another"); + assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().size(), 2); + assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(0).getId(), "partition-1"); + assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(0).getPartitionMax(), 25); + assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(1).getId(), "partition-2"); + assertEquals(updatedBean.getNetworkPartitions().get(0).getPartitions().get(1).getPartitionMax(), 20); + + assertEquals(updatedBean.getNetworkPartitions().get(1).getId(), "network-partition-6"); + assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitionAlgo(), "round-robin"); + assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().size(), 2); + assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(0).getId(), + "network-partition-6-partition-1"); + assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(0).getPartitionMax(), 15); + assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(1).getId(), + "network-partition-6-partition-2"); + assertEquals(updatedBean.getNetworkPartitions().get(1).getPartitions().get(1).getPartitionMax(), 5); + + boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-5", RestConstants.NETWORK_PARTITIONS_NAME); + //Trying to remove the used network partition + assertEquals(removedNet, false); + + boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(removedDep, true); + + DeploymentPolicyBean beanRemovedDep = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(beanRemovedDep, null); + + boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-5", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedN1, true); + + NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-5", + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemovedN1, null); + + boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-6", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedN2, true); + + NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-6", + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemovedN2, null); + + log.info("Ended deployment policy test case**************************************"); - public boolean removeDeploymentPolicy(String deploymentPolicyId, RestClient restClient) { - return restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, entityName); + } catch (Exception e) { + log.error("An error occurred while handling deployment policy", e); + assertTrue("An error occurred while handling deployment policy", false); + } } } http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java index 8593a09..a2ec9dc 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/NetworkPartitionTest.java @@ -22,35 +22,67 @@ package org.apache.stratos.integration.tests; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.beans.partition.NetworkPartitionBean; -import org.apache.stratos.integration.tests.rest.RestClient; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; /** * Test to handle Network partition CRUD operations */ -public class NetworkPartitionTest { +public class NetworkPartitionTest extends StratosTestServerManager { private static final Log log = LogFactory.getLog(NetworkPartitionTest.class); - private static final String networkPartitions = "/network-partitions/mock/"; - private static final String networkPartitionsUpdate = "/network-partitions/mock/update/"; - private static final String entityName = "networkPartition"; - public boolean addNetworkPartition(String networkPartitionId, RestClient restClient) { - return restClient.addEntity(networkPartitions + "/" + networkPartitionId, - RestConstants.NETWORK_PARTITIONS, entityName); - } + @Test + public void testNetworkPartition() { + try { + String networkPartitionId = "network-partition-3"; + log.info("Started network partition test case**************************************"); - public NetworkPartitionBean getNetworkPartition(String networkPartitionId, - RestClient restClient) { - return (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, - NetworkPartitionBean.class, entityName); - } + boolean added = restClient.addEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" + + networkPartitionId + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - public boolean updateNetworkPartition(String networkPartitionId, RestClient restClient) { - return restClient.updateEntity(networkPartitionsUpdate + "/" + networkPartitionId, - RestConstants.NETWORK_PARTITIONS, entityName); - } + assertEquals(added, true); + NetworkPartitionBean bean = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + + assertEquals(bean.getId(), "network-partition-3"); + assertEquals(bean.getPartitions().size(), 1); + assertEquals(bean.getPartitions().get(0).getId(), "partition-1"); + assertEquals(bean.getPartitions().get(0).getProperty().get(0).getName(), "region"); + assertEquals(bean.getPartitions().get(0).getProperty().get(0).getValue(), "default"); + + boolean updated = restClient.updateEntity(RestConstants.NETWORK_PARTITIONS_PATH + "/" + + networkPartitionId + "-v1.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + + assertEquals(updated, true); + NetworkPartitionBean updatedBean = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(updatedBean.getId(), "network-partition-3"); + assertEquals(updatedBean.getPartitions().size(), 2); + assertEquals(updatedBean.getPartitions().get(1).getId(), "partition-2"); + assertEquals(updatedBean.getPartitions().get(1).getProperty().get(0).getName(), "region"); + assertEquals(updatedBean.getPartitions().get(1).getProperty().get(0).getValue(), "default1"); + assertEquals(updatedBean.getPartitions().get(1).getProperty().get(1).getName(), "zone"); + assertEquals(updatedBean.getPartitions().get(1).getProperty().get(1).getValue(), "z1"); + + boolean removed = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removed, true); + + NetworkPartitionBean beanRemoved = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemoved, null); - public boolean removeNetworkPartition(String networkPartitionId, RestClient restClient) { - return restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, entityName); + log.info("Ended network partition test case**************************************"); + } catch (Exception e) { + log.error("An error occurred while handling network partitions", e); + assertTrue("An error occurred while handling network partitions", false); + } } } http://git-wip-us.apache.org/repos/asf/stratos/blob/5b844043/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java index 9678c4e..181aaa5 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/RestConstants.java @@ -34,4 +34,19 @@ public class RestConstants { public static final String APPLICATIONS_DEPLOY = "/deploy"; public static final String APPLICATIONS_UNDEPLOY = "/undeploy"; + public static final String AUTOSCALING_POLICIES_PATH = "/autoscaling-policies/"; + public static final String AUTOSCALING_POLICIES_NAME = "autoscalingPolicy"; + public static final String CARTRIDGE_GROUPS_PATH = "/cartridges-groups/"; + public static final String CARTRIDGE_GROUPS_NAME = "cartridgeGroup"; + public static final String CARTRIDGES_PATH = "/cartridges/mock/"; + public static final String CARTRIDGES_NAME = "cartridge"; + public static final String NETWORK_PARTITIONS_PATH = "/network-partitions/mock/"; + public static final String NETWORK_PARTITIONS_NAME = "networkPartition"; + public static final String DEPLOYMENT_POLICIES_PATH = "/deployment-policies/"; + public static final String DEPLOYMENT_POLICIES_NAME = "deploymentPolicy"; + public static final String APPLICATIONS_PATH = "/applications/simple/single-cartridge-app/"; + public static final String APPLICATIONS_NAME = "application"; + public static final String APPLICATION_POLICIES_PATH = "/application-policies/"; + public static final String APPLICATION_POLICIES_NAME = "applicationPolicy"; + }
