Skip to content

Commit

Permalink
Merge pull request #210 from sanethd/master
Browse files Browse the repository at this point in the history
Add unique API names fro each testcase and removed youtube API dependency
  • Loading branch information
rswijesena committed Jun 5, 2015
2 parents 438574d + 47970b2 commit 3460889
Show file tree
Hide file tree
Showing 32 changed files with 619 additions and 335 deletions.
4 changes: 4 additions & 0 deletions modules/integration/tests-common/admin-clients/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ under the License.
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.priority.executors.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.deployment</groupId>
<artifactId>org.wso2.carbon.webapp.mgt.stub</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.rest.api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.wso2.am.admin.clients.webapp;

import org.apache.axis2.AxisFault;
import org.wso2.carbon.integration.common.admin.client.utils.AuthenticateStubUtil;
import org.wso2.carbon.webapp.mgt.stub.WebappAdminStub;
import org.wso2.carbon.webapp.mgt.stub.types.carbon.VersionedWebappMetadata;
import org.wso2.carbon.webapp.mgt.stub.types.carbon.WebappMetadata;
import org.wso2.carbon.webapp.mgt.stub.types.carbon.WebappUploadData;
import org.wso2.carbon.webapp.mgt.stub.types.carbon.WebappsWrapper;

import javax.activation.DataHandler;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

/**
* Client that enable the functions of WebappAdmin service.
*/
public class WebAppAdminClient {
private WebappAdminStub webappAdminStub;

public WebAppAdminClient(String backendUrl, String sessionCookie) throws AxisFault {
String serviceName = "WebappAdmin";
String endPoint = backendUrl + serviceName;
webappAdminStub = new WebappAdminStub(endPoint);
AuthenticateStubUtil.authenticateStub(sessionCookie, webappAdminStub);
}

/**
* Upload war files to the "repository/deployment/server/webapps/" location.
* Those war files will get automatically deployed.
*
* @param filePath - path to the location where the war files if locally located.
* @return boolean - Return true if WebApp upload success else false.
* @throws RemoteException - Exception occurs when uploading an war file using WebappAdminStub.
* @throws MalformedURLException - Exception occurs when creating the URL Object.
*/

public boolean uploadWarFile(String filePath) throws RemoteException, MalformedURLException {
File file = new File(filePath);
String fileName = file.getName();
URL url = new URL("file://" + filePath);
DataHandler dh = new DataHandler(url);
WebappUploadData webApp;
webApp = new WebappUploadData();
webApp.setFileName(fileName);
webApp.setDataHandler(dh);
return webappAdminStub.uploadWebapp(new WebappUploadData[]{webApp});

}

/**
* Get WebApp summary in Paged manner.
*
* @param searchString - Search string for get the WebAPP summary.
* @param webAppType - Type of the WebApp.
* @param webAppState - State of the WebApp.
* @param pageNo - Page no of the results.
* @throws RemoteException - Exception occurs when retrieving the WebAppSummary from the WebappAdminStub
*/
public WebappsWrapper getPagedWebAppsSummary(String searchString, String webAppType, String webAppState, int pageNo)
throws RemoteException {
return webappAdminStub.getPagedWebappsSummary(searchString, webAppType, webAppState, pageNo);
}


/**
* Get WebApp list for the given search String.
*
* @param webAppNameSearchString - String that contains the data to filter the WebApp.
* @return List - List of WebApps that matches to the given search String.
* @throws RemoteException - Exception occurs when call the method getPagedWebAppsSummary().
*/
public List<String> getWebAppList(String webAppNameSearchString) throws RemoteException {
List<String> list = new ArrayList<String>();
WebappsWrapper wrapper = getPagedWebAppsSummary(webAppNameSearchString, "ALL", "ALL", 0);
VersionedWebappMetadata[] webAppGroups = wrapper.getWebapps();

if (webAppGroups != null) {
for (VersionedWebappMetadata webAppGroup : webAppGroups) {
for (WebappMetadata metaData : webAppGroup.getVersionGroups()) {
list.add(metaData.getWebappFile());
}
}
}
return list;
}

/**
* Get faulty WebApp summary in Paged manner.
*
* @param searchString - Search string for get the WebAPP summary.
* @param webAppType - Type of the WebApp.
* @param pageNo - State of the WebApp.
* @throws RemoteException - Exception occurs when retrieving the WebAppSummary from the WebappAdminStub
*/
public WebappsWrapper getPagedFaultyWebAppsSummary(String searchString, String webAppType, int pageNo)
throws RemoteException {
return webappAdminStub.getPagedFaultyWebappsSummary(searchString, webAppType, pageNo);
}

/**
* Get faulty WebApp list for the given search String.
*
* @param webAppNameSearchString - String that contains the data to filter the WebApp.
* @return - List of WebApps that matches to the given search String.
* @throws RemoteException - Exception occurs when call the method getPagedFaultyWebAppsSummary().
*/
public List<String> getFaultyWebAppList(String webAppNameSearchString) throws RemoteException {
List<String> list = new ArrayList<String>();
WebappsWrapper wrapper = getPagedFaultyWebAppsSummary(webAppNameSearchString, "ALL", 0);
VersionedWebappMetadata[] webAppGroups = wrapper.getWebapps();

if (webAppGroups != null && webAppGroups[0].getVersionGroups() != null) {
for (WebappMetadata metaData : webAppGroups[0].getVersionGroups()) {
list.add(metaData.getWebappFile());
}
}
return list;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.wso2.am.integration.test.utils.webapp;

import org.apache.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.am.admin.clients.webapp.WebAppAdminClient;
import org.wso2.am.integration.test.utils.APIManagerIntegrationTestException;

import java.rmi.RemoteException;
import java.util.Calendar;
import java.util.List;

/**
* Util that is enabled the more utility methods for handling the WebApps
*/
public class WebAppDeploymentUtil {
private static Log log = LogFactory.getLog(WebAppDeploymentUtil.class);
private static int WEB_APP_DEPLOYMENT_DELAY = 90 * 1000;

/**
* Check whether the given web app is deployed correctly. This method will wait maximum 90 seconds
* until it get deployed. check for the web app d
*
* @param backEndUrl - Backend URL of the server where the web app is host.
* @param sessionCookie - valid session cookie of the server where the web app is host.
* @param webAppFileName - File name of the web app that want to check for the deployment.
* @return boolean - if WebAPp is get deployed withing 90 seconds or else return false.
* @throws APIManagerIntegrationTestException - Exception throws when creating WebAppAdminClient object and calling
* methods of WebAppAdminClient class.
*/
public static boolean isWebApplicationDeployed(String backEndUrl, String sessionCookie, String webAppFileName)
throws APIManagerIntegrationTestException {
log.info("waiting " + WEB_APP_DEPLOYMENT_DELAY + " millis for Service deployment " + webAppFileName);

WebAppAdminClient webAppAdminClient;
try {
webAppAdminClient = new WebAppAdminClient(backEndUrl, sessionCookie);
} catch (AxisFault axisFault) {
throw new APIManagerIntegrationTestException("AxisFault Exception occurs when creating the WebAppAdminClient" +
" object ", axisFault);
}

List<String> webAppList;
List<String> faultyWebAppList;
String webAppName = webAppFileName + ".war";
boolean isWebAppDeployed = false;
Calendar startTime = Calendar.getInstance();
long time;
while ((time = (Calendar.getInstance().getTimeInMillis() - startTime.getTimeInMillis())) <
WEB_APP_DEPLOYMENT_DELAY) {
try {
webAppList = webAppAdminClient.getWebAppList(webAppFileName);
faultyWebAppList = webAppAdminClient.getFaultyWebAppList(webAppFileName);
} catch (RemoteException e) {
throw new APIManagerIntegrationTestException("RemoteException occurs while retrieving the web app list" +
" from WebAppAdminClient.", e);
}
//check in the faulty WebApp list
for (String faultWebAppName : faultyWebAppList) {
if (webAppName.equalsIgnoreCase(faultWebAppName)) {
isWebAppDeployed = false;
log.info(webAppFileName + "- Web Application is faulty");
return isWebAppDeployed;
}
}
//check in the successfully deployed WebApp list
for (String name : webAppList) {
if (webAppName.equalsIgnoreCase(name)) {
isWebAppDeployed = true;
log.info(webAppFileName + " Web Application deployed in " + time + " millis");
return isWebAppDeployed;
}
}

try {
//Sleeping 500 milliseconds before the next check of the deployment.
Thread.sleep(500);
} catch (InterruptedException ignored) {
log.warn("InterruptedException occurs while waiting sleep for 500 milliseconds");
}
}
return isWebAppDeployed;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@
*/

public class APIAccessibilityOfPublishedOldAPIAndPublishedCopyAPITestCase extends APIManagerLifecycleBaseTest {
private static final String API_NAME = "APILifeCycleTestAPI";
private static final String API_CONTEXT = "testAPI";
private static final String API_TAGS = "youtube, video, media";
private static final String API_END_POINT_URL = "http://gdata.youtube.com/feeds/api/standardfeeds";
private static final String API_NAME = "APIAccessibilityOfOldAndCopyAPITest";
private static final String API_CONTEXT = "APIAccessibilityOfOldAndCopyAPI";
private static final String API_TAGS = "testTag1, testTag2, testTag3";
private static final String API_DESCRIPTION = "This is test API create by API manager integration test";
private static final String API_END_POINT_METHOD = "/most_popular";
private static final String API_RESPONSE_DATA = "<feed";
private static final String API_END_POINT_METHOD = "/customers/123";
private static final String API_RESPONSE_DATA = "<id>123</id><name>John</name></Customer>";
private static final String API_VERSION_1_0_0 = "1.0.0";
private static final String API_VERSION_2_0_0 = "2.0.0";
private static final String APPLICATION_NAME = "APIAccessibilityOfPublishedOldAPIAndPublishedCopyAPITestCase";
private static final String API_END_POINT_POSTFIX_URL = "jaxrs_basic/services/customers/customerservice/";
private String apiEndPointUrl;
private APIIdentifier apiIdentifierAPI1Version1;
private APIIdentifier apiIdentifierAPI1Version2;
private String providerName;
Expand All @@ -71,10 +72,11 @@ public class APIAccessibilityOfPublishedOldAPIAndPublishedCopyAPITestCase extend
@BeforeClass(alwaysRun = true)
public void initialize() throws APIManagerIntegrationTestException, XPathExpressionException, MalformedURLException {
super.init();
apiEndPointUrl = gatewayUrls.getWebAppURLHttp() + API_END_POINT_POSTFIX_URL;
providerName = publisherContext.getContextTenant().getContextUser().getUserName();
apiCreationRequestBean =
new APICreationRequestBean(API_NAME, API_CONTEXT, API_VERSION_1_0_0, providerName,
new URL(API_END_POINT_URL));
new URL(apiEndPointUrl));
apiCreationRequestBean.setTags(API_TAGS);
apiCreationRequestBean.setDescription(API_DESCRIPTION);
apiIdentifierAPI1Version1 = new APIIdentifier(providerName, API_NAME, API_VERSION_1_0_0);
Expand Down Expand Up @@ -180,16 +182,17 @@ public void testAccessibilityOfPublishedOldAPIAndPublishedCopyAPI() throws APIMa
String accessToken = generateApplicationKeys(apiStoreClientUser1, APPLICATION_NAME).getAccessToken();
// Create requestHeaders
Map<String, String> requestHeaders = new HashMap<String, String>();
requestHeaders.put("accept", "text/xml");
requestHeaders.put("Authorization", "Bearer " + accessToken);
//Invoke old version
HttpResponse oldVersionInvokeResponse =
HttpRequestUtil.doGet(GATEWAY_WEB_APP_URL + API_CONTEXT + "/" + API_VERSION_1_0_0 +
HttpRequestUtil.doGet(gatewayWebAppUrl + API_CONTEXT + "/" + API_VERSION_1_0_0 +
API_END_POINT_METHOD, requestHeaders);
assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched");
assertTrue(oldVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), "Response data mismatched");
//Invoke new version
HttpResponse newVersionInvokeResponse =
HttpRequestUtil.doGet(GATEWAY_WEB_APP_URL + API_CONTEXT + "/" + API_VERSION_2_0_0 +
HttpRequestUtil.doGet(gatewayWebAppUrl + API_CONTEXT + "/" + API_VERSION_2_0_0 +
API_END_POINT_METHOD, requestHeaders);
assertEquals(newVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched");
assertTrue(newVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), "Response data mismatched");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.wso2.am.admin.clients.webapp.WebAppAdminClient;
import org.wso2.am.integration.test.utils.webapp.WebAppDeploymentUtil;
import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment;
import org.wso2.carbon.automation.engine.annotations.SetEnvironment;
import org.wso2.carbon.automation.test.utils.common.FileManager;
import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;

Expand All @@ -37,6 +40,10 @@ public class APIManagerConfigurationChangeTest extends APIManagerLifecycleBaseTe
private static final Log log = LogFactory.getLog(APIManagerConfigurationChangeTest.class);
private ServerConfigurationManager serverManager;
private static final String APIM_CONFIG_XML = "api-manager.xml";
private static final String WEB_APP_NAME = "jaxrs_basic";
private static final String WEB_APP_FILE_NAME = "jaxrs_basic.war";
private String targetPathInServer;
private String sessionId;

@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@BeforeTest(alwaysRun = true)
Expand All @@ -55,14 +62,30 @@ public void startChangeAPIMConfigureXml() throws Exception {
serverManager.applyConfigurationWithoutRestart(sourceFile, targetFile, true);
log.info("api-manager.xml configuration file copy from :" + apimConfigArtifactLocation +
" to :" + apimRepositoryConfigLocation);

String sourcePath =
TestConfigurationProvider.getResourceLocation() + File.separator + "artifacts" + File.separator + "AM" +
File.separator + "lifecycletest" + File.separator + WEB_APP_FILE_NAME;
targetPathInServer =
CARBON_HOME + File.separator + "repository" + File.separator + "deployment" + File.separator +
"server" + File.separator + "webapps" + File.separator + WEB_APP_FILE_NAME;

sessionId = createSession(gatewayContext);
WebAppAdminClient webAppAdminClient =
new WebAppAdminClient(gatewayContext.getContextUrls().getBackEndUrl(), sessionId);
webAppAdminClient.uploadWarFile(sourcePath);
WebAppDeploymentUtil.isWebApplicationDeployed(gatewayContext.getContextUrls().getBackEndUrl(),
sessionId, WEB_APP_NAME);
serverManager.restartGracefully();


}

@AfterTest(alwaysRun = true)
public void startRestoreAPIMConfigureXml() throws Exception {
serverManager.restoreToLastConfiguration();
log.info("Restore the api-manager.xml configuration file");
FileManager.deleteFile(targetPathInServer);
serverManager.restartGracefully();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class APIManagerLifecycleBaseTest extends APIMIntegrationBaseTest {
protected static final int HTTP_RESPONSE_CODE_FORBIDDEN = Response.Status.FORBIDDEN.getStatusCode();
protected static final String HTTP_RESPONSE_DATA_API_BLOCK =
"<am:code>700700</am:code><am:message>API blocked</am:message>";
protected static final String HTTP_RESPONSE_DATA_INVALID_CREDENTIALS =
"<ams:message>Invalid Credentials</ams:message>";
protected static final String UNCLASSIFIED_AUTHENTICATION_FAILURE =
"<ams:message>Unclassified Authentication Failure</ams:message>";
protected static final String HTTP_RESPONSE_DATA_NOT_FOUND =
"<am:code>404</am:code><am:type>Status report</am:type><am:message>Not Found</am:message>";
protected static final int GOLD_INVOCATION_LIMIT_PER_MIN = 20;
Expand All @@ -68,12 +68,12 @@ public class APIManagerLifecycleBaseTest extends APIMIntegrationBaseTest {
"You have exceeded your quota</amt:description>";
protected static final int THROTTLING_UNIT_TIME = 60000;
protected static final int THROTTLING_ADDITIONAL_WAIT_TIME = 5000;
protected static String GATEWAY_WEB_APP_URL;
protected static String gatewayWebAppUrl;

@BeforeClass(alwaysRun = true)
public void init() throws APIManagerIntegrationTestException {
super.init();
GATEWAY_WEB_APP_URL = gatewayUrls.getWebAppURLNhttp();
gatewayWebAppUrl = gatewayUrls.getWebAppURLNhttp();
}

/**
Expand Down
Loading

0 comments on commit 3460889

Please sign in to comment.