Skip to content

Commit

Permalink
changes for integration tests - application and subscription sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
shaniR committed Mar 19, 2015
1 parent 8da0c89 commit 3b5a8a1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; }
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3b5a8a1

Please sign in to comment.