You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/09/10 10:13:52 UTC
[08/16] stratos git commit: Upgrading automation engine to v4.4.2
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/ErrorResponse.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/ErrorResponse.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/ErrorResponse.java
new file mode 100644
index 0000000..3de8c80
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/ErrorResponse.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed 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.common.rest;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+/**
+ * Error response.
+ */
+@XmlRootElement(name = "errorResponse")
+public class ErrorResponse implements Serializable {
+
+ private int errorCode;
+ private String errorMessage;
+
+ public ErrorResponse() {
+ }
+
+ public ErrorResponse(int errorCode, String errorMessage) {
+ this.setErrorCode(errorCode);
+ this.setErrorMessage(errorMessage);
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(int errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponse.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponse.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponse.java
new file mode 100644
index 0000000..7c53ea9
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponse.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed 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.common.rest;
+
+public class HttpResponse {
+
+ private int statusCode;
+ private String content;
+ private String reason;
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public void setReason(String reason) {
+ this.reason = reason;
+ }
+
+ @Override
+ public String toString() {
+ return "HttpResponse [statusCode=" + statusCode + ", content=" + content
+ + ", reason=" + reason + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponseHandler.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponseHandler.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponseHandler.java
new file mode 100644
index 0000000..c3cb3a6
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponseHandler.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed 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.common.rest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+/**
+ * Rest http response handler
+ */
+public class HttpResponseHandler implements ResponseHandler<HttpResponse> {
+ private static final Log log = LogFactory.getLog(HttpResponseHandler.class);
+
+ @Override
+ public HttpResponse handleResponse(org.apache.http.HttpResponse response) throws ClientProtocolException,
+ IOException {
+ StatusLine statusLine = response.getStatusLine();
+ HttpEntity entity = response.getEntity();
+ if (entity == null) {
+ throw new ClientProtocolException("Response contains no content");
+ }
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ (response.getEntity().getContent())));
+
+ String output;
+ String result = "";
+
+ while ((output = reader.readLine()) != null) {
+ result += output;
+ }
+
+ HttpResponse httpResponse = new HttpResponse();
+ httpResponse.setStatusCode(statusLine.getStatusCode());
+ httpResponse.setContent(result);
+ httpResponse.setReason(statusLine.getReasonPhrase());
+
+ if (log.isDebugEnabled()) {
+ log.debug("Extracted Http Response: " + httpResponse.toString());
+ }
+
+ return httpResponse;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/IntegrationMockClient.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/IntegrationMockClient.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/IntegrationMockClient.java
new file mode 100644
index 0000000..73090bd
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/IntegrationMockClient.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed 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.common.rest;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.apache.stratos.mock.iaas.client.MockIaasApiClient;
+import org.apache.stratos.mock.iaas.client.rest.HttpResponse;
+import org.apache.stratos.mock.iaas.client.rest.HttpResponseHandler;
+
+import java.net.URI;
+
+/**
+ * Mock client
+ */
+public class IntegrationMockClient extends MockIaasApiClient {
+ private static final Log log = LogFactory.getLog(IntegrationMockClient.class);
+ private static final String INSTANCES_CONTEXT = "/instances/";
+ private DefaultHttpClient httpClient;
+ private String endpoint;
+
+ public IntegrationMockClient(String endpoint) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
+ // Increase max total connection to 200
+ cm.setMaxTotal(200);
+ // Increase default max connection per route to 50
+ cm.setDefaultMaxPerRoute(50);
+
+ httpClient = new DefaultHttpClient(cm);
+ httpClient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpClient);
+ }
+
+ public boolean terminateInstance(String instanceId) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Terminate instance: [instance-id] %s", instanceId));
+ }
+ URI uri = new URIBuilder(endpoint + INSTANCES_CONTEXT + instanceId).build();
+ org.apache.stratos.mock.iaas.client.rest.HttpResponse response = doDelete(uri);
+ if (response != null) {
+ if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+ return true;
+ } else {
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+ org.apache.stratos.mock.iaas.domain.ErrorResponse errorResponse = gson.fromJson(response.getContent(), org.apache.stratos.mock.iaas.domain.ErrorResponse.class);
+ if (errorResponse != null) {
+ throw new RuntimeException(errorResponse.getErrorMessage());
+ }
+ }
+ }
+ throw new RuntimeException("An unknown error occurred");
+ } catch (Exception e) {
+ String message = "Could not start mock instance";
+ throw new RuntimeException(message, e);
+ }
+ }
+
+ public HttpResponse doDelete(URI resourcePath) throws Exception {
+ HttpDelete httpDelete = null;
+ try {
+ httpDelete = new HttpDelete(resourcePath);
+ httpDelete.addHeader("Content-Type", "application/json");
+
+ return httpClient.execute(httpDelete, new HttpResponseHandler());
+ } finally {
+ releaseConnection(httpDelete);
+ }
+ }
+
+ private void releaseConnection(HttpRequestBase request) {
+ if (request != null) {
+ request.releaseConnection();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/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
new file mode 100644
index 0000000..50783fa
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
@@ -0,0 +1,385 @@
+/*
+ * Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed 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.common.rest;
+
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonParser;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.client.methods.*;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.lang.reflect.Type;
+import java.net.URI;
+
+/**
+ * Rest client to handle rest requests
+ */
+public class RestClient {
+ private static final Log log = LogFactory.getLog(RestClient.class);
+ private DefaultHttpClient httpClient;
+ private String endPoint;
+ private String userName;
+ private String password;
+
+ public RestClient() {
+ PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
+ // Increase max total connection to 200
+ cm.setMaxTotal(200);
+ // Increase default max connection per route to 50
+ cm.setDefaultMaxPerRoute(50);
+
+ httpClient = new DefaultHttpClient(cm);
+ httpClient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpClient);
+ }
+
+ public RestClient(String endPoint, String userName, String password) {
+ this();
+ this.endPoint = endPoint;
+ this.userName = userName;
+ this.password = password;
+ }
+
+ /**
+ * Handle http post request. Return String
+ *
+ * @param resourcePath This should be REST endpoint
+ * @param jsonParamString The json string which should be executed from the post request
+ * @return The HttpResponse
+ * @throws Exception if any errors occur when executing the request
+ */
+ public HttpResponse doPost(URI resourcePath, String jsonParamString) throws Exception {
+ HttpPost postRequest = null;
+ try {
+ postRequest = new HttpPost(resourcePath);
+ StringEntity input = new StringEntity(jsonParamString);
+ input.setContentType("application/json");
+ postRequest.setEntity(input);
+
+ String userPass = getUsernamePassword();
+ String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+ postRequest.addHeader("Authorization", basicAuth);
+
+ return httpClient.execute(postRequest, new HttpResponseHandler());
+ } finally {
+ releaseConnection(postRequest);
+ }
+ }
+
+ /**
+ * Handle http get request. Return String
+ *
+ * @param resourcePath This should be REST endpoint
+ * @return The HttpResponse
+ * @throws org.apache.http.client.ClientProtocolException and IOException
+ * if any errors occur when executing the request
+ */
+ public HttpResponse doGet(URI resourcePath) throws Exception {
+ HttpGet getRequest = null;
+ try {
+ getRequest = new HttpGet(resourcePath);
+ getRequest.addHeader("Content-Type", "application/json");
+ String userPass = getUsernamePassword();
+ String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+ getRequest.addHeader("Authorization", basicAuth);
+
+ return httpClient.execute(getRequest, new HttpResponseHandler());
+ } finally {
+ releaseConnection(getRequest);
+ }
+ }
+
+ public HttpResponse doDelete(URI resourcePath) throws Exception {
+ HttpDelete httpDelete = null;
+ try {
+ httpDelete = new HttpDelete(resourcePath);
+ httpDelete.addHeader("Content-Type", "application/json");
+ String userPass = getUsernamePassword();
+ String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+ httpDelete.addHeader("Authorization", basicAuth);
+ return httpClient.execute(httpDelete, new HttpResponseHandler());
+ } finally {
+ releaseConnection(httpDelete);
+ }
+ }
+
+ public HttpResponse doPut(URI resourcePath, String jsonParamString) throws Exception {
+
+ HttpPut putRequest = null;
+ try {
+ putRequest = new HttpPut(resourcePath);
+
+ StringEntity input = new StringEntity(jsonParamString);
+ input.setContentType("application/json");
+ putRequest.setEntity(input);
+ String userPass = getUsernamePassword();
+ String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+ putRequest.addHeader("Authorization", basicAuth);
+ return httpClient.execute(putRequest, new HttpResponseHandler());
+ } finally {
+ releaseConnection(putRequest);
+ }
+ }
+
+ private void releaseConnection(HttpRequestBase request) {
+ if (request != null) {
+ request.releaseConnection();
+ }
+ }
+
+ 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());
+ }
+ }
+ }
+ 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);
+ }
+ }
+
+ 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());
+ }
+ }
+ }
+ 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);
+ }
+ }
+
+ 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());
+ }
+ }
+ }
+ 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);
+ }
+ }
+
+ 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 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);
+ }
+ }
+
+ 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());
+ }
+ }
+ }
+ 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);
+ }
+ }
+
+ public boolean removeEntity(String resourcePath, String identifier, String entityName) {
+ try {
+ URI uri = new URIBuilder(this.endPoint + "/" + resourcePath + "/" + identifier).build();
+ HttpResponse response = doDelete(uri);
+ if (response != null) {
+ if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
+ return true;
+ } 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());
+ }
+ }
+ }
+ String msg = "An unknown error occurred while removing the " + entityName;
+ log.error(msg);
+ throw new RuntimeException(msg);
+ } catch (Exception e) {
+ String message = "Could not remove " + entityName;
+ log.error(message, e);
+ throw new RuntimeException(message, e);
+ }
+ }
+
+ 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());
+ }
+ }
+ }
+ 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);
+ }
+ }
+
+ /**
+ * Get the json string from the artifacts directory
+ *
+ * @param filePath path of the artifacts
+ * @return json string of the relevant artifact
+ * @throws FileNotFoundException
+ */
+ public String getJsonStringFromFile(String filePath) throws FileNotFoundException {
+ JsonParser parser = new JsonParser();
+ Object object = parser.parse(new FileReader(getResourcesFolderPath() + filePath));
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ Gson gson = gsonBuilder.create();
+ return gson.toJson(object);
+ }
+
+ /**
+ * Get resources folder path
+ *
+ * @return the resource path
+ */
+ private String getResourcesFolderPath() {
+ String path = getClass().getResource("/").getPath();
+ return StringUtils.removeEnd(path, File.separator);
+ }
+
+ /**
+ * Get the username and password
+ *
+ * @return username:password
+ */
+ private String getUsernamePassword() {
+ return this.userName + ":" + this.password;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/WebClientWrapper.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/WebClientWrapper.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/WebClientWrapper.java
new file mode 100644
index 0000000..c507cbd
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/WebClientWrapper.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed 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.common.rest;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+public class WebClientWrapper {
+ public static HttpClient wrapClient(HttpClient base) {
+ try {
+ SSLContext ctx = SSLContext.getInstance("TLS");
+ X509TrustManager tm = new X509TrustManager() {
+ public void checkClientTrusted(X509Certificate[] xcs,
+ String string) throws CertificateException {
+ }
+
+ public void checkServerTrusted(X509Certificate[] xcs,
+ String string) throws CertificateException {
+ }
+
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+ };
+ ctx.init(null, new TrustManager[]{tm}, null);
+ SSLSocketFactory ssf = new SSLSocketFactory(ctx);
+ ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+ ClientConnectionManager ccm = base.getConnectionManager();
+ SchemeRegistry sr = ccm.getSchemeRegistry();
+ sr.register(new Scheme("https", ssf, 443));
+ return new DefaultHttpClient(ccm, base.getParams());
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/products/stratos/modules/integration/test-integration/pom.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/pom.xml b/products/stratos/modules/integration/test-integration/pom.xml
new file mode 100755
index 0000000..d27916c
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/pom.xml
@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-integration</artifactId>
+ <version>4.1.3-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>stratos-test-integration</artifactId>
+ <name>Apache Stratos - Integration Tests</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-exec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon.automation</groupId>
+ <artifactId>org.wso2.carbon.automation.test.utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon.automationutils</groupId>
+ <artifactId>org.wso2.carbon.integration.common.admin.client</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon.automation</groupId>
+ <artifactId>org.wso2.carbon.automation.extensions</artifactId>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.tomcat.embed</groupId>
+ <artifactId>tomcat-embed-logging-juli</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon.automationutils</groupId>
+ <artifactId>org.wso2.carbon.integration.common.utils</artifactId>
+ <scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>log4j-over-slf4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jul-to-slf4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon.automation</groupId>
+ <artifactId>org.wso2.carbon.automation.engine</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>SecVerifier</artifactId>
+ <type>aar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-all</artifactId>
+ <version>5.10.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents.wso2</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>${httpcore.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents.wso2</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${httpclient.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.messaging</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.mock.iaas.client</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon.automationutils</groupId>
+ <artifactId>org.wso2.carbon.integration.common.extensions</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.integration.common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <inherited>false</inherited>
+ <configuration>
+ <argLine>-Xmx512m -XX:PermSize=256m -XX:MaxPermSize=512m</argLine>
+ <systemProperties>
+ <maven.test.haltafterfailure>false</maven.test.haltafterfailure>
+ <property>
+ <name>carbon.zip</name>
+ <value>
+ ${basedir}/../../distribution/target/${stratos.distribution.name}-${project.version}.zip
+ </value>
+ </property>
+ <property>
+ <name>framework.resource.location</name>
+ <value>${basedir}/src/test/resources/</value>
+ </property>
+ <property>
+ <name>server.list</name>
+ <value>STRATOS</value>
+ </property>
+ <property>
+ <name>usedefaultlisteners</name>
+ <value>false</value>
+ </property>
+ <sec.verifier.dir>${basedir}/target/security-verifier/</sec.verifier.dir>
+ <instr.file>${basedir}/src/test/resources/instrumentation.txt</instr.file>
+ <filters.file>${basedir}/src/test/resources/filters.txt</filters.file>
+ </systemProperties>
+ <suiteXmlFiles>
+ <suiteXmlFile>${basedir}/src/test/resources/stratos-testng.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ <workingDirectory>${basedir}/target</workingDirectory>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-jacocodependencies</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/jacoco</outputDirectory>
+ <includeTypes>jar</includeTypes>
+ <includeArtifactIds>org.jacoco.agent</includeArtifactIds>
+ </configuration>
+ </execution>
+ <execution>
+ <id>copy-secVerifier</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/target/security-verifier</outputDirectory>
+ <includeTypes>aar</includeTypes>
+ <includeArtifactIds>SecVerifier</includeArtifactIds>
+ <stripVersion>true</stripVersion>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java
new file mode 100644
index 0000000..6bcb8a7
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2005-2015 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stratos.integration.tests;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.integration.common.Util;
+import org.apache.stratos.integration.common.rest.IntegrationMockClient;
+import org.apache.stratos.integration.common.rest.RestClient;
+import org.wso2.carbon.automation.engine.context.AutomationContext;
+import org.wso2.carbon.automation.engine.context.TestUserMode;
+
+import java.io.File;
+import java.net.URL;
+
+public class StratosIntegrationTest {
+ private static final Log log = LogFactory.getLog(StratosIntegrationTest.class);
+ protected AutomationContext stratosAutomationCtx;
+ protected String adminUsername;
+ protected String adminPassword;
+ protected String stratosBackendURL;
+ protected RestClient restClient;
+ protected IntegrationMockClient mockIaasApiClient;
+ public static final int GLOBAL_TEST_TIMEOUT = 5 * 60 * 1000;
+ public static final int APPLICATION_TEST_TIMEOUT = 20 * 60 * 1000;
+
+ public StratosIntegrationTest() {
+ try {
+ stratosAutomationCtx = new AutomationContext("STRATOS", "stratos-001", TestUserMode.SUPER_TENANT_ADMIN);
+ adminUsername = stratosAutomationCtx.getConfigurationValue
+ ("/automation/userManagement/superTenant/tenant/admin/user/userName");
+ adminPassword = stratosAutomationCtx.getConfigurationValue
+ ("/automation/userManagement/superTenant/tenant/admin/user/password");
+ stratosBackendURL = stratosAutomationCtx.getContextUrls().getWebAppURL();
+ restClient = new RestClient(stratosBackendURL, adminUsername, adminPassword);
+ mockIaasApiClient = new IntegrationMockClient(stratosBackendURL + "/mock-iaas/api");
+ setSystemproperties();
+ }
+ catch (Exception e) {
+ log.error("Could not initialize StratosIntegrationTest base parameters");
+ }
+ }
+
+ public void setSystemproperties() {
+ URL resourceUrl = getClass().getResource(File.separator + "keystores" + File.separator
+ + "products" + File.separator + "wso2carbon.jks");
+ System.setProperty("javax.net.ssl.trustStore", resourceUrl.getPath());
+ System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
+ System.setProperty("javax.net.ssl.trustStoreType", "JKS");
+ log.info("trustStore set to " + resourceUrl.getPath());
+
+ // Set jndi.properties.dir system property for initializing event receivers
+ System.setProperty("jndi.properties.dir", Util.getCommonResourcesFolderPath());
+ try {
+ String autoscalerServiceURL = stratosAutomationCtx.getContextUrls().getSecureServiceUrl() +
+ "/AutoscalerService";
+ System.setProperty(StratosConstants.AUTOSCALER_SERVICE_URL, autoscalerServiceURL);
+ log.info("Autoscaler service URL set to " + autoscalerServiceURL);
+ }
+ catch (Exception e) {
+ throw new RuntimeException("Could not set autoscaler service URL system property");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/395be450/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
new file mode 100644
index 0000000..fc14469
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java
@@ -0,0 +1,235 @@
+/*
+ * 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(SampleApplicationsTest.class);
+ private static final String RESOURCES_PATH = "/application-bursting-test";
+
+
+ @Test(timeOut = APPLICATION_TEST_TIMEOUT)
+ 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/395be450/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
new file mode 100644
index 0000000..310f644
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTest.java
@@ -0,0 +1,247 @@
+/*
+ * 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 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)
+ 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);
+
+ topologyHandler.assertGroupInstanceCount(bean.getApplicationId(), "group3-application-update-test", 2);
+
+ topologyHandler.assertClusterMinMemberCount(bean.getApplicationId(), 2);
+
+ 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");
+
+ 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);
+ }
+ }
+}
\ No newline at end of file