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 23:50:34 UTC
[08/21] stratos git commit: Uplifting automation engine to v4.4.3,
dynamically pick ports for integration tests
http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/extensions/StratosServerExtension.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/extensions/StratosServerExtension.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/extensions/StratosServerExtension.java
new file mode 100644
index 0000000..3de05c3
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/extensions/StratosServerExtension.java
@@ -0,0 +1,196 @@
+/*
+ * 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.extensions;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.stratos.common.test.TestLogAppender;
+import org.apache.stratos.integration.common.StratosTestServerManager;
+import org.apache.stratos.integration.common.Util;
+import org.wso2.carbon.automation.engine.context.AutomationContext;
+import org.wso2.carbon.automation.engine.context.TestUserMode;
+import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException;
+import org.wso2.carbon.automation.engine.extensions.ExecutionListenerExtension;
+import org.wso2.carbon.automation.extensions.ExtensionConstants;
+
+import java.io.File;
+import java.net.URI;
+
+import static org.testng.Assert.assertNotNull;
+
+public class StratosServerExtension extends ExecutionListenerExtension {
+ private static final Log log = LogFactory.getLog(StratosServerExtension.class);
+ private TestLogAppender testLogAppender;
+ private static StratosTestServerManager stratosTestServerManager;
+ private static BrokerService broker;
+
+ @Override
+ public void initiate() throws AutomationFrameworkException {
+ broker = new BrokerService();
+ testLogAppender = new TestLogAppender();
+ }
+
+ @Override
+ public void onExecutionStart() throws AutomationFrameworkException {
+ Logger.getRootLogger().addAppender(testLogAppender);
+ Logger.getRootLogger().setLevel(Level.INFO);
+ int activeMQDynamicPort = startActiveMQServer();
+ startStratosServer(activeMQDynamicPort);
+ }
+
+ private void startStratosServer(int activeMQDynamicPort) throws AutomationFrameworkException {
+ try {
+ log.info("Setting up Stratos server...");
+ AutomationContext stratosAutomationCtx =
+ new AutomationContext("STRATOS", "stratos-001", TestUserMode.SUPER_TENANT_ADMIN);
+ String stratosInitPortOffsetStr =
+ getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND);
+ if (stratosInitPortOffsetStr == null) {
+ throw new AutomationFrameworkException("Port offset not found in automation.xml");
+ }
+ int stratosInitPortOffset = Integer.parseInt(stratosInitPortOffsetStr);
+ int stratosInitSecurePort = Util.STRATOS_DEFAULT_SECURE_PORT + stratosInitPortOffset;
+ int stratosInitPort = Util.STRATOS_DEFAULT_PORT + stratosInitPortOffset;
+ int thriftInitPort = Util.THRIFT_DEFAULT_PORT + stratosInitPortOffset;
+ int thriftInitSecurePort = Util.THRIFT_DEFAULT_SECURE_PORT + stratosInitPortOffset;
+ int rmiRegistryPort = Util.STRATOS_DEFAULT_RMI_REGISTRY_PORT + stratosInitPortOffset;
+ int rmiServerPort = Util.STRATOS_DEFAULT_RMI_SERVER_PORT + stratosInitPortOffset;
+
+ while (!Util.isPortAvailable(stratosInitPort) || !Util.isPortAvailable(stratosInitSecurePort) ||
+ !Util.isPortAvailable(thriftInitPort) || !Util.isPortAvailable(thriftInitSecurePort) ||
+ !Util.isPortAvailable(rmiRegistryPort) || !Util.isPortAvailable(rmiServerPort)) {
+ stratosInitPortOffset++;
+ stratosInitSecurePort++;
+ stratosInitPort++;
+ thriftInitPort++;
+ thriftInitSecurePort++;
+ rmiRegistryPort++;
+ rmiServerPort++;
+ }
+ getParameters()
+ .put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, String.valueOf(stratosInitPortOffset));
+ stratosTestServerManager =
+ new StratosTestServerManager(stratosAutomationCtx, System.getProperty(Util.CARBON_ZIP_KEY),
+ getParameters());
+ stratosTestServerManager.setStratosDynamicPort(stratosInitPort);
+ stratosTestServerManager.setStratosSecureDynamicPort(stratosInitSecurePort);
+ stratosTestServerManager.setThriftDynamicPort(thriftInitPort);
+ stratosTestServerManager.setThriftSecureDynamicPort(thriftInitSecurePort);
+ stratosTestServerManager.setActiveMQDynamicPort(activeMQDynamicPort);
+ stratosTestServerManager.setWebAppURL("http://localhost:" + stratosInitPort);
+ stratosTestServerManager.setWebAppURLHttps("https://localhost:" + stratosInitSecurePort);
+
+ log.info("Stratos server dynamic port offset: " + stratosTestServerManager.getPortOffset());
+ log.info("Stratos dynamic backend URL: " + stratosTestServerManager.getWebAppURL());
+ log.info("Stratos secure dynamic backend URL: " + stratosTestServerManager.getWebAppURLHttps());
+ long time3 = System.currentTimeMillis();
+ String carbonHome = stratosTestServerManager.startServer();
+ assertNotNull(carbonHome, "CARBON_HOME is null");
+ while (!serverStarted()) {
+ log.info("Waiting for topology to be initialized...");
+ Thread.sleep(5000);
+ }
+ while (!mockServiceStarted()) {
+ log.info("Waiting for mock service to be initialized...");
+ Thread.sleep(1000);
+ }
+ long time4 = System.currentTimeMillis();
+ log.info(String.format("Stratos server started in %d sec", (time4 - time3) / 1000));
+ }
+ catch (Exception e) {
+ throw new AutomationFrameworkException("Could not start Stratos server", e);
+ }
+ }
+
+ @Override
+ public void onExecutionFinish() throws AutomationFrameworkException {
+ try {
+ stratosTestServerManager.stopServer();
+ log.info("Stopped Stratos server");
+ }
+ catch (Exception e) {
+ log.error("Could not stop Stratos server", e);
+ }
+
+ try {
+ broker.stop();
+ log.info("Stopped ActiveMQ server");
+ }
+ catch (Exception e) {
+ log.error("Could not stop ActiveMQ server", e);
+ }
+ }
+
+ private int startActiveMQServer() throws AutomationFrameworkException {
+ try {
+ String activemqBindAddress = getParameters().get(Util.ACTIVEMQ_BIND_ADDRESS);
+ if (activemqBindAddress == null) {
+ throw new AutomationFrameworkException("ActiveMQ bind address not found in automation.xml");
+ }
+ URI givenURI = new URI(activemqBindAddress);
+ int initAMQPort = givenURI.getPort();
+ // dynamically pick an open port starting from initial port given in automation.xml
+ while (!Util.isPortAvailable(initAMQPort)) {
+ initAMQPort++;
+ }
+ URI dynamicURL = new URI(givenURI.getScheme(), givenURI.getUserInfo(), givenURI.getHost(), initAMQPort,
+ givenURI.getPath(), givenURI.getQuery(), givenURI.getFragment());
+ long time1 = System.currentTimeMillis();
+ log.info("Starting ActiveMQ with dynamic bind address: " + dynamicURL.toString());
+ broker.setDataDirectory(StratosServerExtension.class.getResource(File.separator).getPath() +
+ File.separator + ".." + File.separator + "activemq-data");
+ broker.setBrokerName("testBroker");
+ broker.addConnector(dynamicURL.toString());
+ broker.start();
+ long time2 = System.currentTimeMillis();
+ log.info(String.format("ActiveMQ started in %d sec", (time2 - time1) / 1000));
+ return initAMQPort;
+ }
+ catch (Exception e) {
+ throw new AutomationFrameworkException("Could not start ActiveMQ", e);
+ }
+ }
+
+ private boolean serverStarted() {
+ for (String message : testLogAppender.getMessages()) {
+ if (message.contains("Topology initialized")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean mockServiceStarted() {
+ for (String message : testLogAppender.getMessages()) {
+ if (message.contains("Mock IaaS service component activated")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static StratosTestServerManager getStratosTestServerManager() {
+ return stratosTestServerManager;
+ }
+
+ public static BrokerService getBroker() {
+ return broker;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/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..7aefe1b
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/ErrorResponse.java
@@ -0,0 +1,56 @@
+/*
+ * 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.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/c0664270/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..fb35191
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponse.java
@@ -0,0 +1,59 @@
+/*
+ * 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.common.rest;
+
+/**
+ * Created by reka on 7/28/15.
+ */
+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/c0664270/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..e636ecd
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/HttpResponseHandler.java
@@ -0,0 +1,68 @@
+/*
+ * 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.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/c0664270/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..5582db7
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/IntegrationMockClient.java
@@ -0,0 +1,102 @@
+/*
+ * 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.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();
+ ErrorResponse errorResponse = gson.fromJson(response.getContent(), 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/c0664270/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..9b29e68
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
@@ -0,0 +1,403 @@
+/*
+ * 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.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.setUserName(userName);
+ this.setPassword(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.getUserName() + ":" + this.getPassword();
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/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..3a2efd1
--- /dev/null
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/WebClientWrapper.java
@@ -0,0 +1,62 @@
+/*
+ * 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.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/c0664270/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..15af42c
--- /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.2.0-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/c0664270/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..9aa5fcd
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.integration.common.RestConstants;
+import org.apache.stratos.integration.common.extensions.StratosServerExtension;
+import org.apache.stratos.integration.common.rest.IntegrationMockClient;
+import org.apache.stratos.integration.common.rest.RestClient;
+import org.apache.stratos.messaging.domain.tenant.Tenant;
+import org.wso2.carbon.automation.engine.context.AutomationContext;
+import org.wso2.carbon.automation.engine.context.TestUserMode;
+
+import static org.testng.Assert.assertEquals;
+
+public class StratosIntegrationTest {
+ private static final Log log = LogFactory.getLog(StratosIntegrationTest.class);
+ protected AutomationContext stratosAutomationCtx;
+ protected String adminUsername;
+ protected String adminPassword;
+ protected String tenant1UserName;
+ protected String tenant1Password;
+ protected String tenant2UserName;
+ protected String tenant2Password;
+ protected String stratosBackendURL;
+ protected RestClient restClientAdmin;
+ protected RestClient restClientTenant1;
+ protected RestClient restClientTenant2;
+ protected int tenant1Id;
+ protected int tenant2Id;
+ protected IntegrationMockClient mockIaasApiClient;
+ public static final int GLOBAL_TEST_TIMEOUT = 5 * 60 * 1000; // 5 mins
+ public static final int APPLICATION_TEST_TIMEOUT = 20 * 60 * 1000; // 20 mins
+ private static volatile Boolean tenantsInitialized = false;
+
+ public StratosIntegrationTest() {
+ init();
+ if (!tenantsInitialized) {
+ synchronized (StratosIntegrationTest.class) {
+ if (!tenantsInitialized) {
+ populateTenants();
+ tenantsInitialized = true;
+ }
+ }
+ }
+
+ Tenant tenant1 = (Tenant) restClientAdmin
+ .getEntity(RestConstants.TENANT_API, RestConstants.TENANT1_GET_RESOURCE, Tenant.class,
+ RestConstants.TENANTS_NAME);
+ tenant1Id = tenant1.getTenantId();
+ Tenant tenant2 = (Tenant) restClientAdmin
+ .getEntity(RestConstants.TENANT_API, RestConstants.TENANT2_GET_RESOURCE, Tenant.class,
+ RestConstants.TENANTS_NAME);
+ tenant2Id = tenant2.getTenantId();
+ }
+
+ private void init() {
+ try {
+ log.info("Initializing StratosIntegrationTest...");
+ 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");
+
+ // Do not rely on automation context for context URLs since ports are dynamically picked
+ stratosBackendURL = StratosServerExtension.getStratosTestServerManager().getWebAppURL();
+ restClientAdmin = new RestClient(stratosBackendURL, adminUsername, adminPassword);
+ mockIaasApiClient = new IntegrationMockClient(stratosBackendURL + "/mock-iaas/api");
+
+ tenant1UserName = "admin@test1.com";
+ tenant1Password = "admin123";
+ tenant2UserName = "admin@test2.com";
+ tenant2Password = "admin123";
+
+ restClientTenant1 = new RestClient(stratosBackendURL, tenant1UserName, tenant1Password);
+ restClientTenant2 = new RestClient(stratosBackendURL, tenant2UserName, tenant2Password);
+ }
+ catch (Exception e) {
+ throw new RuntimeException("Could not initialize StratosIntegrationTest", e);
+ }
+ }
+
+ private void populateTenants() {
+ log.info("Creating tenants in Stratos server...");
+ boolean addedTenant1 = restClientAdmin
+ .addEntity(RestConstants.TENANT1_RESOURCE, RestConstants.TENANT_API, RestConstants.TENANTS_NAME);
+ assertEquals(addedTenant1, true);
+ boolean addedTenant2 = restClientAdmin
+ .addEntity(RestConstants.TENANT2_RESOURCE, RestConstants.TENANT_API, RestConstants.TENANTS_NAME);
+ assertEquals(addedTenant2, true);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/c0664270/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..659682b
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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.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----------------------------");
+
+ String autoscalingPolicyId = "autoscaling-policy-application-bursting-test";
+
+ boolean addedScalingPolicy =
+ restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
+ + "/" + autoscalingPolicyId + ".json",
+ RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
+ assertEquals(addedScalingPolicy, true);
+
+ boolean addedC1 = restClientTenant1.addEntity(
+ RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "esb-application-bursting-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertEquals(addedC1, true);
+
+ boolean addedC2 = restClientTenant1.addEntity(
+ RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "php-application-bursting-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertEquals(addedC2, true);
+
+ boolean addedC3 = restClientTenant1.addEntity(
+ RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "tomcat-application-bursting-test.json",
+ RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+ assertEquals(addedC3, true);
+
+ boolean addedG1 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+ "/" + "esb-php-group-application-bursting-test.json", RestConstants.CARTRIDGE_GROUPS,
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertEquals(addedG1, true);
+
+ CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClientTenant1.
+ 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 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+ "network-partition-application-bursting-test-1.json",
+ RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+ assertEquals(addedN1, true);
+
+ boolean addedN2 = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+ "network-partition-application-bursting-test-2.json",
+ RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+ assertEquals(addedN2, true);
+
+ boolean addedDep =
+ restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+ "deployment-policy-application-bursting-test.json",
+ RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+ assertEquals(addedDep, true);
+
+ boolean added = restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
+ "app-bursting-single-cartriddge-group.json", RestConstants.APPLICATIONS,
+ RestConstants.APPLICATIONS_NAME);
+ assertEquals(added, true);
+
+ ApplicationBean bean = (ApplicationBean) restClientTenant1.getEntity(RestConstants.APPLICATIONS,
+ "application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+ assertEquals(bean.getApplicationId(), "application-bursting-test");
+
+ boolean addAppPolicy =
+ restClientTenant1.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
+ "application-policy-application-bursting-test.json",
+ RestConstants.APPLICATION_POLICIES,
+ RestConstants.APPLICATION_POLICIES_NAME);
+ assertEquals(addAppPolicy, true);
+
+ ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClientTenant1.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 = restClientTenant1.deployEntity(resourcePath,
+ RestConstants.APPLICATIONS_NAME);
+ assertEquals(deployed, true);
+
+ //Application active handling
+ TopologyHandler.getInstance().assertApplicationStatus(bean.getApplicationId(),
+ ApplicationStatus.Active, tenant1Id);
+
+ //Group active handling
+ TopologyHandler.getInstance().assertGroupActivation(bean.getApplicationId(), tenant1Id);
+
+ //Cluster active handling
+ TopologyHandler.getInstance().assertClusterActivation(bean.getApplicationId(), tenant1Id);
+
+ boolean removedGroup = restClientTenant1
+ .removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertEquals(removedGroup, false);
+
+ boolean removedAuto = restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+ autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+ assertEquals(removedAuto, false);
+
+ boolean removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+ "network-partition-application-bursting-test-1",
+ RestConstants.NETWORK_PARTITIONS_NAME);
+ //Trying to remove the used network partition
+ assertEquals(removedNet, false);
+
+ boolean removedDep = restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+ "deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
+ assertEquals(removedDep, false);
+
+ //Un-deploying the application
+ String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "application-bursting-test" +
+ RestConstants.APPLICATIONS_UNDEPLOY;
+
+ boolean unDeployed = restClientTenant1.undeployEntity(resourcePathUndeploy,
+ RestConstants.APPLICATIONS_NAME);
+ assertEquals(unDeployed, true);
+
+ boolean undeploy = TopologyHandler.getInstance().assertApplicationUndeploy("application-bursting-test",
+ tenant1Id);
+ if (!undeploy) {
+ //Need to forcefully undeploy the application
+ log.info("Force undeployment is going to start for the [application] " + "application-bursting-test");
+
+ restClientTenant1.undeployEntity(RestConstants.APPLICATIONS + "/" + "application-bursting-test" +
+ RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
+
+ boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy(
+ "application-bursting-test", tenant1Id);
+ assertEquals(forceUndeployed, true, String.format("Forceful undeployment failed for the application %s",
+ "application-bursting-test"));
+
+ }
+
+ boolean removed = restClientTenant1.removeEntity(RestConstants.APPLICATIONS, "application-bursting-test",
+ RestConstants.APPLICATIONS_NAME);
+ assertEquals(removed, true);
+
+ ApplicationBean beanRemoved = (ApplicationBean) restClientTenant1.getEntity(RestConstants.APPLICATIONS,
+ "application-bursting-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+ assertEquals(beanRemoved, null);
+
+ removedGroup = restClientTenant1
+ .removeEntity(RestConstants.CARTRIDGE_GROUPS, "esb-php-group-application-bursting-test",
+ RestConstants.CARTRIDGE_GROUPS_NAME);
+ assertEquals(removedGroup, true);
+
+ boolean removedC1 =
+ restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "esb-application-bursting-test",
+ RestConstants.CARTRIDGES_NAME);
+ assertEquals(removedC1, true);
+
+ boolean removedC2 =
+ restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "php-application-bursting-test",
+ RestConstants.CARTRIDGES_NAME);
+ assertEquals(removedC2, true);
+
+ boolean removedC3 =
+ restClientTenant1.removeEntity(RestConstants.CARTRIDGES, "tomcat-application-bursting-test",
+ RestConstants.CARTRIDGES_NAME);
+ assertEquals(removedC3, true);
+
+ removedAuto = restClientTenant1.removeEntity(RestConstants.AUTOSCALING_POLICIES,
+ autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+ assertEquals(removedAuto, true);
+
+ removedDep = restClientTenant1.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
+ "deployment-policy-application-bursting-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
+ assertEquals(removedDep, true);
+
+ removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+ "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+ assertEquals(removedNet, false);
+
+ boolean removedN2 = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+ "network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME);
+ assertEquals(removedN2, false);
+
+ boolean removeAppPolicy = restClientTenant1.removeEntity(RestConstants.APPLICATION_POLICIES,
+ "application-policy-application-bursting-test", RestConstants.APPLICATION_POLICIES_NAME);
+ assertEquals(removeAppPolicy, true);
+
+ removedNet = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+ "network-partition-application-bursting-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+ assertEquals(removedNet, true);
+
+ removedN2 = restClientTenant1.removeEntity(RestConstants.NETWORK_PARTITIONS,
+ "network-partition-application-bursting-test-2", RestConstants.NETWORK_PARTITIONS_NAME);
+ assertEquals(removedN2, true);
+
+ log.info("----------------------------Ended application bursting test case----------------------------");
+
+ }
+ catch (Exception e) {
+ log.error("An error occurred while handling application bursting", e);
+ assertTrue(false, "An error occurred while handling application bursting");
+ }
+ }
+}
\ No newline at end of file