http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java deleted file mode 100644 index 476e993..0000000 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java +++ /dev/null @@ -1,173 +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.policies; - -import com.google.gson.reflect.TypeToken; -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.common.RestConstants; -import org.apache.stratos.integration.tests.StratosIntegrationTest; -import org.testng.annotations.Test; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -import static org.testng.AssertJUnit.*; - -/** - * Test to handle autoscaling policy CRUD operations - */ -public class AutoscalingPolicyTest extends StratosIntegrationTest { - private static final Log log = LogFactory.getLog(AutoscalingPolicyTest.class); - private static final String RESOURCES_PATH = "/autoscaling-policy-test"; - - @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) - public void testAutoscalingPolicy() { - log.info("-------------------------Started autoscaling policy test case-------------------------"); - String policyId = "autoscaling-policy-autoscaling-policy-test"; - try { - boolean added = restClient - .addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId + ".json", - RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - - assertTrue(String.format("Autoscaling policy did not added: [autoscaling-policy-id] %s", policyId), added); - AutoscalePolicyBean bean = (AutoscalePolicyBean) restClient. - getEntity(RestConstants.AUTOSCALING_POLICIES, policyId, - AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); - - 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); - - boolean updated = restClient.updateEntity( - RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId + "-v1.json", - RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - - assertTrue(String.format("[autoscaling-policy-id] %s update failed", policyId), updated); - 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); - - boolean removed = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - policyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertTrue(String.format("[autoscaling-policy-id] %s couldn't be removed", policyId), - removed); - - AutoscalePolicyBean beanRemoved = (AutoscalePolicyBean) restClient.getEntity( - RestConstants.AUTOSCALING_POLICIES, policyId, - AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); - assertNull(String.format("[autoscaling-policy-id] %s didn't get removed successfully", - policyId), beanRemoved); - 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); - } - } - - @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) - public void testAutoscalingPolicyList() { - log.info("-------------------------Started autoscaling policy list test case-------------------------"); - String policyId1 = "autoscaling-policy-autoscaling-policy-test-1"; - String policyId2 = "autoscaling-policy-autoscaling-policy-test-2"; - try { - boolean added = restClient.addEntity(RESOURCES_PATH + - RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId1 + ".json", - RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - - assertTrue(String.format("Autoscaling policy did not added: [autoscaling-policy-id] %s", - policyId1), added); - - added = restClient.addEntity(RESOURCES_PATH + - RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId2 + ".json", - RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - - assertTrue(String.format("Autoscaling policy did not added: [autoscaling-policy-id] %s", - policyId2), added); - - - Type listType = new TypeToken<ArrayList<AutoscalePolicyBean>>() { - }.getType(); - - List<AutoscalePolicyBean> autoscalingPolicyList = (List<AutoscalePolicyBean>) restClient. - listEntity(RestConstants.AUTOSCALING_POLICIES, - listType, RestConstants.AUTOSCALING_POLICIES_NAME); - assertTrue(autoscalingPolicyList.size() >= 2); - - AutoscalePolicyBean bean1 = null; - for (AutoscalePolicyBean autoscalePolicyBean : autoscalingPolicyList) { - if (autoscalePolicyBean.getId().equals(policyId1)) { - bean1 = autoscalePolicyBean; - } - } - assertNotNull(bean1); - - AutoscalePolicyBean bean2 = null; - for (AutoscalePolicyBean autoscalePolicyBean : autoscalingPolicyList) { - if (autoscalePolicyBean.getId().equals(policyId2)) { - bean2 = autoscalePolicyBean; - } - } - assertNotNull(bean2); - - - boolean removed = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - policyId1, RestConstants.AUTOSCALING_POLICIES_NAME); - assertTrue(String.format("[autoscaling-policy-id] %s couldn't be removed", policyId1), - removed); - - AutoscalePolicyBean beanRemoved = (AutoscalePolicyBean) restClient.getEntity( - RestConstants.AUTOSCALING_POLICIES, policyId1, - AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); - assertNull(String.format("[autoscaling-policy-id] %s didn't get removed successfully", - policyId1), beanRemoved); - - removed = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - policyId2, RestConstants.AUTOSCALING_POLICIES_NAME); - assertTrue(String.format("[autoscaling-policy-id] %s couldn't be removed", policyId2), - removed); - - beanRemoved = (AutoscalePolicyBean) restClient.getEntity( - RestConstants.AUTOSCALING_POLICIES, policyId2, - AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); - assertNull(String.format("[autoscaling-policy-id] %s didn't get removed successfully", - policyId2), beanRemoved); - - log.info("-------------------------Ended autoscaling policy list test case---------------------------"); - } - catch (Exception e) { - log.error("An error occurred while handling [autoscaling policy] list", e); - assertTrue("An error occurred while handling [autoscaling policy] list", false); - } - } -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java new file mode 100644 index 0000000..24da49f --- /dev/null +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.integration.tests.policies; + +import com.google.gson.reflect.TypeToken; +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.common.RestConstants; +import org.apache.stratos.integration.tests.StratosIntegrationTest; +import org.testng.annotations.Test; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import static org.testng.AssertJUnit.*; + +/** + * Test to handle autoscaling policy CRUD operations + */ +public class AutoscalingPolicyTestCase extends StratosIntegrationTest { + private static final Log log = LogFactory.getLog(AutoscalingPolicyTestCase.class); + private static final String RESOURCES_PATH = "/autoscaling-policy-test"; + + @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) + public void testAutoscalingPolicy() throws Exception { + String policyId = "autoscaling-policy-autoscaling-policy-test"; + boolean added = restClient + .addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId + ".json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); + + assertTrue(String.format("Autoscaling policy did not added: [autoscaling-policy-id] %s", policyId), added); + AutoscalePolicyBean bean = (AutoscalePolicyBean) restClient. + getEntity(RestConstants.AUTOSCALING_POLICIES, policyId, + AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); + + 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); + + boolean updated = restClient.updateEntity( + RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId + "-v1.json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); + + assertTrue(String.format("[autoscaling-policy-id] %s update failed", policyId), updated); + 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); + + boolean removed = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + policyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertTrue(String.format("[autoscaling-policy-id] %s couldn't be removed", policyId), + removed); + + AutoscalePolicyBean beanRemoved = (AutoscalePolicyBean) restClient.getEntity( + RestConstants.AUTOSCALING_POLICIES, policyId, + AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); + assertNull(String.format("[autoscaling-policy-id] %s didn't get removed successfully", + policyId), beanRemoved); + } + + @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) + public void testAutoscalingPolicyList() throws Exception { + String policyId1 = "autoscaling-policy-autoscaling-policy-test-1"; + String policyId2 = "autoscaling-policy-autoscaling-policy-test-2"; + + boolean added = restClient.addEntity(RESOURCES_PATH + + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId1 + ".json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); + + assertTrue(String.format("Autoscaling policy did not added: [autoscaling-policy-id] %s", + policyId1), added); + + added = restClient.addEntity(RESOURCES_PATH + + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId2 + ".json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); + + assertTrue(String.format("Autoscaling policy did not added: [autoscaling-policy-id] %s", + policyId2), added); + + + Type listType = new TypeToken<ArrayList<AutoscalePolicyBean>>() { + }.getType(); + + List<AutoscalePolicyBean> autoscalingPolicyList = (List<AutoscalePolicyBean>) restClient. + listEntity(RestConstants.AUTOSCALING_POLICIES, + listType, RestConstants.AUTOSCALING_POLICIES_NAME); + assertTrue(autoscalingPolicyList.size() >= 2); + + AutoscalePolicyBean bean1 = null; + for (AutoscalePolicyBean autoscalePolicyBean : autoscalingPolicyList) { + if (autoscalePolicyBean.getId().equals(policyId1)) { + bean1 = autoscalePolicyBean; + } + } + assertNotNull(bean1); + + AutoscalePolicyBean bean2 = null; + for (AutoscalePolicyBean autoscalePolicyBean : autoscalingPolicyList) { + if (autoscalePolicyBean.getId().equals(policyId2)) { + bean2 = autoscalePolicyBean; + } + } + assertNotNull(bean2); + boolean removed = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + policyId1, RestConstants.AUTOSCALING_POLICIES_NAME); + assertTrue(String.format("[autoscaling-policy-id] %s couldn't be removed", policyId1), + removed); + + AutoscalePolicyBean beanRemoved = (AutoscalePolicyBean) restClient.getEntity( + RestConstants.AUTOSCALING_POLICIES, policyId1, + AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); + assertNull(String.format("[autoscaling-policy-id] %s didn't get removed successfully", + policyId1), beanRemoved); + + removed = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + policyId2, RestConstants.AUTOSCALING_POLICIES_NAME); + assertTrue(String.format("[autoscaling-policy-id] %s couldn't be removed", policyId2), + removed); + + beanRemoved = (AutoscalePolicyBean) restClient.getEntity( + RestConstants.AUTOSCALING_POLICIES, policyId2, + AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); + assertNull(String.format("[autoscaling-policy-id] %s didn't get removed successfully", + policyId2), beanRemoved); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java deleted file mode 100644 index 3a3169a..0000000 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java +++ /dev/null @@ -1,285 +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.policies; - -import com.google.gson.reflect.TypeToken; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.common.beans.partition.NetworkPartitionReferenceBean; -import org.apache.stratos.common.beans.partition.PartitionReferenceBean; -import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean; -import org.apache.stratos.integration.common.RestConstants; -import org.apache.stratos.integration.tests.StratosIntegrationTest; -import org.testng.annotations.Test; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertTrue; - -/** - * Test to handle Deployment policy CRUD operations - */ -public class DeploymentPolicyTest extends StratosIntegrationTest { - private static final Log log = LogFactory.getLog(DeploymentPolicyTest.class); - private static final String RESOURCES_PATH = "/deployment-policy-test"; - - @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) - public void testDeploymentPolicy() { - try { - String deploymentPolicyId = "deployment-policy-deployment-policy-test"; - log.info("-------------------------Started deployment policy test case-------------------------"); - - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-deployment-policy-test-1" + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN1); - - boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-deployment-policy-test-2" + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN2); - - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - deploymentPolicyId + ".json", - RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(addedDep); - - DeploymentPolicyBean bean = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, - DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - - NetworkPartitionReferenceBean nw1 = bean.getNetworkPartitions().get(0); - NetworkPartitionReferenceBean nw2 = bean.getNetworkPartitions().get(1); - PartitionReferenceBean nw1P1 = nw1.getPartitions().get(0); - PartitionReferenceBean nw2P1 = nw2.getPartitions().get(0); - PartitionReferenceBean nw2P2 = nw2.getPartitions().get(1); - - assertEquals(bean.getId(), "deployment-policy-deployment-policy-test"); - assertEquals(bean.getNetworkPartitions().size(), 2); - assertEquals(nw1.getId(), "network-partition-deployment-policy-test-1"); - assertEquals(nw1.getPartitionAlgo(), "one-after-another"); - assertEquals(nw1.getPartitions().size(), 1); - assertEquals(nw1P1.getId(), "partition-1"); - assertEquals(nw1P1.getPartitionMax(), 20); - - assertEquals(nw2.getId(), "network-partition-deployment-policy-test-2"); - assertEquals(nw2.getPartitionAlgo(), "round-robin"); - assertEquals(nw2.getPartitions().size(), 2); - assertEquals(nw2P1.getId(), - "network-partition-6-partition-1"); - assertEquals(nw2P1.getPartitionMax(), 10); - assertEquals(nw2P2.getId(), - "network-partition-6-partition-2"); - assertEquals(nw2P2.getPartitionMax(), 9); - - //update network partition - boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-deployment-policy-test-1-v1.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(updated); - - //update deployment policy with new partition and max values - boolean updatedDep = restClient.updateEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + - "/" + deploymentPolicyId + "-v1.json", RestConstants.DEPLOYMENT_POLICIES, - RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(updatedDep); - - DeploymentPolicyBean updatedBean = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, - DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - - nw1 = updatedBean.getNetworkPartitions().get(0); - nw2 = updatedBean.getNetworkPartitions().get(1); - nw1P1 = nw1.getPartitions().get(0); - PartitionReferenceBean nw1P2 = nw1.getPartitions().get(1); - nw2P1 = nw2.getPartitions().get(0); - nw2P2 = nw2.getPartitions().get(1); - - assertEquals(updatedBean.getId(), "deployment-policy-deployment-policy-test"); - assertEquals(updatedBean.getNetworkPartitions().size(), 2); - assertEquals(nw1.getId(), "network-partition-deployment-policy-test-1"); - assertEquals(nw1.getPartitionAlgo(), "one-after-another"); - assertEquals(nw1.getPartitions().size(), 2); - assertEquals(nw1P1.getId(), "partition-1"); - assertEquals(nw1P1.getPartitionMax(), 25); - assertEquals(nw1P2.getId(), "partition-2"); - assertEquals(nw1P2.getPartitionMax(), 20); - - assertEquals(nw2.getId(), "network-partition-deployment-policy-test-2"); - assertEquals(nw2.getPartitionAlgo(), "round-robin"); - assertEquals(nw2.getPartitions().size(), 2); - assertEquals(nw2P1.getId(), - "network-partition-6-partition-1"); - assertEquals(nw2P1.getPartitionMax(), 15); - assertEquals(nw2P2.getId(), - "network-partition-6-partition-2"); - assertEquals(nw2P2.getPartitionMax(), 5); - - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - //Trying to remove the used network partition - assertFalse(removedNet); - - boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(removedDep); - - DeploymentPolicyBean beanRemovedDep = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, - DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertNull(beanRemovedDep); - - boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN1); - - DeploymentPolicyBean beanRemovedN1 = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", - DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN1); - - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-deployment-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN2); - - DeploymentPolicyBean beanRemovedN2 = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-2", - DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN2); - - log.info("-------------------------Ended deployment policy test case-------------------------"); - - } - catch (Exception e) { - log.error("An error occurred while handling deployment policy", e); - assertTrue("An error occurred while handling deployment policy", false); - } - } - - @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) - public void testDeploymentPolicyList() { - try { - String deploymentPolicyId1 = "deployment-policy-deployment-policy-test-1"; - String deploymentPolicyId2 = "deployment-policy-deployment-policy-test-2"; - - log.info("-------------------------Started deployment policy list test case-------------------------"); - - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-deployment-policy-test-1" + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN1); - - boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-deployment-policy-test-2" + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN2); - - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - deploymentPolicyId1 + ".json", - RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(addedDep); - - - addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - deploymentPolicyId2 + ".json", - RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(addedDep); - - - Type listType = new TypeToken<ArrayList<DeploymentPolicyBean>>() { - }.getType(); - - List<DeploymentPolicyBean> cartridgeList = (List<DeploymentPolicyBean>) restClient. - listEntity(RestConstants.DEPLOYMENT_POLICIES, - listType, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(cartridgeList.size() >= 2); - - DeploymentPolicyBean bean1 = null; - for (DeploymentPolicyBean deploymentPolicyBean : cartridgeList) { - if (deploymentPolicyBean.getId().equals(deploymentPolicyId1)) { - bean1 = deploymentPolicyBean; - } - } - assertNotNull(bean1); - - DeploymentPolicyBean bean2 = null; - for (DeploymentPolicyBean deploymentPolicyBean : cartridgeList) { - if (deploymentPolicyBean.getId().equals(deploymentPolicyId2)) { - bean2 = deploymentPolicyBean; - } - } - assertNotNull(bean2); - - boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - deploymentPolicyId1, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(removedDep); - - DeploymentPolicyBean beanRemovedDep = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId1, - DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertNull(beanRemovedDep); - - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - //Trying to remove the used network partition - assertFalse(removedNet); - - removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - deploymentPolicyId2, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(removedDep); - - beanRemovedDep = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId2, - DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertNull(beanRemovedDep); - - boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN1); - - DeploymentPolicyBean beanRemovedN1 = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", - DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN1); - - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-deployment-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN2); - - DeploymentPolicyBean beanRemovedN2 = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-2", - DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN2); - - log.info("-------------------------Ended deployment policy list test case-------------------------"); - - } - catch (Exception e) { - log.error("An error occurred while handling deployment policy", e); - assertTrue("An error occurred while handling deployment policy", false); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java new file mode 100644 index 0000000..866132a --- /dev/null +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java @@ -0,0 +1,261 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.integration.tests.policies; + +import com.google.gson.reflect.TypeToken; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.partition.NetworkPartitionReferenceBean; +import org.apache.stratos.common.beans.partition.PartitionReferenceBean; +import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean; +import org.apache.stratos.integration.common.RestConstants; +import org.apache.stratos.integration.tests.StratosIntegrationTest; +import org.testng.annotations.Test; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.AssertJUnit.*; + +/** + * Test to handle Deployment policy CRUD operations + */ +public class DeploymentPolicyTestCase extends StratosIntegrationTest { + private static final Log log = LogFactory.getLog(DeploymentPolicyTestCase.class); + private static final String RESOURCES_PATH = "/deployment-policy-test"; + + @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) + public void testDeploymentPolicy() throws Exception { + String deploymentPolicyId = "deployment-policy-deployment-policy-test"; + boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-deployment-policy-test-1" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(addedN1); + + boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-deployment-policy-test-2" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(addedN2); + + boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + deploymentPolicyId + ".json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(addedDep); + + DeploymentPolicyBean bean = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + + NetworkPartitionReferenceBean nw1 = bean.getNetworkPartitions().get(0); + NetworkPartitionReferenceBean nw2 = bean.getNetworkPartitions().get(1); + PartitionReferenceBean nw1P1 = nw1.getPartitions().get(0); + PartitionReferenceBean nw2P1 = nw2.getPartitions().get(0); + PartitionReferenceBean nw2P2 = nw2.getPartitions().get(1); + + assertEquals(bean.getId(), "deployment-policy-deployment-policy-test"); + assertEquals(bean.getNetworkPartitions().size(), 2); + assertEquals(nw1.getId(), "network-partition-deployment-policy-test-1"); + assertEquals(nw1.getPartitionAlgo(), "one-after-another"); + assertEquals(nw1.getPartitions().size(), 1); + assertEquals(nw1P1.getId(), "partition-1"); + assertEquals(nw1P1.getPartitionMax(), 20); + + assertEquals(nw2.getId(), "network-partition-deployment-policy-test-2"); + assertEquals(nw2.getPartitionAlgo(), "round-robin"); + assertEquals(nw2.getPartitions().size(), 2); + assertEquals(nw2P1.getId(), + "network-partition-6-partition-1"); + assertEquals(nw2P1.getPartitionMax(), 10); + assertEquals(nw2P2.getId(), + "network-partition-6-partition-2"); + assertEquals(nw2P2.getPartitionMax(), 9); + + //update network partition + boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-deployment-policy-test-1-v1.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(updated); + + //update deployment policy with new partition and max values + boolean updatedDep = restClient.updateEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + + "/" + deploymentPolicyId + "-v1.json", RestConstants.DEPLOYMENT_POLICIES, + RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(updatedDep); + + DeploymentPolicyBean updatedBean = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + + nw1 = updatedBean.getNetworkPartitions().get(0); + nw2 = updatedBean.getNetworkPartitions().get(1); + nw1P1 = nw1.getPartitions().get(0); + PartitionReferenceBean nw1P2 = nw1.getPartitions().get(1); + nw2P1 = nw2.getPartitions().get(0); + nw2P2 = nw2.getPartitions().get(1); + + assertEquals(updatedBean.getId(), "deployment-policy-deployment-policy-test"); + assertEquals(updatedBean.getNetworkPartitions().size(), 2); + assertEquals(nw1.getId(), "network-partition-deployment-policy-test-1"); + assertEquals(nw1.getPartitionAlgo(), "one-after-another"); + assertEquals(nw1.getPartitions().size(), 2); + assertEquals(nw1P1.getId(), "partition-1"); + assertEquals(nw1P1.getPartitionMax(), 25); + assertEquals(nw1P2.getId(), "partition-2"); + assertEquals(nw1P2.getPartitionMax(), 20); + + assertEquals(nw2.getId(), "network-partition-deployment-policy-test-2"); + assertEquals(nw2.getPartitionAlgo(), "round-robin"); + assertEquals(nw2.getPartitions().size(), 2); + assertEquals(nw2P1.getId(), + "network-partition-6-partition-1"); + assertEquals(nw2P1.getPartitionMax(), 15); + assertEquals(nw2P2.getId(), + "network-partition-6-partition-2"); + assertEquals(nw2P2.getPartitionMax(), 5); + + boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + //Trying to remove the used network partition + assertFalse(removedNet); + + boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(removedDep); + + DeploymentPolicyBean beanRemovedDep = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertNull(beanRemovedDep); + + boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removedN1); + + DeploymentPolicyBean beanRemovedN1 = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", + DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertNull(beanRemovedN1); + + boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-deployment-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removedN2); + + DeploymentPolicyBean beanRemovedN2 = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-2", + DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertNull(beanRemovedN2); + } + + @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) + public void testDeploymentPolicyList() throws Exception { + String deploymentPolicyId1 = "deployment-policy-deployment-policy-test-1"; + String deploymentPolicyId2 = "deployment-policy-deployment-policy-test-2"; + + boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-deployment-policy-test-1" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(addedN1); + + boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-deployment-policy-test-2" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(addedN2); + + boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + deploymentPolicyId1 + ".json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(addedDep); + + + addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + deploymentPolicyId2 + ".json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(addedDep); + + + Type listType = new TypeToken<ArrayList<DeploymentPolicyBean>>() { + }.getType(); + + List<DeploymentPolicyBean> cartridgeList = (List<DeploymentPolicyBean>) restClient. + listEntity(RestConstants.DEPLOYMENT_POLICIES, + listType, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(cartridgeList.size() >= 2); + + DeploymentPolicyBean bean1 = null; + for (DeploymentPolicyBean deploymentPolicyBean : cartridgeList) { + if (deploymentPolicyBean.getId().equals(deploymentPolicyId1)) { + bean1 = deploymentPolicyBean; + } + } + assertNotNull(bean1); + + DeploymentPolicyBean bean2 = null; + for (DeploymentPolicyBean deploymentPolicyBean : cartridgeList) { + if (deploymentPolicyBean.getId().equals(deploymentPolicyId2)) { + bean2 = deploymentPolicyBean; + } + } + assertNotNull(bean2); + + boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + deploymentPolicyId1, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(removedDep); + + DeploymentPolicyBean beanRemovedDep = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId1, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertNull(beanRemovedDep); + + boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + //Trying to remove the used network partition + assertFalse(removedNet); + + removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + deploymentPolicyId2, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(removedDep); + + beanRemovedDep = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId2, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertNull(beanRemovedDep); + + boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removedN1); + + DeploymentPolicyBean beanRemovedN1 = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", + DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertNull(beanRemovedN1); + + boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-deployment-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removedN2); + + DeploymentPolicyBean beanRemovedN2 = (DeploymentPolicyBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-2", + DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertNull(beanRemovedN2); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java deleted file mode 100644 index 04c3a38..0000000 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java +++ /dev/null @@ -1,170 +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.policies; - -import com.google.gson.reflect.TypeToken; -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.partition.PartitionBean; -import org.apache.stratos.integration.common.RestConstants; -import org.apache.stratos.integration.tests.StratosIntegrationTest; -import org.testng.annotations.Test; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -import static org.testng.Assert.assertNotNull; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertNull; -import static org.testng.AssertJUnit.assertTrue; - -/** - * Test to handle Network partition CRUD operations - */ -public class NetworkPartitionTest extends StratosIntegrationTest { - private static final Log log = LogFactory.getLog(NetworkPartitionTest.class); - private static final String RESOURCES_PATH = "/network-partition-test"; - - @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) - public void testNetworkPartition() { - try { - String networkPartitionId = "network-partition-network-partition-test"; - log.info("-------------------------Started network partition test case-------------------------"); - - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - networkPartitionId + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - - assertTrue(added); - NetworkPartitionBean bean = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, - NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - - PartitionBean p1 = bean.getPartitions().get(0); - assertEquals(bean.getId(), "network-partition-network-partition-test"); - assertEquals(bean.getPartitions().size(), 1); - assertEquals(p1.getId(), "partition-1"); - assertEquals(p1.getProperty().get(0).getName(), "region"); - assertEquals(p1.getProperty().get(0).getValue(), "default"); - - boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - networkPartitionId + "-v1.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - - assertTrue(updated); - NetworkPartitionBean updatedBean = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, - NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - - PartitionBean p2 = updatedBean.getPartitions().get(1); - assertEquals(updatedBean.getId(), "network-partition-network-partition-test"); - assertEquals(updatedBean.getPartitions().size(), 2); - assertEquals(p2.getId(), "partition-2"); - assertEquals(p2.getProperty().get(0).getName(), "region"); - assertEquals(p2.getProperty().get(0).getValue(), "default1"); - assertEquals(p2.getProperty().get(1).getName(), "zone"); - assertEquals(p2.getProperty().get(1).getValue(), "z1"); - - boolean removed = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removed); - - NetworkPartitionBean beanRemoved = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, - NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemoved); - - 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); - } - } - - @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) - public void testNetworkPartitionList() { - try { - String networkPartitionId1 = "network-partition-network-partition-test-1"; - String networkPartitionId2 = "network-partition-network-partition-test-2"; - - log.info("-------------------------Started network partition list test case-------------------------"); - - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - networkPartitionId1 + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(added); - - added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - networkPartitionId2 + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(added); - - Type listType = new TypeToken<ArrayList<NetworkPartitionBean>>() { - }.getType(); - - List<NetworkPartitionBean> cartridgeList = (List<NetworkPartitionBean>) restClient. - listEntity(RestConstants.NETWORK_PARTITIONS, - listType, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(cartridgeList.size() >= 2); - - NetworkPartitionBean bean1 = null; - for (NetworkPartitionBean networkPartitionBean : cartridgeList) { - if (networkPartitionBean.getId().equals(networkPartitionId1)) { - bean1 = networkPartitionBean; - } - } - assertNotNull(bean1); - - NetworkPartitionBean bean2 = null; - for (NetworkPartitionBean networkPartitionBean : cartridgeList) { - if (networkPartitionBean.getId().equals(networkPartitionId2)) { - bean2 = networkPartitionBean; - } - } - assertNotNull(bean2); - - - boolean removed = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - networkPartitionId1, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removed); - - NetworkPartitionBean beanRemoved = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId1, - NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemoved); - - removed = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - networkPartitionId2, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removed); - - beanRemoved = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId2, - NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemoved); - - 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/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java new file mode 100644 index 0000000..ce8e4f5 --- /dev/null +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.integration.tests.policies; + +import com.google.gson.reflect.TypeToken; +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.partition.PartitionBean; +import org.apache.stratos.integration.common.RestConstants; +import org.apache.stratos.integration.tests.StratosIntegrationTest; +import org.testng.annotations.Test; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import static org.testng.Assert.assertNotNull; +import static org.testng.AssertJUnit.*; + +/** + * Test to handle Network partition CRUD operations + */ +public class NetworkPartitionTestCase extends StratosIntegrationTest { + private static final Log log = LogFactory.getLog(NetworkPartitionTestCase.class); + private static final String RESOURCES_PATH = "/network-partition-test"; + + @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) + public void testNetworkPartition() throws Exception { + String networkPartitionId = "network-partition-network-partition-test"; + boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + networkPartitionId + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + + assertTrue(added); + NetworkPartitionBean bean = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + + PartitionBean p1 = bean.getPartitions().get(0); + assertEquals(bean.getId(), "network-partition-network-partition-test"); + assertEquals(bean.getPartitions().size(), 1); + assertEquals(p1.getId(), "partition-1"); + assertEquals(p1.getProperty().get(0).getName(), "region"); + assertEquals(p1.getProperty().get(0).getValue(), "default"); + + boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + networkPartitionId + "-v1.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + + assertTrue(updated); + NetworkPartitionBean updatedBean = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + + PartitionBean p2 = updatedBean.getPartitions().get(1); + assertEquals(updatedBean.getId(), "network-partition-network-partition-test"); + assertEquals(updatedBean.getPartitions().size(), 2); + assertEquals(p2.getId(), "partition-2"); + assertEquals(p2.getProperty().get(0).getName(), "region"); + assertEquals(p2.getProperty().get(0).getValue(), "default1"); + assertEquals(p2.getProperty().get(1).getName(), "zone"); + assertEquals(p2.getProperty().get(1).getValue(), "z1"); + + boolean removed = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removed); + + NetworkPartitionBean beanRemoved = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertNull(beanRemoved); + } + + @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"}) + public void testNetworkPartitionList() throws Exception { + String networkPartitionId1 = "network-partition-network-partition-test-1"; + String networkPartitionId2 = "network-partition-network-partition-test-2"; + boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + networkPartitionId1 + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(added); + + added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + networkPartitionId2 + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(added); + + Type listType = new TypeToken<ArrayList<NetworkPartitionBean>>() { + }.getType(); + + List<NetworkPartitionBean> cartridgeList = (List<NetworkPartitionBean>) restClient. + listEntity(RestConstants.NETWORK_PARTITIONS, + listType, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(cartridgeList.size() >= 2); + + NetworkPartitionBean bean1 = null; + for (NetworkPartitionBean networkPartitionBean : cartridgeList) { + if (networkPartitionBean.getId().equals(networkPartitionId1)) { + bean1 = networkPartitionBean; + } + } + assertNotNull(bean1); + + NetworkPartitionBean bean2 = null; + for (NetworkPartitionBean networkPartitionBean : cartridgeList) { + if (networkPartitionBean.getId().equals(networkPartitionId2)) { + bean2 = networkPartitionBean; + } + } + assertNotNull(bean2); + boolean removed = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + networkPartitionId1, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removed); + + NetworkPartitionBean beanRemoved = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId1, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertNull(beanRemoved); + + removed = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + networkPartitionId2, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removed); + + beanRemoved = (NetworkPartitionBean) restClient. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId2, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertNull(beanRemoved); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTest.java deleted file mode 100644 index 9cab5e7..0000000 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTest.java +++ /dev/null @@ -1,42 +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.users; - -import org.apache.stratos.integration.common.RestConstants; -import org.apache.stratos.integration.tests.StratosIntegrationTest; -import org.testng.annotations.Test; - -import static junit.framework.Assert.assertTrue; - -/** - * Handling users - */ -public class TenantTest extends StratosIntegrationTest { - private static final String RESOURCES_PATH = "/user-test"; - - @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"user.management", "smoke", "disabled"}) - public void addUser() { - String tenantId = "tenant-1"; - boolean addedUser1 = restClient.addEntity(RESOURCES_PATH + "/" + - tenantId + ".json", - RestConstants.USERS, RestConstants.USERS_NAME); - assertTrue(addedUser1); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java new file mode 100644 index 0000000..e64926f --- /dev/null +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java @@ -0,0 +1,42 @@ +/* + * 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.users; + +import org.apache.stratos.integration.common.RestConstants; +import org.apache.stratos.integration.tests.StratosIntegrationTest; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertTrue; + +/** + * Handling users + */ +public class TenantTestCase extends StratosIntegrationTest { + private static final String RESOURCES_PATH = "/user-test"; + + @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"user.management", "smoke", "disabled"}) + public void addUser() throws Exception { + String tenantId = "tenant-1"; + boolean addedUser1 = restClient.addEntity(RESOURCES_PATH + "/" + + tenantId + ".json", + RestConstants.USERS, RestConstants.USERS_NAME); + assertTrue(addedUser1); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTest.java deleted file mode 100644 index 3e760d8..0000000 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTest.java +++ /dev/null @@ -1,112 +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.users; - -import com.google.gson.reflect.TypeToken; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.common.beans.UserInfoBean; -import org.apache.stratos.integration.common.RestConstants; -import org.apache.stratos.integration.tests.StratosIntegrationTest; -import org.testng.annotations.Test; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -import static org.testng.AssertJUnit.*; - -/** - * Handling users - */ -public class UserTest extends StratosIntegrationTest { - private static final Log log = LogFactory.getLog(UserTest.class); - private static final String RESOURCES_PATH = "/user-test"; - - @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"user.management", "smoke"}) - public void addUser() { - try { - log.info("-------------------------------Started users test case-------------------------------"); - String userId = "user-1"; - boolean addedUser1 = restClient.addEntity(RESOURCES_PATH + "/" + - userId + ".json", - RestConstants.USERS, RestConstants.USERS_NAME); - assertTrue(addedUser1); - - Type listType = new TypeToken<ArrayList<UserInfoBean>>() { - }.getType(); - - List<UserInfoBean> userInfoBeanList = (List<UserInfoBean>) restClient.listEntity(RestConstants.USERS, - listType, RestConstants.USERS_NAME); - - UserInfoBean bean1 = null; - for (UserInfoBean userInfoBean : userInfoBeanList) { - if (userInfoBean.getUserName().equals(userId)) { - bean1 = userInfoBean; - } - } - assertNotNull(bean1); - /*assertEquals(bean1.getEmail(), "[email protected]"); - assertEquals(bean1.getFirstName(), "Frank"); - assertEquals(bean1.getRole(), "admin"); - assertEquals(bean1.getLastName(), "Myers"); - assertEquals(bean1.getCredential(), "kim12345");*/ - - boolean updatedUser1 = restClient.updateEntity(RESOURCES_PATH + "/" + - userId + "-v1.json", - RestConstants.USERS, RestConstants.USERS_NAME); - assertTrue(updatedUser1); - - userInfoBeanList = (List<UserInfoBean>) restClient.listEntity(RestConstants.USERS, - listType, RestConstants.USERS_NAME); - - for (UserInfoBean userInfoBean : userInfoBeanList) { - if (userInfoBean.getUserName().equals(userId)) { - bean1 = userInfoBean; - } - } - assertNotNull(bean1); - /*assertEquals(bean1.getEmail(), "[email protected]"); - assertEquals(bean1.getFirstName(), "Frankn"); - assertEquals(bean1.getRole(), "admin"); - assertEquals(bean1.getLastName(), "Myersn"); - assertEquals(bean1.getCredential(), "kim123456");*/ - - boolean removedUser1 = restClient.removeEntity(RestConstants.USERS, - userId, RestConstants.USERS_NAME); - assertTrue(removedUser1); - - userInfoBeanList = (List<UserInfoBean>) restClient.listEntity(RestConstants.USERS, - listType, RestConstants.USERS_NAME); - - bean1 = null; - for (UserInfoBean userInfoBean : userInfoBeanList) { - if (userInfoBean.getUserName().equals(userId)) { - bean1 = userInfoBean; - } - } - assertNull(bean1); - log.info("-------------------------Ended users test case-------------------------"); - } - catch (Exception e) { - log.error("An error occurred while handling application bursting", e); - assertTrue("An error occurred while handling application bursting", false); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java new file mode 100644 index 0000000..24d8a5b --- /dev/null +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java @@ -0,0 +1,104 @@ +/* + * 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.users; + +import com.google.gson.reflect.TypeToken; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.UserInfoBean; +import org.apache.stratos.integration.common.RestConstants; +import org.apache.stratos.integration.tests.StratosIntegrationTest; +import org.testng.annotations.Test; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import static org.testng.AssertJUnit.*; + +/** + * Handling users + */ +public class UserTestCase extends StratosIntegrationTest { + private static final Log log = LogFactory.getLog(UserTestCase.class); + private static final String RESOURCES_PATH = "/user-test"; + + @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"user.management", "smoke"}) + public void addUser() throws Exception { + String userId = "user-1"; + boolean addedUser1 = restClient.addEntity(RESOURCES_PATH + "/" + + userId + ".json", + RestConstants.USERS, RestConstants.USERS_NAME); + assertTrue(addedUser1); + + Type listType = new TypeToken<ArrayList<UserInfoBean>>() { + }.getType(); + + List<UserInfoBean> userInfoBeanList = (List<UserInfoBean>) restClient.listEntity(RestConstants.USERS, + listType, RestConstants.USERS_NAME); + + UserInfoBean bean1 = null; + for (UserInfoBean userInfoBean : userInfoBeanList) { + if (userInfoBean.getUserName().equals(userId)) { + bean1 = userInfoBean; + } + } + assertNotNull(bean1); + /*assertEquals(bean1.getEmail(), "[email protected]"); + assertEquals(bean1.getFirstName(), "Frank"); + assertEquals(bean1.getRole(), "admin"); + assertEquals(bean1.getLastName(), "Myers"); + assertEquals(bean1.getCredential(), "kim12345");*/ + + boolean updatedUser1 = restClient.updateEntity(RESOURCES_PATH + "/" + + userId + "-v1.json", + RestConstants.USERS, RestConstants.USERS_NAME); + assertTrue(updatedUser1); + + userInfoBeanList = (List<UserInfoBean>) restClient.listEntity(RestConstants.USERS, + listType, RestConstants.USERS_NAME); + + for (UserInfoBean userInfoBean : userInfoBeanList) { + if (userInfoBean.getUserName().equals(userId)) { + bean1 = userInfoBean; + } + } + assertNotNull(bean1); + /*assertEquals(bean1.getEmail(), "[email protected]"); + assertEquals(bean1.getFirstName(), "Frankn"); + assertEquals(bean1.getRole(), "admin"); + assertEquals(bean1.getLastName(), "Myersn"); + assertEquals(bean1.getCredential(), "kim123456");*/ + + boolean removedUser1 = restClient.removeEntity(RestConstants.USERS, + userId, RestConstants.USERS_NAME); + assertTrue(removedUser1); + + userInfoBeanList = (List<UserInfoBean>) restClient.listEntity(RestConstants.USERS, + listType, RestConstants.USERS_NAME); + + bean1 = null; + for (UserInfoBean userInfoBean : userInfoBeanList) { + if (userInfoBean.getUserName().equals(userId)) { + bean1 = userInfoBean; + } + } + assertNull(bean1); + } +} \ No newline at end of file
