http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java index 67c71a4..9b6eefe 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTest.java @@ -19,7 +19,6 @@ package org.apache.stratos.integration.tests.group; -import com.google.gson.reflect.TypeToken; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean; @@ -27,11 +26,9 @@ import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; import org.testng.annotations.Test; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -import static junit.framework.Assert.*; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; +import static junit.framework.Assert.assertTrue; /** * Test to handle Cartridge group CRUD operations @@ -45,222 +42,109 @@ public class CartridgeGroupTest extends StratosTestServerManager { try { log.info("-------------------------Started Cartridge group test case-------------------------"); - boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + + boolean addedC1 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c4-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", - "c4-cartridge-group-test"), addedC1); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", + "c4-cartridge-group-test"), addedC1, true); - boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + + boolean addedC2 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c5-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", - "c5-cartridge-group-test"), addedC2); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", + "c5-cartridge-group-test"), addedC2, true); - boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + + boolean addedC3 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c6-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", - "c6-cartridge-group-test"), addedC3); + assertEquals(String.format("Cartridge did not added: [cartridge-name] %s", + "c6-cartridge-group-test"), addedC3, true); - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + + boolean added = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + "/" + "g4-g5-g6-cartridge-group-test.json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s", - "g4-g5-g6-cartridge-group-test"), added); + assertEquals(String.format("Cartridge Group did not added: [cartridge-group-name] %s", + "g4-g5-g6-cartridge-group-test"), added, true); - CartridgeGroupBean bean = (CartridgeGroupBean) restClient. + CartridgeGroupBean bean = (CartridgeGroupBean) restClientTenant1. getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge Group name did not match: [cartridge-group-name] %s", "g4-g5-g6-cartridge-group-test.json"), bean.getName(), "G4-cartridge-group-test"); - boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + + CartridgeGroupBean tenant2Bean = (CartridgeGroupBean) restClientTenant2. + getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", + CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); + assertNull(String.format("Cartridge Group name fouund in tenant 2: [cartridge-group-name] %s", + bean.getName()),tenant2Bean); + + boolean updated = restClientTenant1.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + "/" + "g4-g5-g6-cartridge-group-test-v1.json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge Group did not updated: [cartridge-group-name] %s", - "g4-g5-g6-cartridge-group-test"), updated); + assertEquals(String.format("Cartridge Group did not updated: [cartridge-group-name] %s", + "g4-g5-g6-cartridge-group-test"), updated, true); - CartridgeGroupBean updatedBean = (CartridgeGroupBean) restClient. + CartridgeGroupBean updatedBean = (CartridgeGroupBean) restClientTenant1. getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Updated Cartridge Group didn't match: [cartridge-group-name] %s", "g4-g5-g6-cartridge-group-test"), updatedBean.getName(), "G4-cartridge-group-test"); - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", + updatedBean = (CartridgeGroupBean) restClientTenant2. + getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", + CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); + assertNull(String.format("Updated Cartridge Group found in other tenant: [cartridge-group-name] %s", + "g4-g5-g6-cartridge-group-test"), updatedBean); + + boolean removedC1 = restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); - assertFalse(String.format("Cartridge can be removed while it is used in " + - "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1); + assertEquals(String.format("Cartridge can be removed while it is used in " + + "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1, false); - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", + boolean removedC2 = restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); - assertFalse(String.format("Cartridge can be removed while it is used in " + + assertEquals(String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s", - "c5-cartridge-group-test"), removedC2); + "c5-cartridge-group-test"), removedC2, false); - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", + boolean removedC3 = restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); - assertFalse(String.format("Cartridge can be removed while it is used in " + + assertEquals(String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s", - "c6-cartridge-group-test"), removedC3); + "c6-cartridge-group-test"), removedC3, false); - boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", + boolean removed = restClientTenant1.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s", - "g4-g5-g6-cartridge-group-test"), removed); + assertEquals(String.format("Cartridge Group did not removed: [cartridge-group-name] %s", + "g4-g5-g6-cartridge-group-test"), removed, true); - CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient. + CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClientTenant1. getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); assertEquals(String.format("Cartridge Group did not removed completely: " + "[cartridge-group-name] %s", "g4-g5-g6-cartridge-group-test"), beanRemoved, null); - removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", + removedC1 = restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c4-cartridge-group-test"), removedC1); + assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", + "c4-cartridge-group-test"), removedC1, true); - removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", + removedC2 = restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c5-cartridge-group-test"), removedC2); + assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", + "c5-cartridge-group-test"), removedC2, true); - removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", + removedC3 = restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c6-cartridge-group-test"), removedC3); + assertEquals(String.format("Cartridge can not be removed : [cartridge-name] %s", + "c6-cartridge-group-test"), removedC3, true); log.info("-------------------------Ended Cartridge group test case-------------------------"); } catch (Exception e) { log.error("An error occurred while handling Cartridge group test case", e); - assertFalse("An error occurred while handling Cartridge group test case", false); - } - } - - @Test - public void testCartridgeGroupList() { - try { - log.info("-------------------------Started Cartridge group list test case-------------------------"); - - boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + - "/" + "c4-cartridge-group-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", - "c4-cartridge-group-test"), addedC1); - - boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + - "/" + "c5-cartridge-group-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", - "c5-cartridge-group-test"), addedC2); - - boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + - "/" + "c6-cartridge-group-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", - "c6-cartridge-group-test"), addedC3); - - String group1 = "group-1-cartridge-group-test"; - String group2 = "group-2-cartridge-group-test"; - - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + group1 + ".json", RestConstants.CARTRIDGE_GROUPS, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s", - group1), added); - - added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + group2 + ".json", RestConstants.CARTRIDGE_GROUPS, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s", - group1), added); - - Type listType = new TypeToken<ArrayList<CartridgeGroupBean>>() { - }.getType(); - - List<CartridgeGroupBean> cartridgeGroupList = (List<CartridgeGroupBean>) restClient. - listEntity(RestConstants.CARTRIDGE_GROUPS, - listType, RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(cartridgeGroupList.size() >= 2); - - CartridgeGroupBean bean1 = null; - for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) { - if (cartridgeGroupBean.getName().equals(group1)) { - bean1 = cartridgeGroupBean; - } - } - assertNotNull(bean1); - - CartridgeGroupBean bean2 = null; - for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) { - if (cartridgeGroupBean.getName().equals(group2)) { - bean2 = cartridgeGroupBean; - } - } - assertNotNull(bean2); - - boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, group1, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s", - group1), removed); - - CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, group1, - CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); - assertNull(String.format("Cartridge Group did not removed completely: " + - "[cartridge-group-name] %s", - group1), beanRemoved); - - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertFalse(String.format("Cartridge can be removed while it is used in " + - "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1); - - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertFalse(String.format("Cartridge can be removed while it is used in " + - "cartridge group: [cartridge-name] %s", - "c5-cartridge-group-test"), removedC2); - - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertFalse(String.format("Cartridge can be removed while it is used in " + - "cartridge group: [cartridge-name] %s", - "c6-cartridge-group-test"), removedC3); - - removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, group2, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s", - group2), removed); - - beanRemoved = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, group2, - CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); - assertNull(String.format("Cartridge Group did not removed completely: " + - "[cartridge-group-name] %s", - group2), beanRemoved); - - removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c4-cartridge-group-test"), removedC1); - - removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c5-cartridge-group-test"), removedC2); - - removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", - "c6-cartridge-group-test"), removedC3); - - log.info("-------------------------Ended Cartridge group list test case-------------------------"); - } catch (Exception e) { - log.error("An error occurred while handling Cartridge list group test case", e); - assertFalse("An error occurred while handling Cartridge list group test case", false); + assertTrue("An error occurred while handling Cartridge group test case", false); } } }
http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java index 571b261..afbdc1a 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTest.java @@ -19,7 +19,6 @@ package org.apache.stratos.integration.tests.group; -import com.google.gson.reflect.TypeToken; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.beans.PropertyBean; @@ -28,10 +27,6 @@ import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; import org.testng.annotations.Test; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - import static junit.framework.Assert.*; /** @@ -48,15 +43,15 @@ public class CartridgeTest extends StratosTestServerManager { try { String cartridgeType = "c0-cartridge-test"; - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + + boolean added = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeType + ".json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(added); - CartridgeBean bean = (CartridgeBean) restClient. + assertEquals(added, true); + CartridgeBean bean = (CartridgeBean) restClientTenant1. 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"); @@ -80,13 +75,15 @@ public class CartridgeTest extends StratosTestServerManager { assertEquals(property.getValue(), "61616"); } } - - - boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + + bean = (CartridgeBean) restClientTenant2. + getEntity(RestConstants.CARTRIDGES, cartridgeType, + CartridgeBean.class, RestConstants.CARTRIDGES_NAME); + assertNull("Cartridge exists in other tenant", bean); + boolean updated = restClientTenant1.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeType + "-v1.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(updated); - CartridgeBean updatedBean = (CartridgeBean) restClient. + assertEquals(updated, true); + CartridgeBean updatedBean = (CartridgeBean) restClientTenant1. getEntity(RestConstants.CARTRIDGES, cartridgeType, CartridgeBean.class, RestConstants.CARTRIDGES_NAME); assertEquals(updatedBean.getType(), "c0-cartridge-test"); @@ -116,84 +113,79 @@ public class CartridgeTest extends StratosTestServerManager { } } - boolean removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType, - RestConstants.CARTRIDGES_NAME); - assertTrue(removed); - - CartridgeBean beanRemoved = (CartridgeBean) restClient. + bean = (CartridgeBean) restClientTenant2. getEntity(RestConstants.CARTRIDGES, cartridgeType, CartridgeBean.class, RestConstants.CARTRIDGES_NAME); - assertNull(beanRemoved); - - 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); - } - } - - @Test - public void testCartridgeList() { - log.info("--------------------Started Cartridge list test case-----------------------------"); + assertNull("Cartridge exists in other tenant", bean); - try { - String cartridgeType1 = "c1-cartridge-test"; - String cartridgeType2 = "c2-cartridge-test"; - boolean added1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + - cartridgeType1 + ".json", + added = restClientTenant2.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + + cartridgeType + ".json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(added1); + assertEquals(added, true); - boolean added2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + - cartridgeType2 + ".json", + updated = restClientTenant2.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + + cartridgeType + "-v1.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(added2); - - Type listType = new TypeToken<ArrayList<CartridgeBean>>() { - }.getType(); - - List<CartridgeBean> cartridgeList = (List<CartridgeBean>) restClient.listEntity(RestConstants.CARTRIDGES, - listType, RestConstants.CARTRIDGES_NAME); - assertTrue(cartridgeList.size() >= 2); - - CartridgeBean bean1 = null; - for (CartridgeBean cartridgeBean : cartridgeList) { - if (cartridgeBean.getType().equals(cartridgeType1)) { - bean1 = cartridgeBean; - } - } - assertNotNull(bean1); + assertEquals(updated, true); - CartridgeBean bean2 = null; - for (CartridgeBean cartridgeBean : cartridgeList) { - if (cartridgeBean.getType().equals(cartridgeType1)) { - bean2 = cartridgeBean; + updatedBean = (CartridgeBean) restClientTenant2. + getEntity(RestConstants.CARTRIDGES, cartridgeType, + CartridgeBean.class, RestConstants.CARTRIDGES_NAME); + assertEquals(updatedBean.getType(), "c0-cartridge-test"); + assertEquals(updatedBean.getCategory(), "Data"); + assertEquals(updatedBean.getHost(), "qmog.cisco.com12"); + for (PropertyBean property : updatedBean.getProperty()) { + if (property.getName().equals("payload_parameter.CEP_IP")) { + assertEquals(property.getValue(), "octl.qmog.cisco.com123"); + } else if (property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) { + assertEquals(property.getValue(), "admin123"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) { + assertEquals(property.getValue(), "octl.qmog.cisco.com123"); + } else if (property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) { + assertEquals(property.getValue(), "3"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) { + assertEquals(property.getValue(), "admin123"); + } else if (property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) { + assertEquals(property.getValue(), "test123"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) { + assertEquals(property.getValue(), "7712"); + } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) { + assertEquals(property.getValue(), "7612"); + } else if (property.getName().equals("payload_parameter.CEP_PORT")) { + assertEquals(property.getValue(), "7612"); + } else if (property.getName().equals("payload_parameter.MB_PORT")) { + assertEquals(property.getValue(), "61617"); } } - assertNotNull(bean2); - - boolean removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType1, + boolean removed = restClientTenant1.removeEntity(RestConstants.CARTRIDGES, cartridgeType, RestConstants.CARTRIDGES_NAME); - assertTrue(removed); + assertEquals(removed, true); - CartridgeBean beanRemoved = (CartridgeBean) restClient. - getEntity(RestConstants.CARTRIDGES, cartridgeType1, + bean = (CartridgeBean) restClientTenant2. + getEntity(RestConstants.CARTRIDGES, cartridgeType, + CartridgeBean.class, RestConstants.CARTRIDGES_NAME); + assertNotNull("Cartridge not exists in other tenant", bean); + + CartridgeBean beanRemoved = (CartridgeBean) restClientTenant1. + getEntity(RestConstants.CARTRIDGES, cartridgeType, CartridgeBean.class, RestConstants.CARTRIDGES_NAME); assertEquals(beanRemoved, null); - removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType2, + removed = restClientTenant2.removeEntity(RestConstants.CARTRIDGES, cartridgeType, RestConstants.CARTRIDGES_NAME); - assertTrue(removed); + assertEquals(removed, true); - beanRemoved = (CartridgeBean) restClient. - getEntity(RestConstants.CARTRIDGES, cartridgeType2, + beanRemoved = (CartridgeBean) restClientTenant2. + getEntity(RestConstants.CARTRIDGES, cartridgeType, CartridgeBean.class, RestConstants.CARTRIDGES_NAME); - assertNull(beanRemoved); + assertEquals(beanRemoved, null); + + - log.info("---------------------------Ended Cartridge list test case-------------------------"); + log.info("---------------------------Ended Cartridge test case-------------------------"); } catch (Exception e) { - log.error("An error occurred while handling Cartridges list", e); - assertTrue("An error occurred while handling Cartridges list", false); + 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/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java index 656abc5..6800200 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTest.java @@ -19,7 +19,6 @@ 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.PropertyBean; @@ -29,10 +28,6 @@ import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; import org.testng.annotations.Test; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - import static junit.framework.Assert.*; /** @@ -49,22 +44,22 @@ public class ApplicationPolicyTest extends StratosTestServerManager { String applicationPolicyId = "application-policy-application-policy-test"; log.info("-------------------------Started Application policy test case-------------------------"); - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean addedN1 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + "network-partition-application-policy-test-1" + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN1); + assertEquals(addedN1, true); - boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean addedN2 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + "network-partition-application-policy-test-2" + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN2); + assertEquals(addedN2, true); - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + + boolean addedDep = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + applicationPolicyId + ".json", RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(addedDep); + assertEquals(addedDep, true); - ApplicationPolicyBean bean = (ApplicationPolicyBean) restClient. + ApplicationPolicyBean bean = (ApplicationPolicyBean) restClientTenant1. getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); assertEquals(bean.getId(), applicationPolicyId); @@ -91,141 +86,99 @@ public class ApplicationPolicyTest extends StratosTestServerManager { } } if (!algoFound) { - assertNull(String.format("The networkPartitionGroups property is not found in %s", - applicationPolicyId)); + assertTrue(String.format("The networkPartitionGroups property is not found in %s", + applicationPolicyId), false); } - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + bean = (ApplicationPolicyBean) restClientTenant2. + getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, + ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); + assertNull("Application policy bean found in tenant 2",bean); + + addedN1 = restClientTenant2.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-application-policy-test-1" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN1, true); + + addedN2 = restClientTenant2.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-application-policy-test-2" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN2, true); + + boolean addedTenant2Dep = restClientTenant2.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + + applicationPolicyId + ".json", + RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(addedTenant2Dep, true); + + ApplicationPolicyBean tenant2bean = (ApplicationPolicyBean) restClientTenant2. + getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, + ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); + assertNotNull("Application is not exist in tenant 2", tenant2bean); + + + boolean removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); //Trying to remove the used network partition - assertFalse(removedNet); + assertEquals(removedNet, false); - boolean removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, + boolean removedDep = restClientTenant1.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(removedDep); + assertEquals(removedDep, true); - ApplicationPolicyBean beanRemovedDep = (ApplicationPolicyBean) restClient. + ApplicationPolicyBean beanRemovedDep = (ApplicationPolicyBean) restClientTenant1. getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); - assertNull(beanRemovedDep); + assertEquals(beanRemovedDep, null); - boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + boolean removedN1 = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN1); + assertEquals(removedN1, true); - NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClient. + NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClientTenant1. getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1", NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN1); + assertEquals(beanRemovedN1, null); - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + boolean removedN2 = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN2); + assertEquals(removedN2, true); - NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClient. + NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClientTenant1. getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-2", NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN2); + assertEquals(beanRemovedN2, null); - log.info("-------------------------Ended deployment policy test case-------------------------"); - - } catch (Exception e) { - log.error("An error occurred while handling deployment policy", e); - assertTrue("An error occurred while handling deployment policy", false); - } - } - - @Test - public void testApplicationPolicyList() { - try { - String applicationPolicyId1 = "application-policy-application-policy-test-1"; - String applicationPolicyId2 = "application-policy-application-policy-test-2"; - log.info("-------------------------Started Application policy list test case-------------------------"); - - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-application-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-application-policy-test-2" + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN2); - - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + - applicationPolicyId1 + ".json", - RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(addedDep); - - addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + - applicationPolicyId2 + ".json", - RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(addedDep); - - Type listType = new TypeToken<ArrayList<ApplicationPolicyBean>>() { - }.getType(); - - List<ApplicationPolicyBean> applicationPolicyList = (List<ApplicationPolicyBean>) restClient. - listEntity(RestConstants.APPLICATION_POLICIES, - listType, RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(applicationPolicyList.size() >= 2); - - ApplicationPolicyBean bean1 = null; - for (ApplicationPolicyBean applicationPolicyBean : applicationPolicyList) { - if (applicationPolicyBean.getId().equals(applicationPolicyId1)) { - bean1 = applicationPolicyBean; - } - } - assertNotNull(bean1); - - ApplicationPolicyBean bean2 = null; - for (ApplicationPolicyBean applicationPolicyBean : applicationPolicyList) { - if (applicationPolicyBean.getId().equals(applicationPolicyId2)) { - bean2 = applicationPolicyBean; - } - } - assertNotNull(bean2); - - boolean removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, - applicationPolicyId1, RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(removedDep); - - ApplicationPolicyBean beanRemovedDep = (ApplicationPolicyBean) restClient. - getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId1, + tenant2bean = (ApplicationPolicyBean) restClientTenant2. + getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); - assertNull(beanRemovedDep); - - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - //Trying to remove the used network partition - assertFalse(removedNet); + assertNotNull("Application is not exist in tenant 2", tenant2bean); - removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, - applicationPolicyId2, RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(removedDep); + removedDep = restClientTenant2.removeEntity(RestConstants.APPLICATION_POLICIES, + applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(removedDep, true); - beanRemovedDep = (ApplicationPolicyBean) restClient. - getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId2, + beanRemovedDep = (ApplicationPolicyBean) restClientTenant2. + getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME); - assertNull(beanRemovedDep); + assertEquals(beanRemovedDep, null); - boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + removedN1 = restClientTenant2.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN1); + assertEquals(removedN1, true); - NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClient. + beanRemovedN1 = (NetworkPartitionBean) restClientTenant2. getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1", NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN1); + assertEquals(beanRemovedN1, null); - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + removedN2 = restClientTenant2.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN2); + assertEquals(removedN2, true); - NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClient. + beanRemovedN2 = (NetworkPartitionBean) restClientTenant2. getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-2", NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN2); + assertEquals(beanRemovedN2, null); log.info("-------------------------Ended deployment policy test case-------------------------"); http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java index a615d98..895e5f6 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTest.java @@ -18,7 +18,6 @@ */ 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; @@ -26,10 +25,6 @@ import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; import org.testng.annotations.Test; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - import static junit.framework.Assert.*; /** @@ -45,11 +40,33 @@ public class AutoscalingPolicyTest extends StratosTestServerManager { 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", + boolean added = restClientTenant1.addEntity(RESOURCES_PATH + 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) restClientTenant1. + 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); + + bean = (AutoscalePolicyBean) restClientTenant2. + getEntity(RestConstants.AUTOSCALING_POLICIES, policyId, + AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); + assertNull("Auto scale policy exists for other tenant",bean); + + boolean addedTenant2 = restClientTenant2.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. + assertEquals(String.format("Autoscaling policy did not added: [autoscaling-policy-id] %s", policyId), addedTenant2, true); + bean = (AutoscalePolicyBean) restClientTenant2. getEntity(RestConstants.AUTOSCALING_POLICIES, policyId, AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); @@ -62,11 +79,11 @@ public class AutoscalingPolicyTest extends StratosTestServerManager { 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", + boolean updated = restClientTenant1.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( + assertEquals(String.format("[autoscaling-policy-id] %s update failed", policyId), updated, true); + AutoscalePolicyBean updatedBean = (AutoscalePolicyBean) restClientTenant1.getEntity( RestConstants.AUTOSCALING_POLICIES, policyId, AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); assertEquals(String.format("[autoscaling-policy-id] %s RIF is not correct", policyId), @@ -76,95 +93,46 @@ public class AutoscalingPolicyTest extends StratosTestServerManager { 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); + boolean updatedTenant2 = restClientTenant2.updateEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + policyId + "-v1.json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - AutoscalePolicyBean beanRemoved = (AutoscalePolicyBean) restClient.getEntity( + assertEquals(String.format("[autoscaling-policy-id] %s update failed", policyId), updatedTenant2, true); + AutoscalePolicyBean updatedTenant2Bean = (AutoscalePolicyBean) restClientTenant2.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 - 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); + assertEquals(String.format("[autoscaling-policy-id] %s RIF is not correct", policyId), + updatedTenant2Bean.getLoadThresholds().getRequestsInFlight().getThreshold(), 30.0, 0.0); + assertEquals(String.format("[autoscaling-policy-id] %s Load is not correct", policyId), + updatedTenant2Bean.getLoadThresholds().getMemoryConsumption().getThreshold(), 40.0, 0.0); + assertEquals(String.format("[autoscaling-policy-id] %s Memory is not correct", policyId), + updatedTenant2Bean.getLoadThresholds().getLoadAverage().getThreshold(), 20.0, 0.0); - 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); + boolean removed = restClientTenant1.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, policyId1, + AutoscalePolicyBean beanRemoved = (AutoscalePolicyBean) restClientTenant1.getEntity( + RestConstants.AUTOSCALING_POLICIES, policyId, 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); + assertEquals(String.format("[autoscaling-policy-id] %s didn't get removed successfully", + policyId), beanRemoved, null); - beanRemoved = (AutoscalePolicyBean) restClient.getEntity( - RestConstants.AUTOSCALING_POLICIES, policyId2, + beanRemoved = (AutoscalePolicyBean) restClientTenant2.getEntity( + RestConstants.AUTOSCALING_POLICIES, policyId, AutoscalePolicyBean.class, RestConstants.AUTOSCALING_POLICIES_NAME); - assertNull(String.format("[autoscaling-policy-id] %s didn't get removed successfully", - policyId2), beanRemoved); + assertNotNull("Auto scale policy not exist in other tenant",beanRemoved); + + removed = restClientTenant2.removeEntity(RestConstants.AUTOSCALING_POLICIES, + policyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(String.format("[autoscaling-policy-id] %s couldn't be removed", policyId), + removed, true); - log.info("-------------------------Ended autoscaling policy list test case---------------------------"); + log.info("-------------------------Ended autoscaling policy 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); + 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/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java index 34e398b..b784baf 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTest.java @@ -19,9 +19,9 @@ 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.NetworkPartitionReferenceBean; import org.apache.stratos.common.beans.partition.PartitionReferenceBean; import org.apache.stratos.common.beans.policy.deployment.DeploymentPolicyBean; @@ -29,10 +29,6 @@ import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; import org.testng.annotations.Test; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - import static junit.framework.Assert.*; /** @@ -49,22 +45,22 @@ public class DeploymentPolicyTest extends StratosTestServerManager { String deploymentPolicyId = "deployment-policy-deployment-policy-test"; log.info("-------------------------Started deployment policy test case-------------------------"); - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean addedN1 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + "network-partition-deployment-policy-test-1" + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN1); + assertEquals(addedN1, true); - boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean addedN2 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + "network-partition-deployment-policy-test-2" + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN2); + assertEquals(addedN2, true); - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + boolean addedDep = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + deploymentPolicyId + ".json", RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(addedDep); + assertEquals(addedDep, true); - DeploymentPolicyBean bean = (DeploymentPolicyBean) restClient. + DeploymentPolicyBean bean = (DeploymentPolicyBean) restClientTenant1. getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); @@ -93,18 +89,18 @@ public class DeploymentPolicyTest extends StratosTestServerManager { assertEquals(nw2P2.getPartitionMax(), 9); //update network partition - boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean updated = restClientTenant1.updateEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + "network-partition-deployment-policy-test-1-v1.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(updated); + assertEquals(updated, true); //update deployment policy with new partition and max values - boolean updatedDep = restClient.updateEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + + boolean updatedDep = restClientTenant1.updateEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + deploymentPolicyId + "-v1.json", RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(updatedDep); + assertEquals(updatedDep, true); - DeploymentPolicyBean updatedBean = (DeploymentPolicyBean) restClient. + DeploymentPolicyBean updatedBean = (DeploymentPolicyBean) restClientTenant1. getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); @@ -135,143 +131,96 @@ public class DeploymentPolicyTest extends StratosTestServerManager { "network-partition-6-partition-2"); assertEquals(nw2P2.getPartitionMax(), 5); - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + updatedBean = (DeploymentPolicyBean) restClientTenant2. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertNull("Deployment policy found in tenant 2",updatedBean); + + addedN1 = restClientTenant2.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-deployment-policy-test-1" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN1, true); + + addedN2 = restClientTenant2.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-deployment-policy-test-2" + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN2, true); + + addedDep = restClientTenant2.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + deploymentPolicyId + ".json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(addedDep, true); + + bean = (DeploymentPolicyBean) restClientTenant2. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, + DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertNotNull("Deployment policy not exist in other tenant",bean); + + boolean removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); //Trying to remove the used network partition - assertFalse(removedNet); + assertEquals(removedNet, false); - boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + boolean removedDep = restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(removedDep); + assertEquals(removedDep, true); - DeploymentPolicyBean beanRemovedDep = (DeploymentPolicyBean) restClient. + DeploymentPolicyBean beanRemovedDep = (DeploymentPolicyBean) restClientTenant1. getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertNull(beanRemovedDep); + assertEquals(beanRemovedDep, null); - boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + boolean removedN1 = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN1); + assertEquals(removedN1, true); - DeploymentPolicyBean beanRemovedN1 = (DeploymentPolicyBean) restClient. + NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClientTenant1. getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", - DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN1); + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemovedN1, null); - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + boolean removedN2 = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN2); + assertEquals(removedN2, true); - DeploymentPolicyBean beanRemovedN2 = (DeploymentPolicyBean) restClient. + NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClientTenant1. 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 - 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); + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemovedN2, null); - 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, + bean = (DeploymentPolicyBean) restClientTenant2. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertNull(beanRemovedDep); + assertNotNull("Deployment policy not exist in other tenant",bean); - 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); + removedDep = restClientTenant2.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(removedDep, true); - beanRemovedDep = (DeploymentPolicyBean) restClient. - getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId2, + beanRemovedDep = (DeploymentPolicyBean) restClientTenant2. + getEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId, DeploymentPolicyBean.class, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertNull(beanRemovedDep); + assertEquals(beanRemovedDep, null); - boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + removedN1 = restClientTenant2.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN1); + assertEquals(removedN1, true); - DeploymentPolicyBean beanRemovedN1 = (DeploymentPolicyBean) restClient. + beanRemovedN1 = (NetworkPartitionBean) restClientTenant2. getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-1", - DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN1); + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemovedN1, null); - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + removedN2 = restClientTenant2.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN2); + assertEquals(removedN2, true); - DeploymentPolicyBean beanRemovedN2 = (DeploymentPolicyBean) restClient. + beanRemovedN2 = (NetworkPartitionBean) restClientTenant2. getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-deployment-policy-test-2", - DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemovedN2); + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemovedN2, null); - log.info("-------------------------Ended deployment policy list test case-------------------------"); + log.info("-------------------------Ended deployment policy test case-------------------------"); } catch (Exception e) { log.error("An error occurred while handling deployment policy", e); http://git-wip-us.apache.org/repos/asf/stratos/blob/1afe6ae4/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java index 6f0f928..de5c4fd 100644 --- a/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java +++ b/products/stratos/modules/integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTest.java @@ -19,7 +19,6 @@ 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; @@ -28,10 +27,6 @@ import org.apache.stratos.integration.tests.RestConstants; import org.apache.stratos.integration.tests.StratosTestServerManager; import org.testng.annotations.Test; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - import static junit.framework.Assert.*; /** @@ -48,12 +43,12 @@ public class NetworkPartitionTest extends StratosTestServerManager { String networkPartitionId = "network-partition-network-partition-test"; log.info("-------------------------Started network partition test case-------------------------"); - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean added = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + networkPartitionId + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(added); - NetworkPartitionBean bean = (NetworkPartitionBean) restClient. + assertEquals(added, true); + NetworkPartitionBean bean = (NetworkPartitionBean) restClientTenant1. getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); @@ -64,12 +59,12 @@ public class NetworkPartitionTest extends StratosTestServerManager { assertEquals(p1.getProperty().get(0).getName(), "region"); assertEquals(p1.getProperty().get(0).getValue(), "default"); - boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + boolean updated = restClientTenant1.updateEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + networkPartitionId + "-v1.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(updated); - NetworkPartitionBean updatedBean = (NetworkPartitionBean) restClient. + assertEquals(updated, true); + NetworkPartitionBean updatedBean = (NetworkPartitionBean) restClientTenant1. getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); @@ -82,82 +77,43 @@ public class NetworkPartitionTest extends StratosTestServerManager { 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. + updatedBean = (NetworkPartitionBean) restClientTenant2. getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemoved); + assertNull("Network partition found in tenant 2",updatedBean); - 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); - } - } + added = restClientTenant2.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + networkPartitionId + ".json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - @Test - public void testNetworkPartitionList() { - try { - String networkPartitionId1 = "network-partition-network-partition-test-1"; - String networkPartitionId2 = "network-partition-network-partition-test-2"; + assertEquals(added, true); + bean = (NetworkPartitionBean) restClientTenant2. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertNotNull("Network partition not exist in other tenant",bean); - log.info("-------------------------Started network partition list test case-------------------------"); + boolean removed = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS, + networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removed, true); - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - networkPartitionId1 + ".json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(added); + NetworkPartitionBean beanRemoved = (NetworkPartitionBean) restClientTenant1. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, + NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(beanRemoved, null); - 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, + bean = (NetworkPartitionBean) restClientTenant2. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemoved); + assertNotNull("Network partition not exist in other tenant",bean); - removed = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - networkPartitionId2, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removed); + removed = restClientTenant2.removeEntity(RestConstants.NETWORK_PARTITIONS, + networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removed, true); - beanRemoved = (NetworkPartitionBean) restClient. - getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId2, + beanRemoved = (NetworkPartitionBean) restClientTenant2. + getEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId, NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME); - assertNull(beanRemoved); + assertEquals(beanRemoved, null); log.info("-------------------------Ended network partition test case-------------------------"); } catch (Exception e) {
