From a22d94d46d873837d16992aa7b221fd19b108ec4 Mon Sep 17 00:00:00 2001 From: sanethd Date: Mon, 16 Mar 2015 17:36:43 +0530 Subject: [PATCH] API manager lifecycle Test cases phase 2 --- .../APIManagerIntegrationTestException.java | 15 +- .../utils/clients/APIPublisherRestClient.java | 45 ++ .../utils/clients/APIStoreRestClient.java | 38 + ...shedOldAPIAndPublishedCopyAPITestCase.java | 179 +++++ .../api/lifecycle/APILifecycleTestCase.java | 675 ------------------ .../APIManagerConfigurationChangeTest.java | 76 ++ .../APIManagerLifecycleBaseTest.java | 538 ++++++++++++++ ...ublishingAndVisibilityInStoreTestCase.java | 115 +++ .../AccessibilityOfBlockAPITestCase.java | 124 ++++ ...atedOldAPIAndPublishedCopyAPITestCase.java | 197 +++++ ...dCopyAPIWithOutReSubscriptionTestCase.java | 152 ++++ ...IAndCopyAPIWithReSubscriptionTestCase.java | 189 +++++ .../AccessibilityOfRetireAPITestCase.java | 139 ++++ .../ChangeAPIBackendURLTestCase.java | 132 ++++ .../ChangeAPIEndPointURLTestCase.java | 132 ++++ .../api/lifecycle/ChangeAPITagsTestCase.java | 168 +++++ ...APIAndCheckUpdatedInformationTestCase.java | 101 +++ ...IContextAndCheckAccessibilityTestCase.java | 152 ++++ .../src/test/resources/testng.xml | 26 + 19 files changed, 2516 insertions(+), 677 deletions(-) create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIAccessibilityOfPublishedOldAPIAndPublishedCopyAPITestCase.java delete mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APILifecycleTestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIManagerConfigurationChangeTest.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIManagerLifecycleBaseTest.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIPublishingAndVisibilityInStoreTestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfBlockAPITestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfDeprecatedOldAPIAndPublishedCopyAPITestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfOldAPIAndCopyAPIWithOutReSubscriptionTestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfOldAPIAndCopyAPIWithReSubscriptionTestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfRetireAPITestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPIBackendURLTestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPIEndPointURLTestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPITagsTestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/EditAPIAndCheckUpdatedInformationTestCase.java create mode 100644 modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/EditAPIContextAndCheckAccessibilityTestCase.java diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/APIManagerIntegrationTestException.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/APIManagerIntegrationTestException.java index 6b283ca7fa..e7b1b52fe0 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/APIManagerIntegrationTestException.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/APIManagerIntegrationTestException.java @@ -27,12 +27,23 @@ public class APIManagerIntegrationTestException extends Exception { /** * Constructor for the custom Exception class APIManagerIntegrationTestException. * - * @param message Custom message. - * @param throwable Original Exception. + * @param message - Custom message. + * @param throwable - Original Exception. */ public APIManagerIntegrationTestException(String message, Throwable throwable) { + super(message, throwable); } + /** + * Constructor for the custom Exception class APIManagerIntegrationTestException. + * + * @param message - Custom message. + */ + public APIManagerIntegrationTestException(String message) { + super(message); + } + + } diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIPublisherRestClient.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIPublisherRestClient.java index 36e89dcfd3..2b9e45710e 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIPublisherRestClient.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIPublisherRestClient.java @@ -18,9 +18,11 @@ package org.wso2.am.integration.test.utils.clients; +import org.wso2.am.integration.test.utils.bean.APILifeCycleState; import org.wso2.am.integration.test.utils.bean.APILifeCycleStateRequest; import org.wso2.am.integration.test.utils.bean.APIRequest; import org.wso2.am.integration.test.utils.validation.VerificationUtil; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; @@ -549,4 +551,47 @@ public HttpResponse updateResourceOfAPI(String provider, String apiName, String throw new Exception("API Resource update failed : " + response.getData()); } } + + /** + * Change the API Lifecycle status to Publish with the option of Re-subscription is required or not + * + * @param apiIdentifier - Instance of APIIdentifier + * @param isRequireReSubscription - true if Re-subscription is required else false. + * @return HttpResponse - Response of the API publish event + * @throws Exception - Exception Throws in checkAuthentication() and when do the REST service calls to do the + * lifecycle change + */ + public HttpResponse changeAPILifeCycleStatusToPublish(APIIdentifier apiIdentifier, boolean isRequireReSubscription) + throws Exception { + checkAuthentication(); + APILifeCycleStateRequest publishUpdateRequest = + new APILifeCycleStateRequest(apiIdentifier.getApiName(), apiIdentifier.getProviderName(), APILifeCycleState.PUBLISHED); + publishUpdateRequest.setVersion(apiIdentifier.getVersion()); + String requestParameters = publishUpdateRequest.generateRequestParameters(); + if (isRequireReSubscription) { + requestParameters += "&requireResubscription=true"; + } + + return HttpRequestUtil.doPost(new URL(backEndUrl + "/publisher/site/blocks/life-cycles/ajax/life-cycles.jag") + , requestParameters, requestHeaders); + + } + + /** + * Get the API information for the given API Name,API Version and API Provider + * + * @param apiName - Name of the API + * @param provider - Provider Name of the API + * @param version - Version of the API + * @return HttpResponse - Response of the getAPI request + * @throws Exception - Exception Throws in checkAuthentication() and when do the REST service calls to get the + * API information. + */ + public HttpResponse getApi(String apiName, String provider, String version) + throws Exception { + checkAuthentication(); + return HttpRequestUtil.doPost(new URL(backEndUrl + "/publisher/site/blocks/listing/ajax/item-list.jag") + , "action=getAPI&name=" + apiName + "&version=" + version + "&provider=" + provider + "", requestHeaders); + + } } diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIStoreRestClient.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIStoreRestClient.java index 5d0fedfc17..86a453977f 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIStoreRestClient.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/clients/APIStoreRestClient.java @@ -654,4 +654,42 @@ public HttpResponse getRecentlyAddedAPIs(String tenant, String limit) throws Exc } } + + /** + * Get the web page with filtered API when click the API Tag link + * + * @param apiTag - API tag the need ti filter the api. + * @return HttpResponse - Response that contains the web page with filtered API when click the API Tag link + * @throws Exception - Exception throws when check the Authentication + */ + public HttpResponse getAPIPageFilteredWithTags(String apiTag) + throws Exception { + checkAuthentication(); + HttpResponse response = HttpRequestUtil.sendGetRequest(backEndUrl + "/store/apis/list" + , "tag=" + apiTag + "&tenant=carbon.super"); + return response; + + } + + /** + * Subscribe and API. This method return the response of the subscription server REST call. + * + * @param subscriptionRequest -SubscriptionRequest request instance with API subscription information. + * @return HttpResponse - Response f the subscription server REST call + * @throws Exception- Exception throws when check the Authentication + */ + public HttpResponse subscribeAPI(SubscriptionRequest subscriptionRequest) + throws Exception { + //This method do the same functionality as subscribe(), except this method always returns the response object + //regardless of the response code. But subscribe() returns the response object only if the response code is + // 200 or else it will return an Exception. + checkAuthentication(); + HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag") + , subscriptionRequest.generateRequestParameters() + , requestHeaders); + + return response; + + } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIAccessibilityOfPublishedOldAPIAndPublishedCopyAPITestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIAccessibilityOfPublishedOldAPIAndPublishedCopyAPITestCase.java new file mode 100644 index 0000000000..8d3d694fba --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIAccessibilityOfPublishedOldAPIAndPublishedCopyAPITestCase.java @@ -0,0 +1,179 @@ +/* + * 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.tests.api.lifecycle; + + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.APIMgtTestUtil; +import org.wso2.am.integration.test.utils.bean.APILifeCycleState; +import org.wso2.am.integration.test.utils.bean.APILifeCycleStateRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Change the lifecycle of a copy API to published without deprecating old version.Check whether newest version is + * listed in store. Check whether old version is still listed under more apis from same creator. Whether users can + * still subscribe to old version. Test invocation of both old and new API versions. + */ + +public class APIAccessibilityOfPublishedOldAPIAndPublishedCopyAPITestCase extends APIManagerLifecycleBaseTest { + + + private APIIdentifier apiIdentifierAPI1Version1; + private APIIdentifier apiIdentifierAPI1Version2; + private String applicationName; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + apiIdentifierAPI1Version2 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION2); + applicationName = (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + ; + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + + @Test(groups = {"wso2.am"}, description = " Test Copy API.Copy API version 1.0.0 to 2.0.0 ") + public void testCopyAPI() throws Exception { + + //Create and publish API version 1.0.0 + createAndPublishAPIWithoutRequireReSubscription( + apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1); + + //Copy API version 1.0.0 to 2.0.0 + HttpResponse httpResponseCopyAPI = + apiPublisherClientUser1.copyAPI(API1_PROVIDER_NAME, API1_NAME, API_VERSION1, API_VERSION2, ""); + + assertEquals(httpResponseCopyAPI.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Copy API request code is invalid." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(httpResponseCopyAPI, "error"), "false", + "Copy API response data is invalid" + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + httpResponseCopyAPI.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = " Test Copy API.", dependsOnMethods = "testCopyAPI") + public void testPublishCopiedAPI() throws Exception { + + //Publish version 2.0.0 + APILifeCycleStateRequest publishUpdateRequest = + new APILifeCycleStateRequest(API1_NAME, API1_PROVIDER_NAME, APILifeCycleState.PUBLISHED); + publishUpdateRequest.setVersion(API_VERSION2); + HttpResponse publishAPIResponse = + apiPublisherClientUser1.changeAPILifeCycleStatusToPublish(apiIdentifierAPI1Version2, false); + assertEquals(publishAPIResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "API publish Response code is invalid " + getAPIIdentifierString(apiIdentifierAPI1Version2)); + assertTrue(verifyAPIStatusChange(publishAPIResponse, APILifeCycleState.CREATED, APILifeCycleState.PUBLISHED), + "API status Change is invalid in" + getAPIIdentifierString(apiIdentifierAPI1Version2) + + "Response Data:" + publishAPIResponse.getData()); + + + } + + + @Test(groups = {"wso2.am"}, description = " Test availability of old and new API versions in the store.", + dependsOnMethods = "testPublishCopiedAPI") + public void testAvailabilityOfOldAndNewAPIVersionsInStore() throws Exception { + + // Check availability of old API version in API Store + List apiStoreAPIIdentifierList = + APIMgtTestUtil.getAPIIdentifierListFromHttpResponse(apiStoreClientUser1.getAPI(API1_NAME)); + assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), true, + "Old version Api is not visible in API Store after publish new version." + getAPIIdentifierString( + apiIdentifierAPI1Version1)); + + // Check availability of new API version in API Store + apiStoreAPIIdentifierList = + APIMgtTestUtil.getAPIIdentifierListFromHttpResponse(apiStoreClientUser1.getAPI(API1_NAME)); + assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version2, apiStoreAPIIdentifierList), true, + "New version Api is not visible in API Store after publish new version." + getAPIIdentifierString( + apiIdentifierAPI1Version2)); + } + + + @Test(groups = {"wso2.am"}, description = "Test subscribe of old API version.", + dependsOnMethods = "testAvailabilityOfOldAndNewAPIVersionsInStore") + public void testSubscribeOldVersion() throws Exception { + HttpResponse oldVersionSubscribeResponse = subscribeAPI(apiIdentifierAPI1Version1, applicationName, apiStoreClientUser1); + assertEquals(oldVersionSubscribeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Subscribe of old API version request not successful " + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(oldVersionSubscribeResponse, "error"), "false", + "Error in subscribe of old API version" + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + oldVersionSubscribeResponse.getData()); + } + + + @Test(groups = {"wso2.am"}, description = " Test availability of old and new API versions i the store.", dependsOnMethods = "testSubscribeOldVersion") + public void testSubscribeNewVersion() throws Exception { + + HttpResponse newVersionSubscribeResponse = subscribeAPI(apiIdentifierAPI1Version2, applicationName, apiStoreClientUser1); + assertEquals(newVersionSubscribeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Subscribe of old API version request not successful " + getAPIIdentifierString(apiIdentifierAPI1Version2)); + assertEquals(getValueFromJSON(newVersionSubscribeResponse, "error"), "false", + "Error in subscribe of old API version" + getAPIIdentifierString(apiIdentifierAPI1Version2) + + "Response Data:" + newVersionSubscribeResponse.getData()); + } + + + @Test(groups = {"wso2.am"}, description = "Publish a API and check its visibility in the API Store. Copy and create a new version, " + + "publish the new version, test invocation of both old and new API versions.", dependsOnMethods = "testSubscribeNewVersion") + public void testAccessibilityOfPublishedOldAPIAndPublishedCopyAPI() throws Exception { + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + // Create requestHeaders + Map requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + //Invoke old version + HttpResponse oldVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + + API1_END_POINT_METHOD, requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), "Response data mismatched"); + + //Invoke new version + HttpResponse newVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION2 + + API1_END_POINT_METHOD, requestHeaders); + + assertEquals(newVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched"); + assertTrue(newVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), "Response data mismatched"); + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + deleteAPI(apiIdentifierAPI1Version2, apiPublisherClientUser1); + } + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APILifecycleTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APILifecycleTestCase.java deleted file mode 100644 index c663a8d34e..0000000000 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APILifecycleTestCase.java +++ /dev/null @@ -1,675 +0,0 @@ -/* - * 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.tests.api.lifecycle; - -import org.json.JSONObject; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.wso2.am.integration.test.utils.APIMgtTestUtil; -import org.wso2.am.integration.test.utils.base.AMIntegrationBaseTest; -import org.wso2.am.integration.test.utils.bean.*; -import org.wso2.am.integration.test.utils.publisher.utils.APIPublisherRestClient; -import org.wso2.am.integration.test.utils.store.utils.APIStoreRestClient; -import org.wso2.carbon.apimgt.api.model.APIIdentifier; -import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider; -import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; -import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; -import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager; -import org.wso2.carbon.utils.ServerConstants; - -import java.io.File; -import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -/** - * Test cases for API Manager lifecycle - */ -public class APILifecycleTestCase extends AMIntegrationBaseTest { - - private static final String API1_TAGS = "youtube, video, media"; - private static final String API1_END_POINT_URL = "http://gdata.youtube.com/feeds/api/standardfeeds"; - private static final String API1_DESCRIPTION = "This is test API create by API manager integration test"; - private static final String END_POINT_METHOD = "/most_popular"; - private static final String API1_PROVIDER_NAME = "admin"; - - private static final String API_RESPONSE_DATA = " apiPublisherAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse( - apiPublisherClientUser1.getApi(apiName, API1_PROVIDER_NAME, API_VERSION1)); - assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiPublisherAPIIdentifierList), true, - "Added Api is not available in APi Publisher. API Name:" + apiName + " API Version :" + API_VERSION1 + - " API Provider Name:" + API1_PROVIDER_NAME); - - //Verify the API in API Store : API should not be available in the store. - List apiStoreAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse - (apiStoreClientUser1.getAPI(apiName)); - assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), false, - "Api is visible in API Store before publish." + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - //Publish the API - APILifeCycleStateRequest publishUpdateRequest = new APILifeCycleStateRequest(apiName, API1_PROVIDER_NAME, - APILifeCycleState.PUBLISHED); - publishUpdateRequest.setVersion(API_VERSION1); - HttpResponse httpResponsePublishAPI = apiPublisherClientUser1.changeAPILifeCycleStatusToPublish - (apiIdentifierAPI1Version1, false); - assertEquals(httpResponsePublishAPI.getResponseCode(), HTTP_RESPONSE_CODE_OK, "API publish request not success"); - assertTrue(httpResponsePublishAPI.getData().contains("\"newStatus\" : \"CREATED\", \"oldStatus\"")); - - //Verify the API in API Store : API should not be available in the store. - apiStoreAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse - (apiStoreClientUser1.getAPI(apiName)); - - assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), true, - "Api is not visible in API Store after publish. " + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - } - - @Test(groups = {"wso2.am"}, description = "Publish a API and check its visibility in the API Store. Copy and create a new version, " + - "publish the new version, test invocation of both old and new API versions.", dependsOnMethods = "testAPIPublishingAndVisibilityInStore") - public void testAccessibilityOfPublishedOldAPIAndPublishedCopyAPI() throws Exception { - - - String apiName = "APILifeCycleTestAPI2"; - String apiContext = "testAPI2"; - - APIIdentifier apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION1); - APIIdentifier apiIdentifierAPI1Version2 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION2); - - createAPI(apiName, apiContext, API_VERSION1, apiPublisherClientUser1); - - //Publish the API version 1.0.0 - APILifeCycleStateRequest publishUpdateRequest = new APILifeCycleStateRequest(apiName, API1_PROVIDER_NAME, - APILifeCycleState.PUBLISHED); - publishUpdateRequest.setVersion(API_VERSION1); - apiPublisherClientUser1.changeAPILifeCycleStatusTo(publishUpdateRequest); - - //Copy API version 1.0.0 to 2.0.0 - apiPublisherClientUser1.copyAPI(API1_PROVIDER_NAME, apiName, API_VERSION1, API_VERSION2, ""); - - //Publish version 2.0.0 - publishUpdateRequest = new APILifeCycleStateRequest(apiName, API1_PROVIDER_NAME, - APILifeCycleState.PUBLISHED); - publishUpdateRequest.setVersion(API_VERSION2); - apiPublisherClientUser1.changeAPILifeCycleStatusTo(publishUpdateRequest); - - // Check availability of old API version in API Store - List apiStoreAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse - (apiStoreClientUser1.getAPI(apiName)); - assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), true, - "Old version Api is not visible in API Store after publish new version." + getAPIIdentifierString( - apiIdentifierAPI1Version1)); - - // Check availability of new API version in API Store - apiStoreAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse - (apiStoreClientUser1.getAPI(apiName)); - assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version2, apiStoreAPIIdentifierList), true, - "New version Api is not visible in API Store after publish new version." + getAPIIdentifierString( - apiIdentifierAPI1Version2)); - - //subscribe Old version - assertEquals(SubscribeAPI(apiIdentifierAPI1Version1, apiStoreClientUser1).getData(), - "{\"error\" : false}", "Cannot subscribe to the old API version, " + getAPIIdentifierString( - apiIdentifierAPI1Version1)); - - - //subscribe new version - assertEquals(SubscribeAPI(apiIdentifierAPI1Version2, apiStoreClientUser1).getData(), "{\"error\" : false}", - "Cannot subscribe to the new API version, " + getAPIIdentifierString(apiIdentifierAPI1Version2)); - - //get access token - accessToken = getAccessToken(apiStoreClientUser1); - - // Create requestHeaders - Map requestHeaders = new HashMap(); - requestHeaders.put("Authorization", "Bearer " + accessToken); - //Invoke old version - HttpResponse oldVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION1 + - END_POINT_METHOD, requestHeaders); - Assert.assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched"); - Assert.assertTrue(oldVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), "Response data mismatched"); - - //Invoke new version - HttpResponse newVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION2 + - END_POINT_METHOD, requestHeaders); - - Assert.assertEquals(newVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched"); - Assert.assertTrue(newVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), "Response data mismatched"); - - } - - - @Test(groups = {"wso2.am"}, description = "Publish a API. Copy and create a new version, publish the new version" + - " and deprecate the old version, test invocation of both old and new API versions.", - dependsOnMethods = "testAccessibilityOfPublishedOldAPIAndPublishedCopyAPI") - public void testAccessibilityOfDeprecatedOldAPIAndPublishedCopyAPI() throws Exception { - - - String apiName = "APILifeCycleTestAPI3"; - String apiContext = "testAPI3"; - - APIIdentifier apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION1); - APIIdentifier apiIdentifierAPI1Version2 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION2); - - createAPI(apiName, apiContext, API_VERSION1, apiPublisherClientUser1); - - //Publish the API version 1.0.0 - APILifeCycleStateRequest publishUpdateRequest = new APILifeCycleStateRequest(apiName, API1_PROVIDER_NAME, - APILifeCycleState.PUBLISHED); - publishUpdateRequest.setVersion(API_VERSION1); - apiPublisherClientUser1.changeAPILifeCycleStatusTo(publishUpdateRequest); - - //Copy API version 1.0.0 to 2.0.0 - apiPublisherClientUser1.copyAPI(API1_PROVIDER_NAME, apiName, API_VERSION1, API_VERSION2, ""); - - //Publish version 2.0.0 - publishUpdateRequest = new APILifeCycleStateRequest(apiName, API1_PROVIDER_NAME, - APILifeCycleState.PUBLISHED); - publishUpdateRequest.setVersion(API_VERSION2); - apiPublisherClientUser1.changeAPILifeCycleStatusTo(publishUpdateRequest); - - - //subscribe Old version - assertEquals(SubscribeAPI(apiIdentifierAPI1Version1, apiStoreClientUser1).getData(), "{\"error\" : false}", - "Cannot subscribe to the old API version, " + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - - //subscribe new version - assertEquals(SubscribeAPI(apiIdentifierAPI1Version2, apiStoreClientUser1).getData(), "{\"error\" : false}", - "Cannot subscribe to the new API version, " + getAPIIdentifierString(apiIdentifierAPI1Version2)); - - - APILifeCycleStateRequest deprecatedUpdateRequest = new APILifeCycleStateRequest(apiName, API1_PROVIDER_NAME, - APILifeCycleState.DEPRECATED); - deprecatedUpdateRequest.setVersion(API_VERSION1); - apiPublisherClientUser1.changeAPILifeCycleStatusTo(deprecatedUpdateRequest); - //subscribe Old version - String subscribeErrorMessage = ""; - try { - SubscribeAPI(apiIdentifierAPI1Version1, apiStoreClientUser2).getData(); - } catch (Exception ex) { - subscribeErrorMessage = ex.getMessage(); - } finally { - assertTrue(subscribeErrorMessage.contains("Error while adding the subscription"), - "Users can subscribe to Deprecated API" + getAPIIdentifierString(apiIdentifierAPI1Version1)); - } - - - // Check availability of old API version in API Store - List apiStoreAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse - (apiStoreClientUser1.getAPI(apiName)); - assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), true, - "Old version Api is not visible in API Store after publish new version." + getAPIIdentifierString - (apiIdentifierAPI1Version1)); - - - // Check availability of new API version in API Store - apiStoreAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse - (apiStoreClientUser1.getAPI(apiName)); - assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version2, apiStoreAPIIdentifierList), true, - "New version Api is not visible in API Store after publish new version. " + getAPIIdentifierString - (apiIdentifierAPI1Version2)); - - // Create requestHeaders - Map requestHeaders = new HashMap(); - requestHeaders.put("Authorization", "Bearer " + accessToken); - - //Invoke old version - HttpResponse oldVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION1 - + END_POINT_METHOD, requestHeaders); - Assert.assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, - "Response code mismatched"); - Assert.assertTrue(oldVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), "Response data mismatched"); - - //Invoke new version - HttpResponse newVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION2 + - END_POINT_METHOD, requestHeaders); - Assert.assertEquals(newVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, - "Response code mismatched"); - Assert.assertTrue(newVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), "Response data mismatched"); - - } - - - @Test(groups = {"wso2.am"}, description = "Publish a API. Copy and create a new version, publish the new " + - " API version with re-subscription required and test invocation of New API before and after the " + - "re-subscription.", - dependsOnMethods = "testAccessibilityOfDeprecatedOldAPIAndPublishedCopyAPI", enabled = false) - public void testAccessibilityOfOldAPIAndCopyAPIWithReSubscription() throws Exception { - - - String apiName = "APILifeCycleTestAPI4"; - String apiContext = "testAPI4"; - - APIIdentifier apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION1); - APIIdentifier apiIdentifierAPI1Version2 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION2); - - //create API - createAPI(apiName, apiContext, API_VERSION1, apiPublisherClientUser1); - - //Publish the API version 1.0.0 - HttpResponse httpResponsePublishAPIOldVersion = apiPublisherClientUser1. - changeAPILifeCycleStatusToPublish(apiIdentifierAPI1Version1, false); - assertTrue(httpResponsePublishAPIOldVersion.getData().contains("\"newStatus\" : \"PUBLISHED\""), - "API is not publish correctly." + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - //subscribe Old version - HttpResponse httpResponseSubscribeOldVersion = SubscribeAPI(apiIdentifierAPI1Version1, apiStoreClientUser1); - assertEquals(httpResponseSubscribeOldVersion.getData(), "{\"error\" : false}", "Cannot subscribe to the " + - "old API version, " + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - // Create requestHeaders - Map requestHeaders = new HashMap(); - requestHeaders.put("Authorization", "Bearer " + accessToken); - // Invoke old version - HttpResponse oldVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION1 - + END_POINT_METHOD, requestHeaders); - - Assert.assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, - "Response code mismatched"); - Assert.assertTrue(oldVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), "Response data mismatched"); - - //Copy API version 1.0.0 to 2.0.0 - apiPublisherClientUser1.copyAPI(API1_PROVIDER_NAME, apiName, API_VERSION1, API_VERSION2, ""); - - //Publish version 2.0.0 with Re-Subscription required - HttpResponse httpResponsePublishAPIVersion2 = apiPublisherClientUser1.changeAPILifeCycleStatusToPublish( - apiIdentifierAPI1Version2, - true); - assertTrue(httpResponsePublishAPIVersion2.getData().contains("\"newStatus\" : \"PUBLISHED\""), - "API is not publish correctly." + getAPIIdentifierString(apiIdentifierAPI1Version2)); - - //Invoke new version before subscribe - HttpResponse newVersionInvokeResponseBeforeSubscribe = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + - API_VERSION2 + END_POINT_METHOD, requestHeaders); - Assert.assertEquals(newVersionInvokeResponseBeforeSubscribe.getResponseCode(), HTTP_RESPONSE_CODE_UNAUTHORIZED, - "Invoke was success before subscribe the new version of api when Re-Subscription required. " + - "Incorrect Response code"); - Assert.assertTrue(newVersionInvokeResponseBeforeSubscribe.getData().contains( - "900901Invalid Credentials"), - "Invoke was success before subscribe the new version of api when Re-Subscription required. " + - "Incorrect data in the response."); - - - //subscribe new version - HttpResponse httpResponseSubscribeNewVersion = SubscribeAPI(apiIdentifierAPI1Version2, apiStoreClientUser1); - assertEquals(httpResponseSubscribeNewVersion.getData(), "{\"error\" : false}", - "Cannot subscribe to the new API version, API Name:" + apiName + " API Version:" + API_VERSION2); - - //Invoke new version after subscribe - HttpResponse newVersionInvokeResponse1 = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION2 - + END_POINT_METHOD, requestHeaders); - Assert.assertEquals(newVersionInvokeResponse1.getResponseCode(), HTTP_RESPONSE_CODE_OK, - "Invoke was not successful after subscribe the API. Incorrect Response code\""); - Assert.assertTrue(newVersionInvokeResponse1.getData().contains(API_RESPONSE_DATA), - "Invoke was not successful after subscribe the API.Incorrect data in the response."); - - - } - - @Test(groups = {"wso2.am"}, description = "Publish a API. Copy and create a new version, publish the new API " + - "version with out re-subscription required and test invocation of New API without re-subscription." - , dependsOnMethods = "testAccessibilityOfDeprecatedOldAPIAndPublishedCopyAPI") - public void testAccessibilityOfOldAPIAndCopyAPIWithOutReSubscription() throws Exception { - - - String apiName = "APILifeCycleTestAPI5"; - String apiContext = "testAPI5"; - - APIIdentifier apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION1); - APIIdentifier apiIdentifierAPI1Version2 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION2); - - //create API - createAPI(apiName, apiContext, API_VERSION1, apiPublisherClientUser1); - - //Publish the API version 1.0.0 - HttpResponse httpResponsePublishAPIOldVersion = apiPublisherClientUser1.changeAPILifeCycleStatusToPublish( - apiIdentifierAPI1Version1, false); - assertTrue(httpResponsePublishAPIOldVersion.getData().contains("\"newStatus\" : \"PUBLISHED\""), - "API is not publish correctly." + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - //subscribe Old version - HttpResponse httpResponseSubscribeOldVersion = SubscribeAPI(apiIdentifierAPI1Version1, apiStoreClientUser1); - assertEquals(httpResponseSubscribeOldVersion.getData(), "{\"error\" : false}", - "Cannot subscribe to the old API version, " + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - // Create requestHeaders - Map requestHeaders = new HashMap(); - requestHeaders.put("Authorization", "Bearer " + accessToken); - - // Invoke old version - HttpResponse oldVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION1 + - END_POINT_METHOD, requestHeaders); - - Assert.assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, - "Response code mismatched"); - Assert.assertTrue(oldVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), - "Response data mismatched"); - - //Copy API version 1.0.0 to 2.0.0 - apiPublisherClientUser1.copyAPI(API1_PROVIDER_NAME, apiName, API_VERSION1, API_VERSION2, ""); - - //Publish version 2.0.0 with Re-Subscription not required - HttpResponse httpResponsePublishAPIVersion2 = apiPublisherClientUser1.changeAPILifeCycleStatusToPublish( - apiIdentifierAPI1Version2, false); - assertTrue(httpResponsePublishAPIVersion2.getData().contains("\"newStatus\" : \"PUBLISHED\""), - "API is not publish correctly." + getAPIIdentifierString(apiIdentifierAPI1Version2)); - - //Invoke new version before subscribe - HttpResponse newVersionInvokeResponseBeforeSubscribe = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + - API_VERSION2 + END_POINT_METHOD, requestHeaders); - Assert.assertEquals(newVersionInvokeResponseBeforeSubscribe.getResponseCode(), HTTP_RESPONSE_CODE_OK, - "Invoke was not success before subscribe the new version of api when Re-Subscription not required." + - " Incorrect Response code"); - Assert.assertTrue(newVersionInvokeResponseBeforeSubscribe.getData().contains(API_RESPONSE_DATA), - "Invoke was not success before subscribe the new version of api when Re-Subscription not required." + - " Incorrect data in the response."); - } - - - @Test(groups = {"wso2.am"}, description = "Block an API and check its accessibility in the API Store.", - dependsOnMethods = "testAccessibilityOfOldAPIAndCopyAPIWithOutReSubscription") - public void testAccessibilityOfBlockAPI() throws Exception { - - - String apiName = "APILifeCycleTestAPI6"; - String apiContext = "testAPI6"; - - APIIdentifier apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION1); - - //create API - createAPI(apiName, apiContext, API_VERSION1, apiPublisherClientUser1); - - //Publish the API version 1.0.0 - HttpResponse httpResponsePublishAPIOldVersion = apiPublisherClientUser1.changeAPILifeCycleStatusToPublish( - apiIdentifierAPI1Version1, false); - assertTrue(httpResponsePublishAPIOldVersion.getData().contains("\"newStatus\" : \"PUBLISHED\""), - "API is not publish correctly." + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - //subscribe Old version - HttpResponse httpResponseSubscribeOldVersion = SubscribeAPI(apiIdentifierAPI1Version1, apiStoreClientUser1); - assertEquals(httpResponseSubscribeOldVersion.getData(), "{\"error\" : false}", - "Cannot subscribe to the old API version, " + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - - // Create requestHeaders - Map requestHeaders = new HashMap(); - requestHeaders.put("Authorization", "Bearer " + accessToken); - - // Invoke old version - HttpResponse oldVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + - API_VERSION1 + END_POINT_METHOD, requestHeaders); - - Assert.assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, - "Response code mismatched"); - Assert.assertTrue(oldVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), - "Response data mismatched"); - - //Block the API version 1.0.0 - APILifeCycleStateRequest blockUpdateRequest = new APILifeCycleStateRequest(apiName, API1_PROVIDER_NAME, - APILifeCycleState.BLOCKED); - blockUpdateRequest.setVersion(API_VERSION1); - //Change API lifecycle to Block - HttpResponse blockAPIActionResponse = apiPublisherClientUser1.changeAPILifeCycleStatusTo(blockUpdateRequest); - Assert.assertEquals(blockAPIActionResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched"); - Assert.assertTrue(blockAPIActionResponse.getData().contains( - "\"newStatus\" : \"BLOCKED\", \"oldStatus\" : \"PUBLISHED\""), "Response data "); - - //Access API after Block - HttpResponse blockAPIInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + - "/" + API_VERSION1 + END_POINT_METHOD, requestHeaders); - Assert.assertEquals(blockAPIInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE, - "Response code mismatched"); - Assert.assertTrue(blockAPIInvokeResponse.getData().contains( - "700700API blocked"), "Response data mismatched"); - - } - - - @Test(groups = {"wso2.am"}, description = "Retire an API and check its visibility and accessibility in the API Store.", - dependsOnMethods = "testAccessibilityOfBlockAPI") - public void testAccessibilityOfRetireAPI() throws Exception { - - - String apiName = "APILifeCycleTestAPI7"; - String apiContext = "testAPI7"; - - APIIdentifier apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION1); - - - //create API - createAPI(apiName, apiContext, API_VERSION1, apiPublisherClientUser1); - - //Publish the API version 1.0.0 - HttpResponse httpResponsePublishAPIOldVersion = apiPublisherClientUser1.changeAPILifeCycleStatusToPublish( - apiIdentifierAPI1Version1, false); - assertTrue(httpResponsePublishAPIOldVersion.getData().contains("\"newStatus\" : \"PUBLISHED\""), - "API is not publish correctly." + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - //subscribe Old version - HttpResponse httpResponseSubscribeOldVersion = SubscribeAPI(apiIdentifierAPI1Version1, apiStoreClientUser1); - assertEquals(httpResponseSubscribeOldVersion.getData(), "{\"error\" : false}", - "Cannot subscribe to the old API version, " + getAPIIdentifierString(apiIdentifierAPI1Version1)); - - - // Create requestHeaders - Map requestHeaders = new HashMap(); - requestHeaders.put("Authorization", "Bearer " + accessToken); - - // Invoke old version - HttpResponse oldVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION1 + - END_POINT_METHOD, requestHeaders); - - Assert.assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, - "Response code mismatched"); - Assert.assertTrue(oldVersionInvokeResponse.getData().contains(API_RESPONSE_DATA), - "Response data mismatched"); - - //Block the API version 1.0.0 - APILifeCycleStateRequest retireUpdateRequest = new APILifeCycleStateRequest(apiName, API1_PROVIDER_NAME, - APILifeCycleState.RETIRED); - retireUpdateRequest.setVersion(API_VERSION1); - HttpResponse retireAPIActionResponse = apiPublisherClientUser1.changeAPILifeCycleStatusTo(retireUpdateRequest); - Assert.assertEquals(retireAPIActionResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched"); - - //Verify the API in API Store : API should not be available in the store. - List apiStoreAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse( - apiStoreClientUser1.getAPI(apiName)); - assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), false, - "Api is not visible in API Store after publish. API Name:" + apiName + " API Version :" + API_VERSION1 + - " API Provider Name:" + API1_PROVIDER_NAME); - - // Invoke the API - HttpResponse retireAPIInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + apiContext + "/" + API_VERSION1 + - END_POINT_METHOD, requestHeaders); - Assert.assertEquals(retireAPIInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_NOT_FOUND, - "Response code mismatched"); - Assert.assertTrue(retireAPIInvokeResponse.getData().contains - ("404Status reportNot Found"), - "Response data mismatched"); - } - - - @AfterClass(alwaysRun = true) - /** - * Restore the backup api-manager.xml file. - */ - public void cleanup() throws Exception { - serverManager.restoreToLastConfiguration(); - } - - - - /** - * Create a API in API Publisher - * - * @param apiName Name of the API - * @param apiContext API Context - * @param apiVersion API Version - * @param publisherRestClient Instance of APIPublisherRestClient - * @return Response of the API creation server call. - * @throws Exception - */ - private HttpResponse createAPI(String apiName, String apiContext, String apiVersion, APIPublisherRestClient - publisherRestClient) throws Exception { - - //Create the API Request - APIRequest apiRequestBean = new APIRequest(apiName, apiContext, new URL(API1_END_POINT_URL)); - apiRequestBean.setTags(API1_TAGS); - apiRequestBean.setDescription(API1_DESCRIPTION); - apiRequestBean.setVersion(apiVersion); - apiRequestBean.setVisibility("public"); - - //Add the API to API Publisher - return publisherRestClient.addAPI(apiRequestBean); - - } - - - /** - * Return a String with combining the value of API Name,API Version and API Provider Name as key:value format - * - * @param apiIdentifier Instance of APIIdentifier object that include the API Name,API Version and API Provider - * Name to create the String - * @return String with API Name,API Version and API Provider Name as key:value format - */ - private String getAPIIdentifierString(APIIdentifier apiIdentifier) { - return "API Name:" + apiIdentifier.getApiName() + " API Version:" + apiIdentifier.getVersion() + - " API Provider Name :" + apiIdentifier.getProviderName(); - - } - - /** - * Subscribe a API - * - * @param apiIdentifier Instance of APIIdentifier object that include the API Name,API Version and API Provider - * @param storeRestClient Instance of APIPublisherRestClient - * @return Response of the API subscribe action - * @throws Exception - */ - private HttpResponse SubscribeAPI(APIIdentifier apiIdentifier, APIStoreRestClient storeRestClient) throws Exception { - SubscriptionRequest oldVersionSubscriptionRequest = new SubscriptionRequest(apiIdentifier.getApiName(), - apiIdentifier.getProviderName()); - oldVersionSubscriptionRequest.setVersion(apiIdentifier.getVersion()); - return storeRestClient.subscribe(oldVersionSubscriptionRequest); - - } - - /** - * Generate the access token - * - * @param storeRestClient Instance of storeRestClient - * @return Access Token as a String. - * @throws Exception - */ - private String getAccessToken(APIStoreRestClient storeRestClient) throws Exception { - - GenerateAppKeyRequest generateAppKeyRequest = new GenerateAppKeyRequest("DefaultApplication"); - String responseString = storeRestClient.generateApplicationKey(generateAppKeyRequest).getData(); - JSONObject response = new JSONObject(responseString); - return response.getJSONObject("data").getJSONObject("key").get("accessToken").toString(); - - } - -} \ No newline at end of file diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIManagerConfigurationChangeTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIManagerConfigurationChangeTest.java new file mode 100644 index 0000000000..829561df80 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIManagerConfigurationChangeTest.java @@ -0,0 +1,76 @@ +/* + * 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.tests.api.lifecycle; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.wso2.carbon.automation.engine.annotations.ExecutionEnvironment; +import org.wso2.carbon.automation.engine.annotations.SetEnvironment; +import org.wso2.carbon.automation.test.utils.common.TestConfigurationProvider; +import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager; +import org.wso2.carbon.utils.ServerConstants; + +import java.io.File; + +/** + * Change the api-manager.xml file before start the test suit and restore it after all test executions are finished. + */ +public class APIManagerConfigurationChangeTest extends APIManagerLifecycleBaseTest { + + private static final Log log = LogFactory.getLog(APIManagerConfigurationChangeTest.class); + private ServerConfigurationManager serverManager; + private static final String APIM_CONFIG_XML = "api-manager.xml"; + + @SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE}) + @BeforeTest(alwaysRun = true) + public void startChangeAPIMConfigureXml() throws Exception { + super.init(); + String carbonHome = System.getProperty(ServerConstants.CARBON_HOME); + String artifactsLocation = TestConfigurationProvider.getResourceLocation() + + File.separator + + "artifacts" + File.separator + "AM" + File.separator + "configFiles" + File.separator + "lifecycletest" + + File.separator; + String apimConfigArtifactLocation = artifactsLocation + APIM_CONFIG_XML; + String apimRepositoryConfigLocation = carbonHome + File.separator + "repository" + + File.separator + "conf" + File.separator + APIM_CONFIG_XML; + + File sourceFile = new File(apimConfigArtifactLocation); + File targetFile = new File(apimRepositoryConfigLocation); + serverManager = new ServerConfigurationManager(apimContext); + + // apply configuration to api-manager.xml + serverManager.applyConfigurationWithoutRestart(sourceFile, targetFile, true); + log.info("api-manager.xml configuration file copy from :" + apimConfigArtifactLocation + + " to :" + apimRepositoryConfigLocation); + + serverManager.restartGracefully(); + + } + + @AfterTest(alwaysRun = true) + public void startRestoreAPIMConfigureXml() throws Exception { + serverManager.restoreToLastConfiguration(); + log.info("Restore the api-manager.xml configuration file"); + + } + + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIManagerLifecycleBaseTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIManagerLifecycleBaseTest.java new file mode 100644 index 0000000000..753b9e40b0 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIManagerLifecycleBaseTest.java @@ -0,0 +1,538 @@ +/* + * 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.tests.api.lifecycle; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.testng.annotations.BeforeClass; +import org.wso2.am.integration.test.utils.APIManagerIntegrationTestException; +import org.wso2.am.integration.test.utils.base.AMIntegrationBaseTest; +import org.wso2.am.integration.test.utils.bean.*; +import org.wso2.am.integration.test.utils.clients.APIPublisherRestClient; +import org.wso2.am.integration.test.utils.clients.APIStoreRestClient; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import javax.ws.rs.core.Response; +import java.net.URL; + +/** + * Base test class for all API Manager lifecycle test cases. This class contents the all the + * common variables and t methods. + */ +public class APIManagerLifecycleBaseTest extends AMIntegrationBaseTest { + + + protected static final String API1_NAME = "APILifeCycleTestAPI1"; + protected static final String API1_CONTEXT = "testAPI1"; + protected static final String API1_TAGS = "youtube, video, media"; + protected static final String API1_END_POINT_URL = "http://gdata.youtube.com/feeds/api/standardfeeds"; + protected static final String API1_DESCRIPTION = "This is test API create by API manager integration test"; + protected static final String API1_END_POINT_METHOD = "/most_popular"; + protected static final String API2_END_POINT_URL = "http://public.opencpu.org/ocpu/library"; + protected static final String API2_END_POINT_METHOD = "/"; + protected static final String API1_RESPONSE_DATA = "700700API blocked"; + protected static final String HTTP_RESPONSE_DATA_INVALID_CREDENTIALS = "Invalid Credentials"; + protected static final String HTTP_RESPONSE_DATA_NOT_FOUND = + "404Status reportNot Found"; + protected static String API1_PROVIDER_NAME = "admin"; + + protected APIPublisherRestClient apiPublisherClientUser1; + protected APIStoreRestClient apiStoreClientUser1; + protected APIPublisherRestClient apiPublisherClientUser2; + protected APIStoreRestClient apiStoreClientUser2; + protected static String API_BASE_URL; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + API1_PROVIDER_NAME = apimContext.getContextTenant().getContextUser().getUserName(); + String publisherURLHttp = getPublisherServerURLHttp(); + String storeURLHttp = getStoreServerURLHttp(); + apiPublisherClientUser1 = new APIPublisherRestClient(publisherURLHttp); + apiStoreClientUser1 = new APIStoreRestClient(storeURLHttp); + apiPublisherClientUser2 = new APIPublisherRestClient(publisherURLHttp); + apiStoreClientUser2 = new APIStoreRestClient(storeURLHttp); + + //Login to API Publisher with User1 + apiPublisherClientUser1.login(apimContext.getContextTenant().getContextUser().getUserName(), + apimContext.getContextTenant().getContextUser().getPassword()); + //Login to API Store with User1 + apiStoreClientUser1.login(apimContext.getContextTenant().getContextUser().getUserName(), + apimContext.getContextTenant().getContextUser().getPassword()); + + API_BASE_URL = getGatewayServerURLHttp()+"/"; + //Login to API Publisher with User1 + String userNameUser1 = apimContext.getContextTenant().getTenantUser(USER_KEY_USER2).getUserName(); + String passwordUser1 = apimContext.getContextTenant().getTenantUser(USER_KEY_USER2).getPassword(); + + apiPublisherClientUser2.login(userNameUser1, passwordUser1); + //Login to API Store with User1 + apiStoreClientUser2.login(userNameUser1, passwordUser1); + + } + + + /** + * Create a API in API Publisher + * + * @param apiName - Name of the API + * @param apiContext - API Context + * @param apiVersion - API Version + * @param publisherRestClient - Instance of APIPublisherRestClient + * @return HttpResponse - Response of the API creation server call. + * @throws Exception - Exception throws by the method call of addAPI() in APIPublisherRestClient.java + */ + protected HttpResponse createAPI(String apiName, String apiContext, String apiVersion, APIPublisherRestClient + publisherRestClient) throws Exception { + + //Create the API Request + APIRequest apiRequestBean = new APIRequest(apiName, apiContext, new URL(API1_END_POINT_URL)); + apiRequestBean.setTags(API1_TAGS); + apiRequestBean.setDescription(API1_DESCRIPTION); + apiRequestBean.setVersion(apiVersion); + apiRequestBean.setVisibility("public"); + + //Add the API to API Publisher + return publisherRestClient.addAPI(apiRequestBean); + + } + + /** + * Create a API in API Publisher + * + * @param apiName - Name of the API + * @param apiContext - API Context + * @param apiVersion - API Version + * @param apiTags - API Tags + * @param publisherRestClient - Instance of APIPublisherRestClient + * @return HttpResponse - Response of the API creation server call. + * @throws Exception - Exception throws by the method call of addAPI() in APIPublisherRestClient.java + */ + protected HttpResponse createAPI(String apiName, String apiContext, String apiVersion, String apiTags, + APIPublisherRestClient publisherRestClient) throws Exception { + + //Create the API Request + APIRequest apiRequestBean = new APIRequest(apiName, apiContext, new URL(API1_END_POINT_URL)); + apiRequestBean.setTags(apiTags); + apiRequestBean.setDescription(API1_DESCRIPTION); + apiRequestBean.setVersion(apiVersion); + apiRequestBean.setVisibility("public"); + + //Add the API to API Publisher + return publisherRestClient.addAPI(apiRequestBean); + + } + + + /** + * Return a String with combining the value of API Name,API Version and API Provider Name as key:value format + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name,API Version and API Provider + * Name to create the String + * @return String - with API Name,API Version and API Provider Name as key:value format + */ + protected String getAPIIdentifierString(APIIdentifier apiIdentifier) { + return " API Name:" + apiIdentifier.getApiName() + " API Version:" + apiIdentifier.getVersion() + + " API Provider Name :" + apiIdentifier.getProviderName() + " "; + + } + + /** + * Subscribe a API + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name,API Version and API Provider + * @param storeRestClient - Instance of APIPublisherRestClient + * @return HttpResponse - Response of the API subscribe action + * @throws Exception - Exception throws by the method call of subscribe() in APIStoreRestClient.java + */ + protected HttpResponse subscribeAPI(APIIdentifier apiIdentifier, String applicationName, + APIStoreRestClient storeRestClient) throws Exception { + SubscriptionRequest subscriptionRequest = + new SubscriptionRequest(apiIdentifier.getApiName(), apiIdentifier.getProviderName()); + subscriptionRequest.setVersion(apiIdentifier.getVersion()); + subscriptionRequest.setApplicationName(applicationName); + return storeRestClient.subscribeAPI(subscriptionRequest); + + } + + /** + * Generate the access token + * + * @param storeRestClient - Instance of storeRestClient + * @return String - Access Token as a String. + * @throws Exception - Exception throws by the method call of generateApplicationKey() in APIStoreRestClient.java + */ + protected String getAccessToken(APIStoreRestClient storeRestClient) throws Exception { + + GenerateAppKeyRequest generateAppKeyRequest = new GenerateAppKeyRequest("DefaultApplication"); + String responseString = storeRestClient.generateApplicationKey(generateAppKeyRequest).getData(); + JSONObject response = new JSONObject(responseString); + return response.getJSONObject("data").getJSONObject("key").get("accessToken").toString(); + + } + + /** + * Generate the access token + * + * @param storeRestClient - Instance of storeRestClient + * @param applicationName - Application name + * @return String - Access Token as a String. + * @throws Exception - Exception throws by the method call of generateApplicationKey() in APIStoreRestClient.java + */ + protected String getAccessToken(APIStoreRestClient storeRestClient, String applicationName) throws Exception { + + GenerateAppKeyRequest generateAppKeyRequest = new GenerateAppKeyRequest(applicationName); + String responseString = storeRestClient.generateApplicationKey(generateAppKeyRequest).getData(); + JSONObject response = new JSONObject(responseString); + return response.getJSONObject("data").getJSONObject("key").get("accessToken").toString(); + + } + + /** + * Delete a API from API Publisher. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider. + * @param publisherRestClient - Instance of APIPublisherRestClient. + * @throws Exception - Exception throws by the method call of deleteApi() in APIPublisherRestClient.java. + */ + protected void deleteAPI(APIIdentifier apiIdentifier, APIPublisherRestClient publisherRestClient) throws Exception { + + HttpResponse deleteHTTPResponse = + publisherRestClient.deleteAPI(apiIdentifier.getApiName(), apiIdentifier.getVersion(), + apiIdentifier.getProviderName()); + + if (!(deleteHTTPResponse.getResponseCode() == HTTP_RESPONSE_CODE_OK && + getValueFromJSON(deleteHTTPResponse, "error").equals("false"))) { + + throw new APIManagerIntegrationTestException("Error in API Deletion." + + getAPIIdentifierString(apiIdentifier) + " API Context :" + deleteHTTPResponse + + "Response Code:" + deleteHTTPResponse.getResponseCode() + + " Response Data :" + deleteHTTPResponse.getData()); + + } + } + + /** + * Retrieve the value from JSON object bu using the key. + * + * @param httpResponse - Response that containing the JSON object in it response data. + * @param key - key of the JSON value the need to retrive. + * @return String - The value of provided key as a String + * @throws org.wso2.am.integration.test.utils.APIManagerIntegrationTestException - Exception throws when resolving the JSON object in the HTTP response + */ + protected String getValueFromJSON(HttpResponse httpResponse, String key) throws APIManagerIntegrationTestException { + + try { + JSONObject jsonObject = new JSONObject(httpResponse.getData()); + return jsonObject.get(key).toString(); + } catch (JSONException e) { + throw new APIManagerIntegrationTestException( + "Exception thrown when resolving the JSON object in the HTTP response ", e); + } + + } + + /** + * verify the API status change. this method will check the latest lifecycle status change + * is correct according to the given old status and new status. + * + * @param httpResponse - Response returned in the the API lifecycle status change action + * @param oldStatus - Status of the API before the change + * @param newStatus - Status of the API after the change + * @return boolean - true if the given status change is correct, if not false + * @throws org.wso2.am.integration.test.utils.APIManagerIntegrationTestException - Exception throws when resolving the JSON object in the HTTP response + */ + public boolean verifyAPIStatusChange(HttpResponse httpResponse, APILifeCycleState oldStatus, + APILifeCycleState newStatus) throws APIManagerIntegrationTestException { + + boolean isStatusChangeCorrect = false; + + try { + JSONObject jsonRootObject = new JSONObject(httpResponse.getData()); + + JSONArray jsonArray = (JSONArray) jsonRootObject.get("lcs"); + JSONObject latestChange = (JSONObject) jsonArray.get(0); + // Retrieve the latest API life cycle status change information if there are more than one + // lifecycle status change activities available in the api + if (jsonArray.length() > 0) { + + for (int index = 1; index < jsonArray.length(); index++) { + if (Long.parseLong(((JSONObject) jsonArray.get(index)).get("date").toString()) > + Long.parseLong(latestChange.get("date").toString())) { + latestChange = (JSONObject) jsonArray.get(index); + } + + } + } + + // Check the given status change information is correct in latest lifecycle status change action. + if (latestChange.get("oldStatus").toString().equals(oldStatus.getState()) && + latestChange.get("newStatus").toString().equals(newStatus.getState())) { + isStatusChangeCorrect = true; + } + + return isStatusChangeCorrect; + + } catch (JSONException e) { + throw new APIManagerIntegrationTestException( + "Exception thrown when resolving the JSON object in the HTTP response ", e); + } + + } + + /** + * Publish a API. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name,v + * API Version and API Provider + * @param publisherRestClient - Instance of APIPublisherRestClient + * @param isRequireReSubscription - If publish with re-subscription required option true else false. + * @return HttpResponse - Response of the API Publishing activity + * @throws Exception - Exception throws by the method call of changeAPILifeCycleStatusToPublish() in + * APIPublisherRestClient.java. + */ + private HttpResponse publishAPI(APIIdentifier apiIdentifier, APIPublisherRestClient publisherRestClient, + boolean isRequireReSubscription) throws Exception { + APILifeCycleStateRequest publishUpdateRequest = + new APILifeCycleStateRequest(apiIdentifier.getApiName(), apiIdentifier.getProviderName(), + APILifeCycleState.PUBLISHED); + publishUpdateRequest.setVersion(apiIdentifier.getVersion()); + return publisherRestClient.changeAPILifeCycleStatusToPublish(apiIdentifier, isRequireReSubscription); + + } + + /** + * Create and publish a API. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider + * @param apiContext - Context of the API + * @param publisherRestClient - Instance of APIPublisherRestClient + * @param isRequireReSubscription - If publish with re-subscription required option true else false. + * @throws Exception - Exception throws by API create and publish activities. + */ + private void createAndPublishAPI(APIIdentifier apiIdentifier, String apiContext, + APIPublisherRestClient publisherRestClient, + boolean isRequireReSubscription) throws Exception { + //Create the API + HttpResponse createAPIResponse = + createAPI(apiIdentifier.getApiName(), apiContext, apiIdentifier.getVersion(), publisherRestClient); + if (createAPIResponse.getResponseCode() == HTTP_RESPONSE_CODE_OK && + getValueFromJSON(createAPIResponse, "error").equals("false")) { + //Publish the API + HttpResponse publishAPIResponse = publishAPI(apiIdentifier, publisherRestClient, isRequireReSubscription); + if (!(publishAPIResponse.getResponseCode() == HTTP_RESPONSE_CODE_OK && + verifyAPIStatusChange(publishAPIResponse, APILifeCycleState.CREATED, + APILifeCycleState.PUBLISHED))) { + throw new APIManagerIntegrationTestException("Error in API Publishing" + + getAPIIdentifierString(apiIdentifier) + " API Context :" + apiContext + + "Response Code:" + publishAPIResponse.getResponseCode() + + " Response Data :" + publishAPIResponse.getData()); + } + + } else { + throw new APIManagerIntegrationTestException("Error in API Creation." + + getAPIIdentifierString(apiIdentifier) + " API Context :" + apiContext + + "Response Code:" + createAPIResponse.getResponseCode() + + " Response Data :" + createAPIResponse.getData()); + } + + + } + + /** + * Create and publish a API with re-subscription required. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider + * @param apiContext - Context of the API + * @param publisherRestClient - Instance of APIPublisherRestClient + * @throws Exception - Exception throws by API create and publish activities. + */ + protected void createAndPublishAPIWithRequireReSubscription(APIIdentifier apiIdentifier, String apiContext, + APIPublisherRestClient publisherRestClient) + throws Exception { + createAndPublishAPI(apiIdentifier, apiContext, publisherRestClient, true); + } + + /** + * Create and publish a API with re-subscription not required. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider + * @param apiContext - Context of the API + * @param publisherRestClient - Instance of APIPublisherRestClient + * @throws Exception - Exception throws by API create and publish activities. + */ + protected void createAndPublishAPIWithoutRequireReSubscription(APIIdentifier apiIdentifier, String apiContext, + APIPublisherRestClient publisherRestClient) + throws Exception { + createAndPublishAPI(apiIdentifier, apiContext, publisherRestClient, false); + } + + + /** + * Create and publish a API. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider + * @param apiContext - Context of the API + * @param apiTags - Tags that need to include in the API + * @param publisherRestClient - Instance of APIPublisherRestClient + * @param isRequireReSubscription - If publish with re-subscription required option true else false. + * @throws Exception - Exception throws by API create and publish activities. + */ + private void createAndPublishAPI(APIIdentifier apiIdentifier, String apiContext, String apiTags, APIPublisherRestClient publisherRestClient, boolean isRequireReSubscription) throws Exception { + + HttpResponse createAPIResponse = + createAPI(apiIdentifier.getApiName(), apiContext, apiIdentifier.getVersion(), apiTags, publisherRestClient); + + //Create the API + if (createAPIResponse.getResponseCode() == HTTP_RESPONSE_CODE_OK && + getValueFromJSON(createAPIResponse, "error").equals("false")) { + //Publish the API + HttpResponse publishAPIResponse = publishAPI(apiIdentifier, publisherRestClient, isRequireReSubscription); + if (!(publishAPIResponse.getResponseCode() == HTTP_RESPONSE_CODE_OK && + verifyAPIStatusChange(publishAPIResponse, APILifeCycleState.CREATED, APILifeCycleState.PUBLISHED))) { + throw new APIManagerIntegrationTestException("Error in API Publishing" + + getAPIIdentifierString(apiIdentifier) + " API Context :" + apiContext + + "Response Code:" + publishAPIResponse.getResponseCode() + + " Response Data :" + publishAPIResponse.getData()); + } + + } else { + throw new APIManagerIntegrationTestException("Error in API Creation." + + getAPIIdentifierString(apiIdentifier) + " API Context :" + apiContext + + "Response Code:" + createAPIResponse.getResponseCode() + + " Response Data :" + createAPIResponse.getData()); + } + + + } + + /** + * Create and publish a API with re-subscription not required. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider + * @param apiContext - Context of the API + * @param apiTags - Tags that need to include in the API + * @param publisherRestClient - Instance of APIPublisherRestClient + * @throws Exception - Exception throws by API create and publish activities. + */ + protected void createAndPublishAPIWithoutRequireReSubscription(APIIdentifier apiIdentifier, String apiContext, + String apiTags, + APIPublisherRestClient publisherRestClient) + throws Exception { + createAndPublishAPI(apiIdentifier, apiContext, apiTags, publisherRestClient, false); + } + + + /** + * Copy and API and create a new version. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider + * @param newAPIVersion - New API version need to create + * @param publisherRestClient - Instance of APIPublisherRestClient + * @throws Exception- Exception throws by API copy activities. + */ + + protected void copyAPI(APIIdentifier apiIdentifier, String newAPIVersion, + APIPublisherRestClient publisherRestClient) throws Exception { + //Copy API to version to newVersion + HttpResponse httpResponseCopyAPI = + publisherRestClient.copyAPI(apiIdentifier.getProviderName(), apiIdentifier.getApiName(), + apiIdentifier.getVersion(), newAPIVersion, ""); + if (!(httpResponseCopyAPI.getResponseCode() == HTTP_RESPONSE_CODE_OK && + getValueFromJSON(httpResponseCopyAPI, "error").equals("false"))) { + throw new APIManagerIntegrationTestException("Error in API Copy." + + getAPIIdentifierString(apiIdentifier) + " New API Version :" + newAPIVersion + + "Response Code:" + httpResponseCopyAPI.getResponseCode() + + " Response Data :" + httpResponseCopyAPI.getData()); + + } + + } + + + /** + * Copy and publish the copied API. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider + * @param newAPIVersion - New API version need to create + * @param publisherRestClient - Instance of APIPublisherRestClient + * @param isRequireReSubscription - If publish with re-subscription required option true else false. + * @throws Exception + */ + protected void copyAndPublishCopiedAPI(APIIdentifier apiIdentifier, String newAPIVersion, APIPublisherRestClient publisherRestClient, boolean isRequireReSubscription) throws Exception { + + copyAPI(apiIdentifier, newAPIVersion, publisherRestClient); + APIIdentifier copiedAPIIdentifier = new APIIdentifier(apiIdentifier.getProviderName(), apiIdentifier.getApiName(), newAPIVersion); + publishAPI(copiedAPIIdentifier, publisherRestClient, isRequireReSubscription); + + } + + /** + * Create publish and subscribe a API. + * + * @param apiIdentifier - Instance of APIIdentifier object that include the API Name, + * API Version and API Provider + * @param apiContext - Context of the API + * @param publisherRestClient - Instance of APIPublisherRestClient + * @param storeRestClient - Instance of APIStoreRestClient + * @param applicationName - Name of the Application that the API need to subscribe. + * @throws Exception- Exception throws by API create publish and subscribe a API activities. + */ + protected void createPublishAndSubscribeAPI(APIIdentifier apiIdentifier, String apiContext, + APIPublisherRestClient publisherRestClient, + APIStoreRestClient storeRestClient, String applicationName) + throws Exception { + createAndPublishAPI(apiIdentifier, apiContext, publisherRestClient, false); + HttpResponse httpResponseSubscribeAPI = subscribeAPI(apiIdentifier, applicationName, storeRestClient); + if (!(httpResponseSubscribeAPI.getResponseCode() == HTTP_RESPONSE_CODE_OK && + getValueFromJSON(httpResponseSubscribeAPI, "error").equals("false"))) { + throw new APIManagerIntegrationTestException("Error in API Subscribe." + + getAPIIdentifierString(apiIdentifier) + + "Response Code:" + httpResponseSubscribeAPI.getResponseCode() + + " Response Data :" + httpResponseSubscribeAPI.getData()); + + } + + + } + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIPublishingAndVisibilityInStoreTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIPublishingAndVisibilityInStoreTestCase.java new file mode 100644 index 0000000000..c05a1b4841 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/APIPublishingAndVisibilityInStoreTestCase.java @@ -0,0 +1,115 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.APIMgtTestUtil; +import org.wso2.am.integration.test.utils.bean.APILifeCycleState; +import org.wso2.am.integration.test.utils.bean.APILifeCycleStateRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.util.List; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Publish a API and check its visibility in the API Store. + */ +public class APIPublishingAndVisibilityInStoreTestCase extends APIManagerLifecycleBaseTest { + + + private APIIdentifier apiIdentifierAPI1Version1; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + } + + + @Test(groups = {"wso2.am"}, description = "Create a API and check its availability in Publisher.") + public void testAPICreation() throws Exception { + //Create APi + HttpResponse createAPIResponse = createAPI(API1_NAME, API1_CONTEXT, API_VERSION1, apiPublisherClientUser1); + assertEquals(createAPIResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Create API Response Code is invalid." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(createAPIResponse, "error"), "false", + "Error in API Creation in " + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + createAPIResponse.getData()); + + //Verify the API in API Publisher + List apiPublisherAPIIdentifierList = + APIMgtTestUtil.getAPIIdentifierListFromHttpResponse( + apiPublisherClientUser1.getApi(API1_NAME, API1_PROVIDER_NAME, API_VERSION1)); + assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiPublisherAPIIdentifierList), true, + "Added Api is not available in APi Publisher. " + getAPIIdentifierString(apiIdentifierAPI1Version1)); + } + + + @Test(groups = {"wso2.am"}, description = "Check the visibility of API in Store before the API publish. " + + "it should not be available in store.", dependsOnMethods = "testAPICreation") + public void testVisibilityOfAPIInStoreBeforePublishing() throws Exception { + //Verify the API in API Store : API should not be available in the store. + List apiStoreAPIIdentifierList = + APIMgtTestUtil.getAPIIdentifierListFromHttpResponse(apiStoreClientUser1.getAPI(API1_NAME)); + assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), false, + "Api is visible in API Store before publish." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + } + + + @Test(groups = {"wso2.am"}, description = "Test the API publishing action. " + + "Response HTTP message should contains API status change from CREATED to PUBLISHED", + dependsOnMethods = "testVisibilityOfAPIInStoreBeforePublishing") + public void testAPIPublishing() throws Exception { + //Publish the API + APILifeCycleStateRequest publishUpdateRequest = + new APILifeCycleStateRequest(API1_NAME, API1_PROVIDER_NAME, APILifeCycleState.PUBLISHED); + publishUpdateRequest.setVersion(API_VERSION1); + HttpResponse publishAPIResponse = + apiPublisherClientUser1.changeAPILifeCycleStatusToPublish(apiIdentifierAPI1Version1, false); + assertEquals(publishAPIResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "API publish Response code is invalid " + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertTrue(verifyAPIStatusChange(publishAPIResponse, APILifeCycleState.CREATED, APILifeCycleState.PUBLISHED), + "API status Change is invalid in" + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + publishAPIResponse.getData()); + } + + @Test(groups = {"wso2.am"}, description = "Test the visibility of API in the store after API publish.", + dependsOnMethods = "testAPIPublishing") + public void testVisibilityOfAPIInStoreAfterPublishing() throws Exception { + //Verify the API in API Store : API should not be available in the store. + List apiStoreAPIIdentifierList = + APIMgtTestUtil.getAPIIdentifierListFromHttpResponse(apiStoreClientUser1.getAPI(API1_NAME)); + assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), true, + "Api is not visible in API Store after publish. " + getAPIIdentifierString(apiIdentifierAPI1Version1)); + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + } + + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfBlockAPITestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfBlockAPITestCase.java new file mode 100644 index 0000000000..23e2b900fc --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfBlockAPITestCase.java @@ -0,0 +1,124 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.bean.APILifeCycleState; +import org.wso2.am.integration.test.utils.bean.APILifeCycleStateRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * "Block an API and check its accessibility in the API Store." + */ +public class AccessibilityOfBlockAPITestCase extends APIManagerLifecycleBaseTest { + private APIIdentifier apiIdentifierAPI1Version1; + + private String applicationName; + + private Map requestHeaders; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + applicationName = + (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + + @Test(groups = {"wso2.am"}, description = "Test invocation of the APi before block") + public void testInvokeAPIBeforeChangeAPILifecycleToBlock() throws Exception { + + //Create and publish and subscribe API version 1.0.0 + createPublishAndSubscribeAPI(apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1, apiStoreClientUser1, applicationName); + + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + + // Create requestHeaders + requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke api before block"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke API before block" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Change API lifecycle to block", dependsOnMethods = "testInvokeAPIBeforeChangeAPILifecycleToBlock") + public void testChangeAPILifecycleToBlock() throws Exception { + //Block the API version 1.0.0 + APILifeCycleStateRequest blockUpdateRequest = + new APILifeCycleStateRequest(API1_NAME, API1_PROVIDER_NAME, APILifeCycleState.BLOCKED); + blockUpdateRequest.setVersion(API_VERSION1); + //Change API lifecycle to Block + HttpResponse blockAPIActionResponse = + apiPublisherClientUser1.changeAPILifeCycleStatus(blockUpdateRequest); + assertEquals(blockAPIActionResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched"); + assertTrue(verifyAPIStatusChange(blockAPIActionResponse, APILifeCycleState.PUBLISHED, + APILifeCycleState.BLOCKED), "API status Change is invalid when block an API :" + + getAPIIdentifierString(apiIdentifierAPI1Version1) + " Response Code:" + blockAPIActionResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Invocation og the APi after block", dependsOnMethods = "testChangeAPILifecycleToBlock") + public void testInvokeAPIAfterChangeAPILifecycleToBlock() throws Exception { + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE, + "Response code mismatched when invoke api after block"); + assertTrue(oldVersionInvokeResponse.getData().contains(HTTP_RESPONSE_DATA_API_BLOCK), + "Response data mismatched when invoke API after block" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + } + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + } + + +} + diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfDeprecatedOldAPIAndPublishedCopyAPITestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfDeprecatedOldAPIAndPublishedCopyAPITestCase.java new file mode 100644 index 0000000000..2babf2bcec --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfDeprecatedOldAPIAndPublishedCopyAPITestCase.java @@ -0,0 +1,197 @@ +/* + * 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.tests.api.lifecycle; + + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.APIMgtTestUtil; +import org.wso2.am.integration.test.utils.bean.APILifeCycleState; +import org.wso2.am.integration.test.utils.bean.APILifeCycleStateRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Publish a API. Copy and create a new version, publish the new version and deprecate the old version, + * test invocation of both old and new API versions." + */ +public class AccessibilityOfDeprecatedOldAPIAndPublishedCopyAPITestCase extends APIManagerLifecycleBaseTest { + + + private APIIdentifier apiIdentifierAPI1Version1; + private APIIdentifier apiIdentifierAPI1Version2; + private String applicationName; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + apiIdentifierAPI1Version2 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION2); + applicationName = + (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + + @Test(groups = {"wso2.am"}, description = "Test subscribe of old API version before deprecate the old version") + public void testSubscribeOldVersionBeforeDeprecate() throws Exception { + + //Create and publish API version 1.0.0 + createAndPublishAPIWithoutRequireReSubscription( + apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1); + // Copy to version 2.0.0 and Publish Copied API + copyAndPublishCopiedAPI(apiIdentifierAPI1Version1, API_VERSION2, apiPublisherClientUser1, false); + + HttpResponse oldVersionSubscribeResponse = + subscribeAPI(apiIdentifierAPI1Version1, applicationName, apiStoreClientUser1); + assertEquals(oldVersionSubscribeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Subscribe of old API version request not successful " + + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(oldVersionSubscribeResponse, "error"), "false", + "Error in subscribe of old API version" + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + oldVersionSubscribeResponse.getData()); + } + + + @Test(groups = {"wso2.am"}, description = "Test subscribe of new API version before deprecate the old version", + dependsOnMethods = "testSubscribeOldVersionBeforeDeprecate") + public void testSubscribeNewVersion() throws Exception { + + HttpResponse newVersionSubscribeResponse = + subscribeAPI(apiIdentifierAPI1Version2, applicationName, apiStoreClientUser1); + assertEquals(newVersionSubscribeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Subscribe of old API version request not successful " + + getAPIIdentifierString(apiIdentifierAPI1Version2)); + assertEquals(getValueFromJSON(newVersionSubscribeResponse, "error"), "false", + "Error in subscribe of old API version" + getAPIIdentifierString(apiIdentifierAPI1Version2) + + "Response Data:" + newVersionSubscribeResponse.getData()); + } + + + @Test(groups = {"wso2.am"}, description = "Test deprecate old api version", dependsOnMethods = "testSubscribeNewVersion") + public void testDeprecateOldVersion() throws Exception { + + APILifeCycleStateRequest deprecatedUpdateRequest = + new APILifeCycleStateRequest(API1_NAME, API1_PROVIDER_NAME, APILifeCycleState.DEPRECATED); + deprecatedUpdateRequest.setVersion(API_VERSION1); + HttpResponse deprecateAPIResponse = + apiPublisherClientUser1.changeAPILifeCycleStatus(deprecatedUpdateRequest); + + assertEquals(deprecateAPIResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "API deprecate Response code is invalid " + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertTrue(verifyAPIStatusChange(deprecateAPIResponse, + APILifeCycleState.PUBLISHED, APILifeCycleState.DEPRECATED), + "API deprecate status Change is invalid in" + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + deprecateAPIResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the visibility of API in the store after API deprecate.", + dependsOnMethods = "testDeprecateOldVersion") + public void testVisibilityOfOldAPIInStoreAfterDeprecate() throws Exception { + //Verify the API in API Store + List apiStoreAPIIdentifierList = + APIMgtTestUtil.getAPIIdentifierListFromHttpResponse(apiStoreClientUser1.getAPI(API1_NAME)); + assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), true, + "Old API version is not visible in API Store after deprecate." + + getAPIIdentifierString(apiIdentifierAPI1Version1)); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the visibility of API in the store after API deprecate.", + dependsOnMethods = "testVisibilityOfOldAPIInStoreAfterDeprecate") + public void testVisibilityOfNewAPIInStore() throws Exception { + //Verify the API in API Store + List apiStoreAPIIdentifierList = + APIMgtTestUtil.getAPIIdentifierListFromHttpResponse(apiStoreClientUser1.getAPI(API1_NAME)); + assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version2, apiStoreAPIIdentifierList), true, + "New API version is not visible in API Store after deprecate the old version." + + getAPIIdentifierString(apiIdentifierAPI1Version2)); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the subscription of deprecated API version.", + dependsOnMethods = "testVisibilityOfNewAPIInStore") + public void testSubscribeOldVersionAfterDeprecate() throws Exception { + //subscribe deprecated old version + + HttpResponse oldVersionSubscribeResponse = subscribeAPI + (apiIdentifierAPI1Version1, applicationName, apiStoreClientUser2); + assertEquals(oldVersionSubscribeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Subscribe of old API version after deprecate response code is invalid." + + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(oldVersionSubscribeResponse, "error"), "true", + "Subscribe of old API version after deprecate success, which should fail." + + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + oldVersionSubscribeResponse.getData()); + + + } + + + @Test(groups = {"wso2.am"}, description = "Test the invocation of both deprecated old and " + + "publish new API versions", dependsOnMethods = "testSubscribeOldVersionAfterDeprecate") + public void testAccessibilityOfDeprecateOldAPIAndPublishedCopyAPI() throws Exception { + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + // Create requestHeaders + Map requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + + API1_END_POINT_METHOD, requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), + HTTP_RESPONSE_CODE_OK, "Response code mismatched"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), "Response data mismatched"); + + //Invoke new version + HttpResponse newVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + + "/" + API_VERSION2 + API1_END_POINT_METHOD, requestHeaders); + + assertEquals(newVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched"); + assertTrue(newVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), "Response data mismatched"); + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + deleteAPI(apiIdentifierAPI1Version2, apiPublisherClientUser1); + } + + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfOldAPIAndCopyAPIWithOutReSubscriptionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfOldAPIAndCopyAPIWithOutReSubscriptionTestCase.java new file mode 100644 index 0000000000..b9c1dcad48 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfOldAPIAndCopyAPIWithOutReSubscriptionTestCase.java @@ -0,0 +1,152 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.bean.APILifeCycleState; +import org.wso2.am.integration.test.utils.bean.APILifeCycleStateRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Publish a API. Copy and create a new version, publish the new API version with out re-subscription required and + * test invocation of New API without re-subscription." + */ +public class AccessibilityOfOldAPIAndCopyAPIWithOutReSubscriptionTestCase extends APIManagerLifecycleBaseTest { + private APIIdentifier apiIdentifierAPI1Version1; + private APIIdentifier apiIdentifierAPI1Version2; + private String applicationName; + + private Map requestHeaders; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + apiIdentifierAPI1Version2 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION2); + applicationName = + (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + + @Test(groups = {"wso2.am"}, description = "Test subscribe of old api version.") + public void testSubscriptionOfOldAPI() throws Exception { + //Create and publish API version 1.0.0 + createAndPublishAPIWithoutRequireReSubscription( + apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1); + + // Subscribe old api version (1.0.0) + HttpResponse oldVersionSubscribeResponse = + subscribeAPI(apiIdentifierAPI1Version1, applicationName, apiStoreClientUser1); + assertEquals(oldVersionSubscribeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Subscribe of old API version request not successful " + + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(oldVersionSubscribeResponse, "error"), "false", + "Error in subscribe of old API version" + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + oldVersionSubscribeResponse.getData()); + + + } + + + @Test(groups = {"wso2.am"}, description = "Test publishing of copied API with out re-subscription required", + dependsOnMethods = "testSubscriptionOfOldAPI") + public void testPublishCopiedAPIWithOutReSubscriptionRequired() throws Exception { + // Copy API + copyAPI(apiIdentifierAPI1Version1, API_VERSION2, apiPublisherClientUser1); + + + //Publish version 2.0.0 with re-subscription required + APILifeCycleStateRequest publishUpdateRequest = + new APILifeCycleStateRequest(API1_NAME, API1_PROVIDER_NAME, APILifeCycleState.PUBLISHED); + publishUpdateRequest.setVersion(API_VERSION2); + HttpResponse publishAPIResponse = + apiPublisherClientUser1.changeAPILifeCycleStatusToPublish(apiIdentifierAPI1Version2, false); + assertEquals(publishAPIResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "API publish Response code is invalid " + getAPIIdentifierString(apiIdentifierAPI1Version2)); + assertTrue(verifyAPIStatusChange(publishAPIResponse, APILifeCycleState.CREATED, APILifeCycleState.PUBLISHED), + "API status Change is invalid in" + getAPIIdentifierString(apiIdentifierAPI1Version2) + + "Response Data:" + publishAPIResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test invocation of old API version before the" + + " new version is subscribed.", dependsOnMethods = "testPublishCopiedAPIWithOutReSubscriptionRequired") + public void testInvokeOldAPIBeforeSubscribeTheNewVersion() throws Exception { + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + // Create requestHeaders + requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke old api before subscribe the new version"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke old API version before subscribe the new version." + + " Response Data:" + oldVersionInvokeResponse.getData()); + + + } + + + @Test(groups = {"wso2.am"}, description = "Test invocation of new API version" + + " before the new version is subscribed.", dependsOnMethods = "testInvokeOldAPIBeforeSubscribeTheNewVersion") + public void testInvokeNewAPIWithoutSubscribeTheNewVersion() throws Exception { + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION2 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke new api before subscribe the new version when re-subscription" + + " is not required."); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke new API version before subscribe the new version when" + + "re-subscription is not required." + " Response Data:" + oldVersionInvokeResponse.getData()); + + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + deleteAPI(apiIdentifierAPI1Version2, apiPublisherClientUser1); + } + + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfOldAPIAndCopyAPIWithReSubscriptionTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfOldAPIAndCopyAPIWithReSubscriptionTestCase.java new file mode 100644 index 0000000000..ab6779a5e1 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfOldAPIAndCopyAPIWithReSubscriptionTestCase.java @@ -0,0 +1,189 @@ +/* + * 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.tests.api.lifecycle; + + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.bean.APILifeCycleState; +import org.wso2.am.integration.test.utils.bean.APILifeCycleStateRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * "Publish a API. Copy and create a new version, publish the new API version with re-subscription required and + * test invocation of New API before and after the re-subscription." + */ +public class AccessibilityOfOldAPIAndCopyAPIWithReSubscriptionTestCase extends APIManagerLifecycleBaseTest { + private APIIdentifier apiIdentifierAPI1Version1; + private APIIdentifier apiIdentifierAPI1Version2; + private String applicationName; + + private Map requestHeaders; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + apiIdentifierAPI1Version2 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION2); + applicationName = + (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + + @Test(groups = {"wso2.am"}, description = "Test subscribe of old api version.", enabled = false) + public void testSubscriptionOfOldAPI() throws Exception { + //disable the test case because of APIMANAGER-3374 + //Create and publish API version 1.0.0 + createAndPublishAPIWithoutRequireReSubscription( + apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1); + + + // Subscribe old api version (1.0.0) + HttpResponse oldVersionSubscribeResponse = + subscribeAPI(apiIdentifierAPI1Version1, applicationName, apiStoreClientUser1); + assertEquals(oldVersionSubscribeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Subscribe of old API version request not successful " + + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(oldVersionSubscribeResponse, "error"), "false", + "Error in subscribe of old API version" + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + oldVersionSubscribeResponse.getData()); + + + } + + + @Test(groups = {"wso2.am"}, description = "Test publishing of copied API with re-subscription required", + dependsOnMethods = "testSubscriptionOfOldAPI", enabled = false) + public void testPublishCopiedAPIWithReSubscriptionRequired() throws Exception { + + // Copy API + copyAPI(apiIdentifierAPI1Version1, API_VERSION2, apiPublisherClientUser1); + + + //Publish version 2.0.0 with re-subscription required + APILifeCycleStateRequest publishUpdateRequest = + new APILifeCycleStateRequest(API1_NAME, API1_PROVIDER_NAME, APILifeCycleState.PUBLISHED); + publishUpdateRequest.setVersion(API_VERSION2); + HttpResponse publishAPIResponse = + apiPublisherClientUser1.changeAPILifeCycleStatusToPublish(apiIdentifierAPI1Version2, true); + assertEquals(publishAPIResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "API publish Response code is invalid " + getAPIIdentifierString(apiIdentifierAPI1Version2)); + assertTrue(verifyAPIStatusChange(publishAPIResponse, APILifeCycleState.CREATED, APILifeCycleState.PUBLISHED), + "API status Change is invalid in" + getAPIIdentifierString(apiIdentifierAPI1Version2) + + "Response Data:" + publishAPIResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test invocation of old API version before the new version is subscribed.", + dependsOnMethods = "testPublishCopiedAPIWithReSubscriptionRequired", enabled = false) + public void testInvokeOldAPIBeforeSubscribeTheNewVersion() throws Exception { + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + // Create requestHeaders + requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke old api before subscribe the new version"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke old API version before subscribe the new version." + + " Response Data:" + oldVersionInvokeResponse.getData()); + + + } + + + @Test(groups = {"wso2.am"}, description = "Test invocation of new API version before the new version is subscribed. " + + "This invocation should be failed", dependsOnMethods = "testInvokeOldAPIBeforeSubscribeTheNewVersion", enabled = false) + public void testInvokeNewAPIBeforeSubscribeTheNewVersion() throws Exception { + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION2 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_UNAUTHORIZED, + "Response code mismatched when invoke new api before subscribe the new version"); + assertTrue(oldVersionInvokeResponse.getData().contains(HTTP_RESPONSE_DATA_INVALID_CREDENTIALS), + "Response data mismatched when invoke new API version before subscribe the new version." + + " Response Data:" + oldVersionInvokeResponse.getData()); + + + } + + @Test(groups = {"wso2.am"}, description = "Test subscribe the new API Version", + dependsOnMethods = "testInvokeNewAPIBeforeSubscribeTheNewVersion", enabled = false) + public void testSubscribeTheNewVersion() throws Exception { + + //subscribe new version + HttpResponse httpResponseSubscribeNewVersion = subscribeAPI(apiIdentifierAPI1Version2, applicationName, apiStoreClientUser1); + assertEquals(httpResponseSubscribeNewVersion.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Subscribe of New API version when re-subscription required not successful. Invalid Response Code " + + getAPIIdentifierString(apiIdentifierAPI1Version2)); + assertEquals(getValueFromJSON(httpResponseSubscribeNewVersion, "error"), "false", + "Error in subscribe of New API version when re-subscription required not successful" + getAPIIdentifierString(apiIdentifierAPI1Version2) + + "Response Data:" + httpResponseSubscribeNewVersion.getData()); + + + } + + @Test(groups = {"wso2.am"}, description = "Test invocation of new API version after the new version is subscribed.", + dependsOnMethods = "testSubscribeTheNewVersion", enabled = false) + public void testInvokeNewAPIAfterSubscribeTheNewVersion() throws Exception { + + + //Invoke new version after subscription + HttpResponse oldVersionInvokeResponse = HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION2 + + API1_END_POINT_METHOD, requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched when invoke " + + "new api after subscribe the new version"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), "Response data mismatched when invoke new API" + + " version after subscribe the new version. Response Data:" + oldVersionInvokeResponse.getData()); + + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + deleteAPI(apiIdentifierAPI1Version2, apiPublisherClientUser1); + } + + +} + + diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfRetireAPITestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfRetireAPITestCase.java new file mode 100644 index 0000000000..b8947f0db9 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/AccessibilityOfRetireAPITestCase.java @@ -0,0 +1,139 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.APIMgtTestUtil; +import org.wso2.am.integration.test.utils.bean.APILifeCycleState; +import org.wso2.am.integration.test.utils.bean.APILifeCycleStateRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * "Retire an API and check its accessibility and visibility in the API Store." + */ +public class AccessibilityOfRetireAPITestCase extends APIManagerLifecycleBaseTest { + private APIIdentifier apiIdentifierAPI1Version1; + + private String applicationName; + + private Map requestHeaders; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + applicationName = + (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + + @Test(groups = {"wso2.am"}, description = "Test invocation of the APi before retire") + public void testInvokeAPIBeforeChangeAPILifecycleToRetired() throws Exception { + + //Create and publish and subscribe API version 1.0.0 + createPublishAndSubscribeAPI(apiIdentifierAPI1Version1, API1_CONTEXT, + apiPublisherClientUser1, apiStoreClientUser1, applicationName); + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + // Create requestHeaders + requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke api before Retire"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke API before Retire" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Change API lifecycle to Retired", + dependsOnMethods = "testInvokeAPIBeforeChangeAPILifecycleToRetired") + public void testChangeAPILifecycleToRetired() throws Exception { + //Block the API version 1.0.0 + APILifeCycleStateRequest blockUpdateRequest = + new APILifeCycleStateRequest(API1_NAME, API1_PROVIDER_NAME, APILifeCycleState.RETIRED); + blockUpdateRequest.setVersion(API_VERSION1); + //Change API lifecycle to Block + HttpResponse blockAPIActionResponse = + apiPublisherClientUser1.changeAPILifeCycleStatus(blockUpdateRequest); + assertEquals(blockAPIActionResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, "Response code mismatched"); + assertTrue(verifyAPIStatusChange(blockAPIActionResponse, APILifeCycleState.PUBLISHED, + APILifeCycleState.RETIRED), "API status Change is invalid when retire an API :" + + getAPIIdentifierString(apiIdentifierAPI1Version1) + + " Response Code:" + blockAPIActionResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the availability of retired API in the store", + dependsOnMethods = "testChangeAPILifecycleToRetired") + public void testAvailabilityOfRetiredAPIInStore() throws Exception { + // Verify the API in API Store : API should not be available in the store. + List apiStoreAPIIdentifierList = APIMgtTestUtil.getAPIIdentifierListFromHttpResponse( + apiStoreClientUser1.getAPI(API1_NAME)); + assertEquals(APIMgtTestUtil.isAPIAvailable(apiIdentifierAPI1Version1, apiStoreAPIIdentifierList), false, + "Api is visible in API Store after retire." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the invocation of the API after retire", + dependsOnMethods = "testAvailabilityOfRetiredAPIInStore") + public void testInvokeAPIAfterChangeAPILifecycleToRetired() throws Exception { + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_NOT_FOUND, + "Response code mismatched when invoke api after retire"); + assertTrue(oldVersionInvokeResponse.getData().contains(HTTP_RESPONSE_DATA_NOT_FOUND), + "Response data mismatched when invoke API after retire" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + } + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + } + + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPIBackendURLTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPIBackendURLTestCase.java new file mode 100644 index 0000000000..ded0532d07 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPIBackendURLTestCase.java @@ -0,0 +1,132 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.bean.APIRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Change the API Backend URL and test the invocation. + */ +public class ChangeAPIBackendURLTestCase extends APIManagerLifecycleBaseTest { + private APIIdentifier apiIdentifierAPI1Version1; + private Map requestHeaders; + private String applicationName; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + applicationName = + (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + @Test(groups = {"wso2.am"}, description = "Test invocation of API before change the api backend URL.", enabled = false) + public void testAPIInvocationBeforeChangeTheBackendURL() throws Exception { + //Disable the test case because of APIMANAGER-3378 + //Create and publish and subscribe API version 1.0.0 + createPublishAndSubscribeAPI(apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1, + apiStoreClientUser1, applicationName); + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + // Create requestHeaders + requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke api before change the backend URL"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke API before change the backend URL" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test changing of the API Backend URL", + dependsOnMethods = "testAPIInvocationBeforeChangeTheBackendURL", enabled = false) + public void testEditBackendURLAPIContext() throws Exception { + + + //Create the API Request with new context + + APIRequest apiRequestBean = new APIRequest(API1_NAME, API1_CONTEXT, new URL(API2_END_POINT_URL)); + apiRequestBean.setTags(API1_TAGS); + apiRequestBean.setDescription(API1_DESCRIPTION); + apiRequestBean.setVersion(API_VERSION1); + apiRequestBean.setVisibility("public"); + //Update API with Edited information + HttpResponse updateAPIHTTPResponse = apiPublisherClientUser1.updateAPI(apiRequestBean); + + assertEquals(updateAPIHTTPResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Update API backend URL Response Code is invalid." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(updateAPIHTTPResponse, "error"), "false", + "Error in API backend URL Update in " + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + updateAPIHTTPResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the invocation of API using new backend URL" + + " after backend URL change", dependsOnMethods = "testEditBackendURLAPIContext", enabled = false) + public void testInvokeAPIAfterChangeAPIBackendURLWithNewBackendURL() throws Exception { + //Invoke new context + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke API after change the backend URL"); + assertTrue(oldVersionInvokeResponse.getData().contains(API2_RESPONSE_DATA), + "Response data mismatched when invoke API after change the backend URL" + + " Response Data:" + oldVersionInvokeResponse.getData()); + assertTrue(!(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA)), + "Response data mismatched when invoke API after change the backend URL. It contains the" + + " Old backend URL response data. Response Data:" + oldVersionInvokeResponse.getData()); + + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + + } + + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPIEndPointURLTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPIEndPointURLTestCase.java new file mode 100644 index 0000000000..92c0caa590 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPIEndPointURLTestCase.java @@ -0,0 +1,132 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.bean.APIRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Change the API end point URL and test the invocation. + */ +public class ChangeAPIEndPointURLTestCase extends APIManagerLifecycleBaseTest { + private APIIdentifier apiIdentifierAPI1Version1; + private Map requestHeaders; + private String applicationName; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + applicationName = + (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + @Test(groups = {"wso2.am"}, description = "Test invocation of API before change the api end point URL.", enabled = false) + public void testAPIInvocationBeforeChangeTheEndPointURL() throws Exception { + //Disable the test case because of APIMANAGER-3378 + //Create and publish and subscribe API version 1.0.0 + createPublishAndSubscribeAPI(apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1, + apiStoreClientUser1, applicationName); + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + // Create requestHeaders + requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke api before change the end point URL"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke API before change the end point URL" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test changing of the API end point URL", + dependsOnMethods = "testAPIInvocationBeforeChangeTheEndPointURL", enabled = false) + public void testEditEndPointURL() throws Exception { + + + //Create the API Request with new context + + APIRequest apiRequestBean = new APIRequest(API1_NAME, API1_CONTEXT, new URL(API2_END_POINT_URL)); + apiRequestBean.setTags(API1_TAGS); + apiRequestBean.setDescription(API1_DESCRIPTION); + apiRequestBean.setVersion(API_VERSION1); + apiRequestBean.setVisibility("public"); + //Update API with Edited information + HttpResponse updateAPIHTTPResponse = apiPublisherClientUser1.updateAPI(apiRequestBean); + + assertEquals(updateAPIHTTPResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Update API end point URL Response Code is invalid." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(updateAPIHTTPResponse, "error"), "false", + "Error in API end point URL Update in " + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + updateAPIHTTPResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the invocation of API using new end point URL" + + " after end point URL change", dependsOnMethods = "testEditEndPointURL", enabled = false) + public void testInvokeAPIAfterChangeAPIEndPointURLWithNewEndPointURL() throws Exception { + //Invoke new context + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke API after change the end point URL"); + assertTrue(oldVersionInvokeResponse.getData().contains(API2_RESPONSE_DATA), + "Response data mismatched when invoke API after change the end point URL" + + " Response Data:" + oldVersionInvokeResponse.getData()); + assertTrue(!(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA)), + "Response data mismatched when invoke API after change the end point URL. It contains the" + + " Old end point URL response data. Response Data:" + oldVersionInvokeResponse.getData()); + + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + + } + + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPITagsTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPITagsTestCase.java new file mode 100644 index 0000000000..60ce3361b5 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/ChangeAPITagsTestCase.java @@ -0,0 +1,168 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.bean.APIRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.*; + + +/** + * Change the API Tags and check how the API are listed under tags. + */ +public class ChangeAPITagsTestCase extends APIManagerLifecycleBaseTest { + + + private APIIdentifier apiIdentifierAPI1Version1; + private Map apiTagsMapBeforeChange; + private Map apiTagsMapAfterChange; + private static final String TEST_TAG = "Tag3"; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + + apiTagsMapBeforeChange = new HashMap(); + apiTagsMapBeforeChange.put("APITagTest1", "Tag1, Tag2, Tag3"); + apiTagsMapBeforeChange.put("APITagTest2", "Tag2, Tag3, Tag4"); + apiTagsMapBeforeChange.put("APITagTest3", "Tag1, Tag3, Tag5"); + apiTagsMapBeforeChange.put("APITagTest4", "Tag1, Tag2"); + + apiTagsMapAfterChange = new HashMap(); + apiTagsMapAfterChange.put("APITagTest1", "Tag1, Tag2"); + apiTagsMapAfterChange.put("APITagTest2", "Tag2, Tag4"); + apiTagsMapAfterChange.put("APITagTest3", "Tag1, Tag5"); + apiTagsMapAfterChange.put("APITagTest4", "Tag1, Tag2"); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the filter by Tags before changing the Tags") + public void testFilterByTagsBeforeTagChange() throws Exception { + + + for (Map.Entry apiTagEntry : apiTagsMapBeforeChange.entrySet()) { + String apiName = apiTagEntry.getKey(); + String apiTags = apiTagEntry.getValue(); + String apiContext = apiName.toLowerCase(); + APIIdentifier apiIdentifier = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION1); + + createAndPublishAPIWithoutRequireReSubscription(apiIdentifier, apiContext, apiTags, apiPublisherClientUser1); + + } + + + HttpResponse apiPageFilteredWithTagsResponse = apiStoreClientUser1.getAPIPageFilteredWithTags("Tag3"); + assertEquals(apiPageFilteredWithTagsResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, ""); + String apiPageFilteredWithTagsResponseString = apiPageFilteredWithTagsResponse.getData(); + + for (Map.Entry apiTagEntry : apiTagsMapBeforeChange.entrySet()) { + + String apiLinkToTestInPage = "/store/apis/info?name=" + apiTagEntry.getKey() + "&version=" + API_VERSION1 + + "&provider=" + API1_PROVIDER_NAME + "&tenant=carbon.super&tag=" + TEST_TAG + ""; + if (apiTagEntry.getValue().contains(TEST_TAG)) { + //API Link should be in page + assertTrue(apiPageFilteredWithTagsResponseString.contains(apiLinkToTestInPage), + "API is not listed with correct tag, API:" + apiTagEntry.getKey() + " Tag:" + TEST_TAG); + } else { + //API Link should not be in page + assertFalse(apiPageFilteredWithTagsResponseString.contains(apiLinkToTestInPage), + "API is listed with incorrect tag, API:" + apiTagEntry.getKey() + " Tag:" + TEST_TAG); + } + + } + + } + + + @Test(groups = {"wso2.am"}, description = "Test the filter by Tags After changing the Tags", + dependsOnMethods = "testFilterByTagsBeforeTagChange") + public void testUpdateTagsAndFilterByTags() throws Exception { + + + for (Map.Entry apiTagEntry : apiTagsMapAfterChange.entrySet()) { + String apiName = apiTagEntry.getKey(); + String apiTags = apiTagEntry.getValue(); + String apiContext = apiName.toLowerCase(); + + APIRequest apiRequestBean = new APIRequest(apiName, apiContext, new URL(API1_END_POINT_URL)); + + apiRequestBean.setTags(apiTags); + apiRequestBean.setDescription(API1_DESCRIPTION); + apiRequestBean.setVersion(API_VERSION1); + apiRequestBean.setVisibility("public"); + + //Update API with Edited Tags + HttpResponse updateAPIHTTPResponse = apiPublisherClientUser1.updateAPI(apiRequestBean); + + assertEquals(updateAPIHTTPResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Update API Response Code is invalid." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(updateAPIHTTPResponse, "error"), "false", + "Error in API Update in " + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + updateAPIHTTPResponse.getData()); + + } + + + HttpResponse apiPageFilteredWithTagsResponse = apiStoreClientUser1.getAPIPageFilteredWithTags("Tag3"); + assertEquals(apiPageFilteredWithTagsResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, ""); + String apiPageFilteredWithTagsResponseString = apiPageFilteredWithTagsResponse.getData(); + + for (Map.Entry apiTagEntry : apiTagsMapBeforeChange.entrySet()) { + + String apiLinkToTestInPage = "/store/apis/info?name=" + apiTagEntry.getKey() + "&version=" + API_VERSION1 + + "&provider=" + API1_PROVIDER_NAME + "&tenant=carbon.super&tag=" + TEST_TAG + ""; + if (apiTagEntry.getValue().contains(TEST_TAG)) { + //API Link should be in page + assertTrue(apiPageFilteredWithTagsResponseString.contains(apiLinkToTestInPage), + " API is not listed with correct tag, API:" + apiTagEntry.getKey() + " Tag:" + TEST_TAG); + } else { + //API Link should not be in page + assertFalse(apiPageFilteredWithTagsResponseString.contains(apiLinkToTestInPage), + "API is listed with incorrect tag, API:" + apiTagEntry.getKey() + " Tag:" + TEST_TAG); + } + + } + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + for (Map.Entry apiTagEntry : apiTagsMapBeforeChange.entrySet()) { + String apiName = apiTagEntry.getKey(); + APIIdentifier apiIdentifier = new APIIdentifier(API1_PROVIDER_NAME, apiName, API_VERSION1); + deleteAPI(apiIdentifier, apiPublisherClientUser1); + } + } + + +} + + diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/EditAPIAndCheckUpdatedInformationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/EditAPIAndCheckUpdatedInformationTestCase.java new file mode 100644 index 0000000000..0b721e5985 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/EditAPIAndCheckUpdatedInformationTestCase.java @@ -0,0 +1,101 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.APIMgtTestUtil; +import org.wso2.am.integration.test.utils.bean.APIBean; +import org.wso2.am.integration.test.utils.bean.APIRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.net.URL; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Edit the API information and check whether it is correctly updated. + */ +public class EditAPIAndCheckUpdatedInformationTestCase extends APIManagerLifecycleBaseTest { + APIIdentifier apiIdentifierAPI1Version1; + + + String newTag; + String apiNewDescription; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + + } + + + @Test(groups = {"wso2.am"}, description = "Edit the API Information") + public void testEditAPIInformation() throws Exception { + //Create and publish API version 1.0.0 + createAndPublishAPIWithoutRequireReSubscription( + apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1); + + //Edit the api + apiNewDescription = API1_DESCRIPTION + " New Description"; + newTag = "newtag"; + String apiNewTags = API1_TAGS + ", " + newTag; + + //Create the API Request with new edited information + APIRequest apiRequestBean = new APIRequest(API1_NAME, API1_CONTEXT, new URL(API1_END_POINT_URL)); + + apiRequestBean.setTags(apiNewTags); + apiRequestBean.setDescription(apiNewDescription); + apiRequestBean.setVersion(API_VERSION1); + apiRequestBean.setVisibility("public"); + //Update API with Edited information + HttpResponse updateAPIHTTPResponse = apiPublisherClientUser1.updateAPI(apiRequestBean); + + assertEquals(updateAPIHTTPResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Update API Response Code is invalid." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(updateAPIHTTPResponse, "error"), "false", + "Error in API Update in " + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + updateAPIHTTPResponse.getData()); + + } + + @Test(groups = {"wso2.am"}, description = "Test whether the updated information available in the publisher ", + dependsOnMethods = "testEditAPIInformation") + public void testUpdatedAPIInformationFromAPIPublisher() throws Exception { + + APIBean apiBeanAfterUpdate = + APIMgtTestUtil.getAPIBeanFromHttpResponse(apiPublisherClientUser1.getApi( + API1_NAME, API1_PROVIDER_NAME, API_VERSION1)); + assertEquals(apiBeanAfterUpdate.getDescription(), apiNewDescription, "Updated Description is not available"); + assertTrue(apiBeanAfterUpdate.getTags().contains(newTag), "Newly added Tag is not available"); + + } + + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + + } + +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/EditAPIContextAndCheckAccessibilityTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/EditAPIContextAndCheckAccessibilityTestCase.java new file mode 100644 index 0000000000..e544f67a83 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/api/lifecycle/EditAPIContextAndCheckAccessibilityTestCase.java @@ -0,0 +1,152 @@ +/* + * 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.tests.api.lifecycle; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.am.integration.test.utils.bean.APIRequest; +import org.wso2.carbon.apimgt.api.model.APIIdentifier; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; + +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * Edit the API context and check its accessibility. + */ +public class EditAPIContextAndCheckAccessibilityTestCase extends APIManagerLifecycleBaseTest { + APIIdentifier apiIdentifierAPI1Version1; + + private String applicationName; + private String newContext; + private Map requestHeaders; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + apiIdentifierAPI1Version1 = new APIIdentifier(API1_PROVIDER_NAME, API1_NAME, API_VERSION1); + applicationName = + (this.getClass().getName().replace(this.getClass().getPackage().getName(), "")).replace(".", ""); + apiStoreClientUser1.addApplication(applicationName, "", "", ""); + } + + + @Test(groups = {"wso2.am"}, description = "Test invoke the API before the context change", enabled=false) + public void testInvokeAPIBeforeChangeAPIContext() throws Exception { + //Disable the test case because of APIMANAGER-3377 + //Create and publish and subscribe API version 1.0.0 + createPublishAndSubscribeAPI(apiIdentifierAPI1Version1, API1_CONTEXT, apiPublisherClientUser1, + apiStoreClientUser1, applicationName); + + //get access token + String accessToken = getAccessToken(apiStoreClientUser1, applicationName); + + // Create requestHeaders + requestHeaders = new HashMap(); + requestHeaders.put("Authorization", "Bearer " + accessToken); + + //Invoke old version + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke api before change the context"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke API before change the context" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test changing of the API context", + dependsOnMethods = "testInvokeAPIBeforeChangeAPIContext", enabled=false) + public void testEditAPIContext() throws Exception { + + + //Create the API Request with new context + newContext = "new" + API1_CONTEXT; + APIRequest apiRequestBean = new APIRequest(API1_NAME, newContext, new URL(API1_END_POINT_URL)); + apiRequestBean.setTags(API1_TAGS); + apiRequestBean.setDescription(API1_DESCRIPTION); + apiRequestBean.setVersion(API_VERSION1); + apiRequestBean.setVisibility("public"); + //Update API with Edited information + HttpResponse updateAPIHTTPResponse = apiPublisherClientUser1.updateAPI(apiRequestBean); + + assertEquals(updateAPIHTTPResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Update API Response Code is invalid." + getAPIIdentifierString(apiIdentifierAPI1Version1)); + assertEquals(getValueFromJSON(updateAPIHTTPResponse, "error"), "false", + "Error in API Update in " + getAPIIdentifierString(apiIdentifierAPI1Version1) + + "Response Data:" + updateAPIHTTPResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the invocation of API using old context after Context change" + + " after the API context change", dependsOnMethods = "testEditAPIContext", enabled=false) + public void testInvokeAPIAfterChangeAPIContextWithOldContext() throws Exception { + + //Invoke old context + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + API1_CONTEXT + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_NOT_FOUND, + "Response code mismatched when invoke api before changing the context"); + assertTrue(oldVersionInvokeResponse.getData().contains(HTTP_RESPONSE_DATA_NOT_FOUND), + "Response data mismatched when invoke API before changing the context" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + } + + + @Test(groups = {"wso2.am"}, description = "Test the invocation of API using new context after Context change", + dependsOnMethods = "testInvokeAPIAfterChangeAPIContextWithOldContext", enabled=false) + public void testInvokeAPIAfterChangeAPIContextWithNewContext() throws Exception { + //Invoke new context + HttpResponse oldVersionInvokeResponse = + HttpRequestUtil.doGet(API_BASE_URL + newContext + "/" + API_VERSION1 + API1_END_POINT_METHOD, + requestHeaders); + assertEquals(oldVersionInvokeResponse.getResponseCode(), HTTP_RESPONSE_CODE_OK, + "Response code mismatched when invoke api after changing the context"); + assertTrue(oldVersionInvokeResponse.getData().contains(API1_RESPONSE_DATA), + "Response data mismatched when invoke API after changing the context" + + " Response Data:" + oldVersionInvokeResponse.getData()); + + + } + + @AfterClass(alwaysRun = true) + public void cleanup() throws Exception { + apiStoreClientUser1.removeApplication(applicationName); + deleteAPI(apiIdentifierAPI1Version1, apiPublisherClientUser1); + + } + + +} + + + + diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index d119c2eb85..dd3ad43e1b 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -1,7 +1,33 @@ + + + + + + + + + +