diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/GenerateAppKeyRequest.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/GenerateAppKeyRequest.java index e0f0d2d6d8..ea0f7d0f8e 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/GenerateAppKeyRequest.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/bean/GenerateAppKeyRequest.java @@ -28,6 +28,10 @@ public class GenerateAppKeyRequest extends AbstractRequest { private String callbackUrl = "some-url"; private String authorizedDomains = "ALL"; private int validityTime = 360000; + private String appId ="1"; + + + public GenerateAppKeyRequest(String application) { this.application = application; @@ -45,6 +49,7 @@ public void init() { addParameter("callbackUrl", callbackUrl); addParameter("authorizedDomains", authorizedDomains); addParameter("validityTime", String.valueOf(validityTime)); + addParameter("selectedAppID", appId); } public String getApplication(){ return application; } @@ -80,4 +85,13 @@ public int getValidityTime() { public void setValidityTime(int validityTime) { this.validityTime = validityTime; } + + public String getAppId() { + return appId; + } + + + public void setAppId(String appId) { + this.appId = appId; + } } 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 3e9cbe1807..f3ce5433d2 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 @@ -19,6 +19,9 @@ package org.wso2.am.integration.test.utils.clients; import org.apache.commons.codec.binary.Base64; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import org.wso2.am.integration.test.utils.bean.GenerateAppKeyRequest; import org.wso2.am.integration.test.utils.bean.SubscriptionRequest; import org.wso2.am.integration.test.utils.validation.VerificationUtil; @@ -79,6 +82,9 @@ public HttpResponse subscribe(SubscriptionRequest subscriptionRequest) public HttpResponse generateApplicationKey(GenerateAppKeyRequest generateAppKeyRequest) throws Exception { checkAuthentication(); + HttpResponse responseApp = getAllApplications(); + String appId = getApplicationId(responseApp.getData(), generateAppKeyRequest.getApplication()); + generateAppKeyRequest.setAppId(appId); HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag") , generateAppKeyRequest.generateRequestParameters() @@ -483,4 +489,24 @@ public HttpResponse getRecentlyAddedAPIs(String tenant, String limit) } } + + private String getApplicationId(String jsonStringOfApplications, String applicationName) throws Exception{ + String applicationId=null; + JSONObject obj; + try { + obj = new JSONObject(jsonStringOfApplications); + JSONArray arr = obj.getJSONArray("applications"); + for (int i = 0; i < arr.length(); i++) + { + String appName = arr.getJSONObject(i).getString("name"); + if(applicationName.equals(appName)){ + applicationId = arr.getJSONObject(i).getString("id"); + } + } + } catch (JSONException e) { + throw new Exception("getting application Id failed "); + } + return applicationId; + + } } diff --git a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/store/utils/APIStoreRestClient.java b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/store/utils/APIStoreRestClient.java index 34824443c2..11de65fd80 100644 --- a/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/store/utils/APIStoreRestClient.java +++ b/modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/am/integration/test/utils/store/utils/APIStoreRestClient.java @@ -19,6 +19,9 @@ package org.wso2.am.integration.test.utils.store.utils; import org.apache.commons.codec.binary.Base64; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import org.wso2.am.integration.test.utils.VerificationUtil; import org.wso2.am.integration.test.utils.bean.GenerateAppKeyRequest; import org.wso2.am.integration.test.utils.bean.SubscriptionRequest; @@ -76,9 +79,11 @@ public HttpResponse subscribe(SubscriptionRequest subscriptionRequest) public HttpResponse generateApplicationKey(GenerateAppKeyRequest generateAppKeyRequest) throws Exception { checkAuthentication(); + HttpResponse response1=getAllApplications(); + String appId = getApplicationId(response1.getData(), generateAppKeyRequest.getApplication()); HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag?"+ "action=generateApplicationKey&application="+ generateAppKeyRequest.getApplication() + - "&keytype=" + generateAppKeyRequest.getKeyType() + "&callbackUrl=&authorizedDomains=ALL&validityTime=360000"), + "&keytype=" + generateAppKeyRequest.getKeyType() + "&callbackUrl=&authorizedDomains=ALL&validityTime=360000&selectedAppID=" +appId), "", requestHeaders); if (response.getResponseCode() == 200) { @@ -445,4 +450,24 @@ public HttpResponse removeAPISubscription(String API, String version, String pro } } + + private String getApplicationId(String jsonStringOfApplications, String applicationName) throws Exception{ + String applicationId=null; + JSONObject obj; + try { + obj = new JSONObject(jsonStringOfApplications); + JSONArray arr = obj.getJSONArray("applications"); + for (int i = 0; i < arr.length(); i++) + { + String appName = arr.getJSONObject(i).getString("name"); + if(applicationName.equals(appName)){ + applicationId = arr.getJSONObject(i).getString("id"); + } + } + } catch (JSONException e) { + throw new Exception("getting application Id failed "); + } + return applicationId; + + } } diff --git a/modules/integration/tests/src/test/java/org/wso2/carbon/am/tests/util/APIStoreRestClient.java b/modules/integration/tests/src/test/java/org/wso2/carbon/am/tests/util/APIStoreRestClient.java index 947d58148c..fa3b88da4b 100644 --- a/modules/integration/tests/src/test/java/org/wso2/carbon/am/tests/util/APIStoreRestClient.java +++ b/modules/integration/tests/src/test/java/org/wso2/carbon/am/tests/util/APIStoreRestClient.java @@ -75,9 +75,10 @@ public HttpResponse subscribe(SubscriptionRequest subscriptionRequest) public HttpResponse generateApplicationKey(GenerateAppKeyRequest generateAppKeyRequest) throws Exception { checkAuthentication(); + HttpResponse response1=HttpRequestUtil.getAllApplications(); HttpResponse response = HttpRequestUtil.doPost(new URL(backEndUrl + "/store/site/blocks/subscription/subscription-add/ajax/subscription-add.jag?"+ "action=generateApplicationKey&application="+ generateAppKeyRequest.getApplication() + - "&keytype=" + generateAppKeyRequest.getKeyType() + "&callbackUrl=&authorizedDomains=ALL&validityTime=360000"), + "&keytype=" + generateAppKeyRequest.getKeyType() + "&callbackUrl=&authorizedDomains=ALL&validityTime=360000&selectedAppID=1"), "", requestHeaders); if (response.getResponseCode() == 200) {