Program: 114819
Project: 114819
Buggy source:
@Test(groups={"String_Node_Str"},description="String_Node_Str") public void testTokenAPITestCase() throws Exception {
  String APIName="String_Node_Str";
  String APIContext="String_Node_Str";
  String tags="String_Node_Str";
  String url=getGatewayURLHttp() + "String_Node_Str";
  String description="String_Node_Str";
  String providerName=publisherContext.getContextTenant().getContextUser().getUserName();
  String APIVersion="String_Node_Str";
  APIRequest apiRequest=new APIRequest(APIName,APIContext,new URL(url),new URL(url));
  apiRequest.setTags(tags);
  apiRequest.setDescription(description);
  apiRequest.setVersion(APIVersion);
  apiRequest.setSandbox(url);
  apiRequest.setProvider(user.getUserName());
  apiPublisher.addAPI(apiRequest);
  APILifeCycleStateRequest updateRequest=new APILifeCycleStateRequest(APIName,providerName,APILifeCycleState.PUBLISHED);
  apiPublisher.changeAPILifeCycleStatus(updateRequest);
  String gatewayUrl=getAPIInvocationURLHttp("String_Node_Str");
  apiStore.addApplication("String_Node_Str",APIMIntegrationConstants.APPLICATION_TIER.UNLIMITED,"String_Node_Str","String_Node_Str");
  String provider=storeContext.getContextTenant().getContextUser().getUserName();
  SubscriptionRequest subscriptionRequest=new SubscriptionRequest(APIName,provider);
  subscriptionRequest.setTier(APIMIntegrationConstants.API_TIER.GOLD);
  subscriptionRequest.setApplicationName("String_Node_Str");
  apiStore.subscribe(subscriptionRequest);
  APPKeyRequestGenerator generateAppKeyRequestSandBox=new APPKeyRequestGenerator("String_Node_Str");
  generateAppKeyRequestSandBox.setKeyType("String_Node_Str");
  String responseStringSandBox=apiStore.generateApplicationKey(generateAppKeyRequestSandBox).getData();
  JSONObject responseSandBOX=new JSONObject(responseStringSandBox);
  String SANDbOXAccessToken=responseSandBOX.getJSONObject("String_Node_Str").getJSONObject("String_Node_Str").get("String_Node_Str").toString();
  Map<String,String> requestHeadersSandBox=new HashMap<String,String>();
  requestHeadersSandBox.put("String_Node_Str","String_Node_Str" + SANDbOXAccessToken);
  HttpResponse youTubeResponseSandBox=HttpRequestUtil.doGet(gatewayUrl,requestHeadersSandBox);
  log.info("String_Node_Str" + youTubeResponseSandBox);
  APPKeyRequestGenerator generateAppKeyRequest=new APPKeyRequestGenerator("String_Node_Str");
  String responseString=apiStore.generateApplicationKey(generateAppKeyRequest).getData();
  JSONObject response=new JSONObject(responseString);
  String accessToken=response.getJSONObject("String_Node_Str").getJSONObject("String_Node_Str").get("String_Node_Str").toString();
  String consumerKey=response.getJSONObject("String_Node_Str").getJSONObject("String_Node_Str").getString("String_Node_Str");
  String consumerSecret=response.getJSONObject("String_Node_Str").getJSONObject("String_Node_Str").getString("String_Node_Str");
  Thread.sleep(2000);
  String requestBody="String_Node_Str";
  URL tokenEndpointURL=new URL(getGatewayURLNhttp() + "String_Node_Str");
  JSONObject accessTokenGenerationResponse=new JSONObject(apiStore.generateUserAccessKey(consumerKey,consumerSecret,requestBody,tokenEndpointURL).getData());
  String userAccessToken=accessTokenGenerationResponse.getString("String_Node_Str");
  String refreshToken=accessTokenGenerationResponse.getString("String_Node_Str");
  log.info(refreshToken);
  Map<String,String> requestHeaders=new HashMap<String,String>();
  requestHeaders.put("String_Node_Str","String_Node_Str" + userAccessToken);
  requestHeaders.put("String_Node_Str","String_Node_Str");
  Thread.sleep(2000);
  HttpResponse youTubeResponse=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  assertEquals(youTubeResponse.getResponseCode(),Response.Status.OK.getStatusCode(),"String_Node_Str");
  assertTrue(youTubeResponse.getData().contains("String_Node_Str"),"String_Node_Str");
  assertTrue(youTubeResponse.getData().contains("String_Node_Str"),"String_Node_Str");
  assertTrue(youTubeResponse.getData().contains("String_Node_Str"),"String_Node_Str");
  requestHeaders.clear();
  requestHeaders.put("String_Node_Str","String_Node_Str" + accessToken);
  requestHeaders.put("String_Node_Str","String_Node_Str");
  HttpResponse youTubeResponseWithApplicationToken=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  assertEquals(youTubeResponseWithApplicationToken.getResponseCode(),Response.Status.OK.getStatusCode(),"String_Node_Str");
  assertTrue(youTubeResponseWithApplicationToken.getData().contains("String_Node_Str"),"String_Node_Str");
  assertTrue(youTubeResponseWithApplicationToken.getData().contains("String_Node_Str"),"String_Node_Str");
  assertTrue(youTubeResponseWithApplicationToken.getData().contains("String_Node_Str"),"String_Node_Str");
  HttpResponse youTubeResponseWithApplicationTokenHttps=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  log.info("String_Node_Str" + youTubeResponseWithApplicationTokenHttps);
  assertEquals(youTubeResponseWithApplicationTokenHttps.getResponseCode(),200,"String_Node_Str");
  HttpResponse errorResponse=null;
  errorResponse=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  log.info("String_Node_Str" + errorResponse);
  apiPublisher.revokeAccessToken(accessToken,consumerKey,providerName);
  requestHeaders.clear();
  requestHeaders.put("String_Node_Str","String_Node_Str" + "String_Node_Str");
  requestHeaders.put("String_Node_Str","String_Node_Str");
  errorResponse=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  assertEquals(errorResponse.getResponseCode(),401,"String_Node_Str");
  try {
    errorResponse=HttpRequestUtil.doGet(getAPIInvocationURLHttp("String_Node_Str"),requestHeaders);
    log.info("String_Node_Str" + errorResponse);
  }
 catch (  Exception e) {
  }
  assertEquals(errorResponse.getResponseCode(),401,"String_Node_Str");
}

Fixed version (ground truth):
@Test(groups={"String_Node_Str"},description="String_Node_Str") public void testTokenAPITestCase() throws Exception {
  String APIName="String_Node_Str";
  String APIContext="String_Node_Str";
  String tags="String_Node_Str";
  String url=getGatewayURLHttp() + "String_Node_Str";
  String description="String_Node_Str";
  String providerName=publisherContext.getContextTenant().getContextUser().getUserName();
  String APIVersion="String_Node_Str";
  APIRequest apiRequest=new APIRequest(APIName,APIContext,new URL(url),new URL(url));
  apiRequest.setTags(tags);
  apiRequest.setDescription(description);
  apiRequest.setVersion(APIVersion);
  apiRequest.setSandbox(url);
  apiRequest.setProvider(user.getUserName());
  apiPublisher.addAPI(apiRequest);
  APILifeCycleStateRequest updateRequest=new APILifeCycleStateRequest(APIName,providerName,APILifeCycleState.PUBLISHED);
  apiPublisher.changeAPILifeCycleStatus(updateRequest);
  String gatewayUrl=getAPIInvocationURLHttp("String_Node_Str");
  apiStore.addApplication("String_Node_Str",APIMIntegrationConstants.APPLICATION_TIER.UNLIMITED,"String_Node_Str","String_Node_Str");
  String provider=storeContext.getContextTenant().getContextUser().getUserName();
  SubscriptionRequest subscriptionRequest=new SubscriptionRequest(APIName,provider);
  subscriptionRequest.setTier(APIMIntegrationConstants.API_TIER.GOLD);
  subscriptionRequest.setApplicationName("String_Node_Str");
  apiStore.subscribe(subscriptionRequest);
  APPKeyRequestGenerator generateAppKeyRequestSandBox=new APPKeyRequestGenerator("String_Node_Str");
  generateAppKeyRequestSandBox.setKeyType("String_Node_Str");
  String responseStringSandBox=apiStore.generateApplicationKey(generateAppKeyRequestSandBox).getData();
  JSONObject responseSandBOX=new JSONObject(responseStringSandBox);
  String SANDbOXAccessToken=responseSandBOX.getJSONObject("String_Node_Str").getJSONObject("String_Node_Str").get("String_Node_Str").toString();
  Map<String,String> requestHeadersSandBox=new HashMap<String,String>();
  requestHeadersSandBox.put("String_Node_Str","String_Node_Str" + SANDbOXAccessToken);
  HttpResponse youTubeResponseSandBox=HttpRequestUtil.doGet(gatewayUrl,requestHeadersSandBox);
  log.info("String_Node_Str" + youTubeResponseSandBox);
  APPKeyRequestGenerator generateAppKeyRequest=new APPKeyRequestGenerator("String_Node_Str");
  String responseString=apiStore.generateApplicationKey(generateAppKeyRequest).getData();
  JSONObject response=new JSONObject(responseString);
  String accessToken=response.getJSONObject("String_Node_Str").getJSONObject("String_Node_Str").get("String_Node_Str").toString();
  String consumerKey=response.getJSONObject("String_Node_Str").getJSONObject("String_Node_Str").getString("String_Node_Str");
  String consumerSecret=response.getJSONObject("String_Node_Str").getJSONObject("String_Node_Str").getString("String_Node_Str");
  Thread.sleep(2000);
  String requestBody="String_Node_Str" + user.getUserName() + "String_Node_Str";
  URL tokenEndpointURL=new URL(getGatewayURLNhttp() + "String_Node_Str" + user.getUserDomain());
  JSONObject accessTokenGenerationResponse=new JSONObject(apiStore.generateUserAccessKey(consumerKey,consumerSecret,requestBody,tokenEndpointURL).getData());
  String userAccessToken=accessTokenGenerationResponse.getString("String_Node_Str");
  String refreshToken=accessTokenGenerationResponse.getString("String_Node_Str");
  log.info(refreshToken);
  Map<String,String> requestHeaders=new HashMap<String,String>();
  requestHeaders.put("String_Node_Str","String_Node_Str" + userAccessToken);
  requestHeaders.put("String_Node_Str","String_Node_Str");
  Thread.sleep(2000);
  HttpResponse youTubeResponse=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  assertEquals(youTubeResponse.getResponseCode(),Response.Status.OK.getStatusCode(),"String_Node_Str");
  assertTrue(youTubeResponse.getData().contains("String_Node_Str"),"String_Node_Str");
  assertTrue(youTubeResponse.getData().contains("String_Node_Str"),"String_Node_Str");
  assertTrue(youTubeResponse.getData().contains("String_Node_Str"),"String_Node_Str");
  requestHeaders.clear();
  requestHeaders.put("String_Node_Str","String_Node_Str" + accessToken);
  requestHeaders.put("String_Node_Str","String_Node_Str");
  HttpResponse youTubeResponseWithApplicationToken=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  assertEquals(youTubeResponseWithApplicationToken.getResponseCode(),Response.Status.OK.getStatusCode(),"String_Node_Str");
  assertTrue(youTubeResponseWithApplicationToken.getData().contains("String_Node_Str"),"String_Node_Str");
  assertTrue(youTubeResponseWithApplicationToken.getData().contains("String_Node_Str"),"String_Node_Str");
  assertTrue(youTubeResponseWithApplicationToken.getData().contains("String_Node_Str"),"String_Node_Str");
  HttpResponse youTubeResponseWithApplicationTokenHttps=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  log.info("String_Node_Str" + youTubeResponseWithApplicationTokenHttps);
  assertEquals(youTubeResponseWithApplicationTokenHttps.getResponseCode(),200,"String_Node_Str");
  HttpResponse errorResponse=null;
  errorResponse=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  log.info("String_Node_Str" + errorResponse);
  apiPublisher.revokeAccessToken(accessToken,consumerKey,providerName);
  requestHeaders.clear();
  requestHeaders.put("String_Node_Str","String_Node_Str" + "String_Node_Str");
  requestHeaders.put("String_Node_Str","String_Node_Str");
  errorResponse=HttpRequestUtil.doGet(gatewayUrl,requestHeaders);
  assertEquals(errorResponse.getResponseCode(),401,"String_Node_Str");
  try {
    errorResponse=HttpRequestUtil.doGet(getAPIInvocationURLHttp("String_Node_Str"),requestHeaders);
    log.info("String_Node_Str" + errorResponse);
  }
 catch (  Exception e) {
  }
  assertEquals(errorResponse.getResponseCode(),401,"String_Node_Str");
}