Refactoring integration test cases according to guidelines, throwing all exceptions
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/1803972c Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/1803972c Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/1803972c Branch: refs/heads/stratos-4.1.x Commit: 1803972c99014aaf9438844d7e962e71a5a2fdf8 Parents: 5a9537d Author: Akila Perera <[email protected]> Authored: Sat Sep 19 21:25:53 2015 +0530 Committer: Akila Perera <[email protected]> Committed: Sun Sep 20 00:19:41 2015 +0530 ---------------------------------------------------------------------- .../integration/common/rest/RestClient.java | 252 ++++------- .../application/ApplicationBurstingTest.java | 235 ---------- .../ApplicationBurstingTestCase.java | 225 ++++++++++ .../application/ApplicationUpdateTest.java | 269 ------------ .../application/ApplicationUpdateTestCase.java | 257 +++++++++++ .../application/GroupStartupOrderTest.java | 377 ---------------- .../application/GroupStartupOrderTestCase.java | 364 ++++++++++++++++ .../GroupTerminationBehaviorTest.java | 427 ------------------- .../GroupTerminationBehaviorTestCase.java | 416 ++++++++++++++++++ .../PartitionOneAfterAnotherClusterTest.java | 291 ------------- ...PartitionOneAfterAnotherClusterTestCase.java | 279 ++++++++++++ .../PartitionRoundRobinClusterTest.java | 298 ------------- .../PartitionRoundRobinClusterTestCase.java | 286 +++++++++++++ .../application/SampleApplicationsTest.java | 419 ------------------ .../application/SampleApplicationsTestCase.java | 404 ++++++++++++++++++ .../application/SingleClusterScalingTest.java | 369 ---------------- .../SingleClusterScalingTestCase.java | 358 ++++++++++++++++ .../tests/group/CartridgeGroupTest.java | 272 ------------ .../tests/group/CartridgeGroupTestCase.java | 251 +++++++++++ .../integration/tests/group/CartridgeTest.java | 203 --------- .../tests/group/CartridgeTestCase.java | 183 ++++++++ .../tests/policies/ApplicationPolicyTest.java | 243 ----------- .../policies/ApplicationPolicyTestCase.java | 222 ++++++++++ .../tests/policies/AutoscalingPolicyTest.java | 173 -------- .../policies/AutoscalingPolicyTestCase.java | 155 +++++++ .../tests/policies/DeploymentPolicyTest.java | 285 ------------- .../policies/DeploymentPolicyTestCase.java | 261 ++++++++++++ .../tests/policies/NetworkPartitionTest.java | 170 -------- .../policies/NetworkPartitionTestCase.java | 147 +++++++ .../integration/tests/users/TenantTest.java | 42 -- .../integration/tests/users/TenantTestCase.java | 42 ++ .../integration/tests/users/UserTest.java | 112 ----- .../integration/tests/users/UserTestCase.java | 104 +++++ 33 files changed, 4047 insertions(+), 4344 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java index f1beec7..e438a9e 100644 --- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java +++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java @@ -158,154 +158,108 @@ public class RestClient { } } - public boolean addEntity(String filePath, String resourcePath, String entityName) { - try { - String content = getJsonStringFromFile(filePath); - URI uri = new URIBuilder(this.endPoint + resourcePath).build(); - - HttpResponse response = doPost(uri, content); - if (response != null) { - if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { - return true; - } else { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class); - if (errorResponse != null) { - throw new RuntimeException(errorResponse.getErrorMessage()); - } + public boolean addEntity(String filePath, String resourcePath, String entityName) throws Exception { + String content = getJsonStringFromFile(filePath); + URI uri = new URIBuilder(this.endPoint + resourcePath).build(); + + HttpResponse response = doPost(uri, content); + if (response != null) { + if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { + return true; + } else { + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class); + if (errorResponse != null) { + throw new RuntimeException(errorResponse.getErrorMessage()); } } - String msg = "An unknown error occurred while trying to add "; - log.error(msg + entityName); - throw new RuntimeException(msg + entityName); - } - catch (Exception e) { - String message = "Could not add " + entityName; - log.error(message, e); - throw new RuntimeException(message, e); } + throw new Exception("Null response received. Could not add entity [entity name] " + entityName); } - public boolean deployEntity(String resourcePath, String entityName) { - try { - URI uri = new URIBuilder(this.endPoint + resourcePath).build(); - - HttpResponse response = doPost(uri, ""); - if (response != null) { - if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { - return true; - } else { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class); - if (errorResponse != null) { - throw new RuntimeException(errorResponse.getErrorMessage()); - } + public boolean deployEntity(String resourcePath, String entityName) throws Exception { + URI uri = new URIBuilder(this.endPoint + resourcePath).build(); + + HttpResponse response = doPost(uri, ""); + if (response != null) { + if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { + return true; + } else { + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class); + if (errorResponse != null) { + throw new RuntimeException(errorResponse.getErrorMessage()); } } - String msg = "An unknown error occurred while trying to deploy "; - log.error(msg + entityName); - throw new RuntimeException(msg + entityName); - } - catch (Exception e) { - String message = "Could not deploy " + entityName; - log.error(message, e); - throw new RuntimeException(message, e); } + throw new Exception("Null response received. Could not deploy entity [entity name] " + entityName); } - public boolean undeployEntity(String resourcePath, String entityName) { - try { - URI uri = new URIBuilder(this.endPoint + resourcePath).build(); - - HttpResponse response = doPost(uri, ""); - if (response != null) { - if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { - return true; - } else { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class); - if (errorResponse != null) { - throw new RuntimeException(errorResponse.getErrorMessage()); - } + public boolean undeployEntity(String resourcePath, String entityName) throws Exception { + URI uri = new URIBuilder(this.endPoint + resourcePath).build(); + + HttpResponse response = doPost(uri, ""); + if (response != null) { + if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { + return true; + } else { + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class); + if (errorResponse != null) { + throw new RuntimeException(errorResponse.getErrorMessage()); } } - String msg = "An unknown error occurred while trying to undeploy "; - log.error(msg + entityName); - throw new RuntimeException(msg + entityName); - } - catch (Exception e) { - String message = "Could not deploy " + entityName; - log.error(message, e); - throw new RuntimeException(message, e); } + throw new Exception("Null response received. Could not undeploy entity [entity name] " + entityName); } public Object getEntity(String resourcePath, String identifier, Class responseJsonClass, - String entityName) { - try { - URI uri = new URIBuilder(this.endPoint + resourcePath + "/" + identifier).build(); - HttpResponse response = doGet(uri); - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - if (response != null) { - if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { - return gson.fromJson(response.getContent(), responseJsonClass); - } else if (response.getStatusCode() == 404) { - return null; - } else { - ErrorResponse errorResponse = gson.fromJson(response.getContent(), - ErrorResponse.class); - if (errorResponse != null) { - throw new RuntimeException(errorResponse.getErrorMessage()); - } + String entityName) throws Exception { + URI uri = new URIBuilder(this.endPoint + resourcePath + "/" + identifier).build(); + HttpResponse response = doGet(uri); + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + if (response != null) { + if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { + return gson.fromJson(response.getContent(), responseJsonClass); + } else if (response.getStatusCode() == 404) { + return null; + } else { + ErrorResponse errorResponse = gson.fromJson(response.getContent(), + ErrorResponse.class); + if (errorResponse != null) { + throw new RuntimeException(errorResponse.getErrorMessage()); } } - String msg = "An unknown error occurred while getting the " + entityName; - log.error(msg); - throw new RuntimeException(msg); - } - catch (Exception e) { - String message = "Could not get " + entityName; - log.error(message, e); - throw new RuntimeException(message, e); } + throw new Exception("Null response received. Could not get entity [entity name] " + entityName); } - public Object listEntity(String resourcePath, Type type, String entityName) { - try { - URI uri = new URIBuilder(this.endPoint + resourcePath).build(); - HttpResponse response = doGet(uri); - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - if (response != null) { - if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { - return gson.fromJson(response.getContent(), type); - } else if (response.getStatusCode() == 404) { - return null; - } else { - ErrorResponse errorResponse = gson.fromJson(response.getContent(), - ErrorResponse.class); - if (errorResponse != null) { - throw new RuntimeException(errorResponse.getErrorMessage()); - } + public Object listEntity(String resourcePath, Type type, String entityName) throws Exception { + URI uri = new URIBuilder(this.endPoint + resourcePath).build(); + HttpResponse response = doGet(uri); + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + if (response != null) { + if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { + return gson.fromJson(response.getContent(), type); + } else if (response.getStatusCode() == 404) { + return null; + } else { + ErrorResponse errorResponse = gson.fromJson(response.getContent(), + ErrorResponse.class); + if (errorResponse != null) { + throw new RuntimeException(errorResponse.getErrorMessage()); } } - String msg = "An unknown error occurred while getting the " + entityName; - log.error(msg); - throw new RuntimeException(msg); - } - catch (Exception e) { - String message = "Could not get " + entityName; - log.error(message, e); - throw new RuntimeException(message, e); } + throw new Exception("Null response received. Could not get entity [entity name] " + entityName); } public boolean removeEntity(String resourcePath, String identifier, String entityName) throws Exception { - URI uri = new URIBuilder(this.endPoint + "/" + resourcePath + "/" + identifier).build(); HttpResponse response = doDelete(uri); if (response != null) { @@ -319,51 +273,31 @@ public class RestClient { log.error("Error response while removing entity [identifier] " + identifier + ", [entity name] " + entityName + ", [error] " + errorResponse.getErrorMessage() + ", [error code] " + errorResponse .getErrorCode()); - /*else if (response.getContent().contains("it is used") || response.getContent().contains("in use")) { - return false; - } else { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - ErrorResponse errorResponse = gson.fromJson(response.getContent(), - ErrorResponse.class); - if (errorResponse != null) { - throw new RuntimeException(errorResponse.getErrorMessage()); - } - }*/ return false; } } - throw new Exception("No response received from back-end."); + throw new Exception("Null response received. Could not remove entity [entity name] " + entityName); } - public boolean updateEntity(String filePath, String resourcePath, String entityName) { - try { - String content = getJsonStringFromFile(filePath); - URI uri = new URIBuilder(this.endPoint + resourcePath).build(); - - HttpResponse response = doPut(uri, content); - if (response != null) { - if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { - return true; - } else { - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.create(); - ErrorResponse errorResponse = gson.fromJson(response.getContent(), - ErrorResponse.class); - if (errorResponse != null) { - throw new RuntimeException(errorResponse.getErrorMessage()); - } + public boolean updateEntity(String filePath, String resourcePath, String entityName) throws Exception { + String content = getJsonStringFromFile(filePath); + URI uri = new URIBuilder(this.endPoint + resourcePath).build(); + + HttpResponse response = doPut(uri, content); + if (response != null) { + if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) { + return true; + } else { + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.create(); + ErrorResponse errorResponse = gson.fromJson(response.getContent(), + ErrorResponse.class); + if (errorResponse != null) { + throw new RuntimeException(errorResponse.getErrorMessage()); } } - String msg = "An unknown error occurred while trying to update "; - log.error(msg + entityName); - throw new RuntimeException(msg + entityName); - } - catch (Exception e) { - String message = "Could not update " + entityName; - log.error(message, e); - throw new RuntimeException(message, e); } + throw new Exception("Null response received. Could not update entity [entity name] " + entityName); } /** @@ -399,4 +333,4 @@ public class RestClient { private String getUsernamePassword() { return this.userName + ":" + this.password; } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java deleted file mode 100644 index 2fab10b..0000000 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.stratos.integration.tests.application; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.common.beans.application.ApplicationBean; -import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean; -import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean; -import org.apache.stratos.integration.common.RestConstants; -import org.apache.stratos.integration.common.TopologyHandler; -import org.apache.stratos.integration.tests.StratosIntegrationTest; -import org.apache.stratos.messaging.domain.application.ApplicationStatus; -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertTrue; - -/** - * This will handle the application bursting test cases - */ -public class ApplicationBurstingTest extends StratosIntegrationTest { - private static final Log log = LogFactory.getLog(ApplicationBurstingTest.class); - private static final String RESOURCES_PATH = "/application-bursting-test"; - - - @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"}) - public void testApplicationBusting() { - try { - log.info("----------------------------Started application Bursting test case----------------------------"); - TopologyHandler topologyHandler = TopologyHandler.getInstance(); - String autoscalingPolicyId = "autoscaling-policy-application-bursting-test"; - - boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH - + "/" + autoscalingPolicyId + ".json", - RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - assertTrue(addedScalingPolicy); - - boolean addedC1 = restClient.addEntity( - RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "esb-application-bursting-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(addedC1); - - boolean addedC2 = restClient.addEntity( - RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "php-application-bursting-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(addedC2); - - boolean addedC3 = restClient.addEntity( - RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "tomcat-application-bursting-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertTrue(addedC3); - - boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + "esb-php-group-application-bursting-test.json", RestConstants.CARTRIDGE_GROUPS, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(addedG1); - - CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", - CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(beanG1.getName(), "esb-php-group-application-bursting-test"); - - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-application-bursting-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-bursting-test-2.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(addedN2); - - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - "deployment-policy-application-bursting-test.json", - RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(addedDep); - - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + - "app-bursting-single-cartriddge-group.json", RestConstants.APPLICATIONS, - RestConstants.APPLICATIONS_NAME); - assertTrue(added); - - ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(bean.getApplicationId(), "application-bursting-test"); - - boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + - "application-policy-application-bursting-test.json", RestConstants.APPLICATION_POLICIES, - RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(addAppPolicy); - - ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity( - RestConstants.APPLICATION_POLICIES, - "application-policy-application-bursting-test", ApplicationPolicyBean.class, - RestConstants.APPLICATION_POLICIES_NAME); - - //deploy the application - String resourcePath = RestConstants.APPLICATIONS + "/" + "application-bursting-test" + - RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-application-bursting-test"; - boolean deployed = restClient.deployEntity(resourcePath, - RestConstants.APPLICATIONS_NAME); - assertTrue(deployed); - - //Application active handling - topologyHandler.assertApplicationStatus(bean.getApplicationId(), - ApplicationStatus.Active); - - //Group active handling - topologyHandler.assertGroupActivation(bean.getApplicationId()); - - //Cluster active handling - topologyHandler.assertClusterActivation(bean.getApplicationId()); - - boolean removedGroup = - restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertFalse(removedGroup); - - boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertFalse(removedAuto); - - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-bursting-test-1", - RestConstants.NETWORK_PARTITIONS_NAME); - //Trying to remove the used network partition - assertFalse(removedNet); - - boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - "deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertFalse(removedDep); - - //Un-deploying the application - String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "application-bursting-test" + - RestConstants.APPLICATIONS_UNDEPLOY; - - boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, - RestConstants.APPLICATIONS_NAME); - assertTrue(unDeployed); - - boolean undeploy = topologyHandler.assertApplicationUndeploy("application-bursting-test"); - if (!undeploy) { - //Need to forcefully undeploy the application - log.info("Force undeployment is going to start for the [application] " + "application-bursting-test"); - - restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "application-bursting-test" + - RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); - - boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("application-bursting-test"); - assertEquals(String.format("Forceful undeployment failed for the application %s", - "application-bursting-test"), forceUndeployed); - - } - - boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "application-bursting-test", - RestConstants.APPLICATIONS_NAME); - assertTrue(removed); - - ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertNull(beanRemoved); - - removedGroup = - restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertTrue(removedGroup); - - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "esb-application-bursting-test", - RestConstants.CARTRIDGES_NAME); - assertTrue(removedC1); - - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "php-application-bursting-test", - RestConstants.CARTRIDGES_NAME); - assertTrue(removedC2); - - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "tomcat-application-bursting-test", - RestConstants.CARTRIDGES_NAME); - assertTrue(removedC3); - - removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertTrue(removedAuto); - - removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - "deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertTrue(removedDep); - - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertFalse(removedNet); - - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertFalse(removedN2); - - boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, - "application-policy-application-bursting-test", RestConstants.APPLICATION_POLICIES_NAME); - assertTrue(removeAppPolicy); - - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedNet); - - removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertTrue(removedN2); - - log.info("----------------------------Ended application bursting test case----------------------------"); - - } - catch (Exception e) { - log.error("An error occurred while handling application bursting", e); - assertTrue("An error occurred while handling application bursting", false); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java new file mode 100644 index 0000000..2ed317d --- /dev/null +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.integration.tests.application; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.application.ApplicationBean; +import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean; +import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean; +import org.apache.stratos.integration.common.RestConstants; +import org.apache.stratos.integration.common.TopologyHandler; +import org.apache.stratos.integration.tests.StratosIntegrationTest; +import org.apache.stratos.messaging.domain.application.ApplicationStatus; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertTrue; + +/** + * This will handle the application bursting test cases + */ +public class ApplicationBurstingTestCase extends StratosIntegrationTest { + private static final Log log = LogFactory.getLog(ApplicationBurstingTestCase.class); + private static final String RESOURCES_PATH = "/application-bursting-test"; + + + @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"}) + public void testApplicationBusting() throws Exception { + TopologyHandler topologyHandler = TopologyHandler.getInstance(); + String autoscalingPolicyId = "autoscaling-policy-application-bursting-test"; + + boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + + "/" + autoscalingPolicyId + ".json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); + assertTrue(addedScalingPolicy); + + boolean addedC1 = restClient.addEntity( + RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "esb-application-bursting-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertTrue(addedC1); + + boolean addedC2 = restClient.addEntity( + RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "php-application-bursting-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertTrue(addedC2); + + boolean addedC3 = restClient.addEntity( + RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "tomcat-application-bursting-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertTrue(addedC3); + + boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + + "/" + "esb-php-group-application-bursting-test.json", RestConstants.CARTRIDGE_GROUPS, + RestConstants.CARTRIDGE_GROUPS_NAME); + assertTrue(addedG1); + + CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient. + getEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", + CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(beanG1.getName(), "esb-php-group-application-bursting-test"); + + boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-application-bursting-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-bursting-test-2.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(addedN2); + + boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + "deployment-policy-application-bursting-test.json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(addedDep); + + boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + + "app-bursting-single-cartriddge-group.json", RestConstants.APPLICATIONS, + RestConstants.APPLICATIONS_NAME); + assertTrue(added); + + ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + "application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(bean.getApplicationId(), "application-bursting-test"); + + boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + + "application-policy-application-bursting-test.json", RestConstants.APPLICATION_POLICIES, + RestConstants.APPLICATION_POLICIES_NAME); + assertTrue(addAppPolicy); + + ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity( + RestConstants.APPLICATION_POLICIES, + "application-policy-application-bursting-test", ApplicationPolicyBean.class, + RestConstants.APPLICATION_POLICIES_NAME); + + //deploy the application + String resourcePath = RestConstants.APPLICATIONS + "/" + "application-bursting-test" + + RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-application-bursting-test"; + boolean deployed = restClient.deployEntity(resourcePath, + RestConstants.APPLICATIONS_NAME); + assertTrue(deployed); + + //Application active handling + topologyHandler.assertApplicationStatus(bean.getApplicationId(), + ApplicationStatus.Active); + + //Group active handling + topologyHandler.assertGroupActivation(bean.getApplicationId()); + + //Cluster active handling + topologyHandler.assertClusterActivation(bean.getApplicationId()); + + boolean removedGroup = + restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertFalse(removedGroup); + + boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertFalse(removedAuto); + + boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-bursting-test-1", + RestConstants.NETWORK_PARTITIONS_NAME); + //Trying to remove the used network partition + assertFalse(removedNet); + + boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + "deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME); + assertFalse(removedDep); + + //Un-deploying the application + String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "application-bursting-test" + + RestConstants.APPLICATIONS_UNDEPLOY; + + boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, + RestConstants.APPLICATIONS_NAME); + assertTrue(unDeployed); + + boolean undeploy = topologyHandler.assertApplicationUndeploy("application-bursting-test"); + if (!undeploy) { + //Need to forcefully undeploy the application + log.info("Force undeployment is going to start for the [application] " + "application-bursting-test"); + + restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "application-bursting-test" + + RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); + + boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("application-bursting-test"); + assertEquals(String.format("Forceful undeployment failed for the application %s", + "application-bursting-test"), forceUndeployed); + + } + + boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "application-bursting-test", + RestConstants.APPLICATIONS_NAME); + assertTrue(removed); + + ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + "application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertNull(beanRemoved); + + removedGroup = + restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertTrue(removedGroup); + + boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "esb-application-bursting-test", + RestConstants.CARTRIDGES_NAME); + assertTrue(removedC1); + + boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "php-application-bursting-test", + RestConstants.CARTRIDGES_NAME); + assertTrue(removedC2); + + boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "tomcat-application-bursting-test", + RestConstants.CARTRIDGES_NAME); + assertTrue(removedC3); + + removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertTrue(removedAuto); + + removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + "deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME); + assertTrue(removedDep); + + removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + assertFalse(removedNet); + + boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertFalse(removedN2); + + boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, + "application-policy-application-bursting-test", RestConstants.APPLICATION_POLICIES_NAME); + assertTrue(removeAppPolicy); + + removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removedNet); + + removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertTrue(removedN2); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/1803972c/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java deleted file mode 100644 index a7c1a89..0000000 --- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.stratos.integration.tests.application; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.common.beans.application.ApplicationBean; -import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean; -import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean; -import org.apache.stratos.integration.common.RestConstants; -import org.apache.stratos.integration.common.TopologyHandler; -import org.apache.stratos.integration.tests.StratosIntegrationTest; -import org.apache.stratos.integration.common.TopologyHandler; -import org.apache.stratos.messaging.domain.application.Application; -import org.apache.stratos.messaging.domain.application.ApplicationStatus; -import org.apache.stratos.messaging.domain.application.ClusterDataHolder; -import org.apache.stratos.messaging.domain.application.Group; -import org.apache.stratos.messaging.message.receiver.application.ApplicationManager; -import org.testng.annotations.Test; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; - -/** - * Sample application tests with application add, . - */ -public class ApplicationUpdateTest extends StratosIntegrationTest { - private static final Log log = LogFactory.getLog(ApplicationUpdateTest.class); - private static final String RESOURCES_PATH = "/application-update-test"; - - @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"}) - public void testDeployApplication() { - try { - log.info("-------------------------Started application runtime update test case-------------------------"); - TopologyHandler topologyHandler = TopologyHandler.getInstance(); - String autoscalingPolicyId = "autoscaling-policy-application-update-test"; - - boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH - + "/" + autoscalingPolicyId + ".json", - RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); - assertEquals(addedScalingPolicy, true); - - boolean addedC1 = restClient - .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-application-update-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC1, true); - - boolean addedC2 = restClient - .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-application-update-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC2, true); - - boolean addedC3 = restClient - .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-application-update-test.json", - RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); - assertEquals(addedC3, true); - - boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + - "/" + "cartrdige-nested-application-update-test.json", RestConstants.CARTRIDGE_GROUPS, - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(addedG1, true); - - CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient. - getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", - CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(beanG1.getName(), "G1-application-update-test"); - - boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-application-update-test-1.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(addedN1, true); - - boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + - "network-partition-application-update-test-2.json", - RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(addedN2, true); - - boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + - "deployment-policy-application-update-test.json", - RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(addedDep, true); - - boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + - "g-sc-G123-1-application-update-test.json", RestConstants.APPLICATIONS, - RestConstants.APPLICATIONS_NAME); - assertEquals(added, true); - - ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(bean.getApplicationId(), "g-sc-G123-1-application-update-test"); - - boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + - "application-policy-application-update-test.json", RestConstants.APPLICATION_POLICIES, - RestConstants.APPLICATION_POLICIES_NAME); - assertEquals(addAppPolicy, true); - - ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity( - RestConstants.APPLICATION_POLICIES, - "application-policy-application-update-test", ApplicationPolicyBean.class, - RestConstants.APPLICATION_POLICIES_NAME); - - //deploy the application - String resourcePath = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + - RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-application-update-test"; - boolean deployed = restClient.deployEntity(resourcePath, - RestConstants.APPLICATIONS_NAME); - assertEquals(deployed, true); - - //Application active handling - topologyHandler.assertApplicationStatus(bean.getApplicationId(), - ApplicationStatus.Active); - - //Group active handling - topologyHandler.assertGroupActivation(bean.getApplicationId()); - - //Cluster active handling - topologyHandler.assertClusterActivation(bean.getApplicationId()); - - //Updating application - boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + - "g-sc-G123-1-application-update-test-v1.json", RestConstants.APPLICATIONS, - RestConstants.APPLICATIONS_NAME); - assertEquals(updated, true); - - ApplicationBean updatedBean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(updatedBean.getApplicationId(), "g-sc-G123-1-application-update-test"); - - //Need to validate whether the updated taken into the applications Topology - Application application = ApplicationManager.getApplications(). - getApplication(bean.getApplicationId()); - - Group group = application.getGroupRecursively("group3-application-update-test"); - assertEquals(group.getGroupMaxInstances(), 3); - assertEquals(group.getGroupMinInstances(), 2); - log.info("Application update is successfully done for [application] " + - bean.getApplicationId() + " [group] " + group.getUniqueIdentifier()); - - ClusterDataHolder clusterDataHolder = application. - getClusterDataHolderRecursivelyByAlias("c3-1x0-application-update-test"); - assertEquals(clusterDataHolder.getMaxInstances(), 3); - assertEquals(clusterDataHolder.getMinInstances(), 2); - log.info("Application update is successfully done for [application] " + - bean.getApplicationId() + " [Cluster] " + clusterDataHolder.getClusterId()); - - topologyHandler.assertGroupInstanceCount(bean.getApplicationId(), "group3-application-update-test", 2); - - topologyHandler.assertClusterMinMemberCount(bean.getApplicationId(), 2); - - boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(removedGroup, false); - - boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertEquals(removedAuto, false); - - boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-1", - RestConstants.NETWORK_PARTITIONS_NAME); - //Trying to remove the used network partition - assertEquals(removedNet, false); - - boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - "deployment-policy-application-update-test", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(removedDep, false); - - //Un-deploying the application - String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + - RestConstants.APPLICATIONS_UNDEPLOY; - - boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, - RestConstants.APPLICATIONS_NAME); - assertEquals(unDeployed, true); - - boolean undeploy = topologyHandler.assertApplicationUndeploy("g-sc-G123-1-application-update-test"); - if (!undeploy) { - //Need to forcefully undeploy the application - log.info("Force undeployment is going to start for the [application] " + - "g-sc-G123-1-application-update-test"); - - restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + - RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); - - boolean forceUndeployed = - topologyHandler.assertApplicationUndeploy("g-sc-G123-1-application-update-test"); - assertEquals(String.format("Forceful undeployment failed for the application %s", - "g-sc-G123-1-application-update-test"), forceUndeployed, true); - - } - - boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-application-update-test", - RestConstants.APPLICATIONS_NAME); - assertEquals(removed, true); - - ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, - "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); - assertEquals(beanRemoved, null); - - removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", - RestConstants.CARTRIDGE_GROUPS_NAME); - assertEquals(removedGroup, true); - - boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1-application-update-test", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC1, true); - - boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2-application-update-test", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC2, true); - - boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3-application-update-test", - RestConstants.CARTRIDGES_NAME); - assertEquals(removedC3, true); - - removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, - autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); - assertEquals(removedAuto, true); - - removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, - "deployment-policy-application-update-test", RestConstants.DEPLOYMENT_POLICIES_NAME); - assertEquals(removedDep, true); - - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedNet, false); - - boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, false); - - boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, - "application-policy-application-update-test", RestConstants.APPLICATION_POLICIES_NAME); - assertEquals(removeAppPolicy, true); - - removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedNet, true); - - removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, - "network-partition-application-update-test-2", RestConstants.NETWORK_PARTITIONS_NAME); - assertEquals(removedN2, true); - - log.info("-------------------------Ended application runtime update test case-------------------------"); - - } - catch (Exception e) { - log.error("An error occurred while handling application deployment/undeployment and update", e); - assertTrue("An error occurred while handling application deployment/undeployment and update", 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/application/ApplicationUpdateTestCase.java ---------------------------------------------------------------------- diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTestCase.java new file mode 100644 index 0000000..5ed9b5d --- /dev/null +++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTestCase.java @@ -0,0 +1,257 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.integration.tests.application; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.beans.application.ApplicationBean; +import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean; +import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean; +import org.apache.stratos.integration.common.RestConstants; +import org.apache.stratos.integration.common.TopologyHandler; +import org.apache.stratos.integration.tests.StratosIntegrationTest; +import org.apache.stratos.messaging.domain.application.Application; +import org.apache.stratos.messaging.domain.application.ApplicationStatus; +import org.apache.stratos.messaging.domain.application.ClusterDataHolder; +import org.apache.stratos.messaging.domain.application.Group; +import org.apache.stratos.messaging.message.receiver.application.ApplicationManager; +import org.testng.annotations.Test; + +import static junit.framework.Assert.assertEquals; + +/** + * Sample application tests with application add, . + */ +public class ApplicationUpdateTestCase extends StratosIntegrationTest { + private static final Log log = LogFactory.getLog(ApplicationUpdateTestCase.class); + private static final String RESOURCES_PATH = "/application-update-test"; + + @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"}) + public void testDeployApplication() throws Exception { + TopologyHandler topologyHandler = TopologyHandler.getInstance(); + String autoscalingPolicyId = "autoscaling-policy-application-update-test"; + + boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + + "/" + autoscalingPolicyId + ".json", + RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(addedScalingPolicy, true); + + boolean addedC1 = restClient + .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-application-update-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(addedC1, true); + + boolean addedC2 = restClient + .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-application-update-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(addedC2, true); + + boolean addedC3 = restClient + .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-application-update-test.json", + RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME); + assertEquals(addedC3, true); + + boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH + + "/" + "cartrdige-nested-application-update-test.json", RestConstants.CARTRIDGE_GROUPS, + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(addedG1, true); + + CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient. + getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", + CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(beanG1.getName(), "G1-application-update-test"); + + boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-application-update-test-1.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN1, true); + + boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + + "network-partition-application-update-test-2.json", + RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(addedN2, true); + + boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + + "deployment-policy-application-update-test.json", + RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(addedDep, true); + + boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + + "g-sc-G123-1-application-update-test.json", RestConstants.APPLICATIONS, + RestConstants.APPLICATIONS_NAME); + assertEquals(added, true); + + ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(bean.getApplicationId(), "g-sc-G123-1-application-update-test"); + + boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + + "application-policy-application-update-test.json", RestConstants.APPLICATION_POLICIES, + RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(addAppPolicy, true); + + ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity( + RestConstants.APPLICATION_POLICIES, + "application-policy-application-update-test", ApplicationPolicyBean.class, + RestConstants.APPLICATION_POLICIES_NAME); + + //deploy the application + String resourcePath = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + + RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-application-update-test"; + boolean deployed = restClient.deployEntity(resourcePath, + RestConstants.APPLICATIONS_NAME); + assertEquals(deployed, true); + + //Application active handling + topologyHandler.assertApplicationStatus(bean.getApplicationId(), + ApplicationStatus.Active); + + //Group active handling + topologyHandler.assertGroupActivation(bean.getApplicationId()); + + //Cluster active handling + topologyHandler.assertClusterActivation(bean.getApplicationId()); + + //Updating application + boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + + "g-sc-G123-1-application-update-test-v1.json", RestConstants.APPLICATIONS, + RestConstants.APPLICATIONS_NAME); + assertEquals(updated, true); + + ApplicationBean updatedBean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(updatedBean.getApplicationId(), "g-sc-G123-1-application-update-test"); + + //Need to validate whether the updated taken into the applications Topology + Application application = ApplicationManager.getApplications(). + getApplication(bean.getApplicationId()); + + Group group = application.getGroupRecursively("group3-application-update-test"); + assertEquals(group.getGroupMaxInstances(), 3); + assertEquals(group.getGroupMinInstances(), 2); + log.info("Application update is successfully done for [application] " + + bean.getApplicationId() + " [group] " + group.getUniqueIdentifier()); + + ClusterDataHolder clusterDataHolder = application. + getClusterDataHolderRecursivelyByAlias("c3-1x0-application-update-test"); + assertEquals(clusterDataHolder.getMaxInstances(), 3); + assertEquals(clusterDataHolder.getMinInstances(), 2); + log.info("Application update is successfully done for [application] " + + bean.getApplicationId() + " [Cluster] " + clusterDataHolder.getClusterId()); + + topologyHandler.assertGroupInstanceCount(bean.getApplicationId(), "group3-application-update-test", 2); + + topologyHandler.assertClusterMinMemberCount(bean.getApplicationId(), 2); + + boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(removedGroup, false); + + boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(removedAuto, false); + + boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-1", + RestConstants.NETWORK_PARTITIONS_NAME); + //Trying to remove the used network partition + assertEquals(removedNet, false); + + boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + "deployment-policy-application-update-test", RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(removedDep, false); + + //Un-deploying the application + String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + + RestConstants.APPLICATIONS_UNDEPLOY; + + boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, + RestConstants.APPLICATIONS_NAME); + assertEquals(unDeployed, true); + + boolean undeploy = topologyHandler.assertApplicationUndeploy("g-sc-G123-1-application-update-test"); + if (!undeploy) { + //Need to forcefully undeploy the application + log.info("Force undeployment is going to start for the [application] " + + "g-sc-G123-1-application-update-test"); + + restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + "g-sc-G123-1-application-update-test" + + RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS); + + boolean forceUndeployed = + topologyHandler.assertApplicationUndeploy("g-sc-G123-1-application-update-test"); + assertEquals(String.format("Forceful undeployment failed for the application %s", + "g-sc-G123-1-application-update-test"), forceUndeployed, true); + + } + + boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-application-update-test", + RestConstants.APPLICATIONS_NAME); + assertEquals(removed, true); + + ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS, + "g-sc-G123-1-application-update-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME); + assertEquals(beanRemoved, null); + + removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-application-update-test", + RestConstants.CARTRIDGE_GROUPS_NAME); + assertEquals(removedGroup, true); + + boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1-application-update-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC1, true); + + boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2-application-update-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC2, true); + + boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3-application-update-test", + RestConstants.CARTRIDGES_NAME); + assertEquals(removedC3, true); + + removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, + autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME); + assertEquals(removedAuto, true); + + removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, + "deployment-policy-application-update-test", RestConstants.DEPLOYMENT_POLICIES_NAME); + assertEquals(removedDep, true); + + removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedNet, false); + + boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedN2, false); + + boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, + "application-policy-application-update-test", RestConstants.APPLICATION_POLICIES_NAME); + assertEquals(removeAppPolicy, true); + + removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-1", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedNet, true); + + removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, + "network-partition-application-update-test-2", RestConstants.NETWORK_PARTITIONS_NAME); + assertEquals(removedN2, true); + } +}
