예제 #1
0
  @Test(
      groups = {"wso2.am"},
      description = "API Life cycle test case")
  public void testDAOTestCase() throws Exception {
    String APIName = "DAOTestAPI";
    String APIContext = "DAOTestAPI";
    String tags = "youtube, video, media";
    String url = "http://gdata.youtube.com/feeds/api/standardfeeds";
    String description = "This is test API create by API manager integration test";

    String APIVersion = "1.0.0";
    String apiContextAddedValue = APIContext + "/" + APIVersion;

    APIRequest apiRequest = new APIRequest(APIName, APIContext, new URL(url));
    apiRequest.setTags(tags);
    apiRequest.setDescription(description);
    apiRequest.setVersion(APIVersion);
    apiRequest.setProvider(providerName);
    apiPublisher.addAPI(apiRequest);
    apiPublisher.deleteAPI(APIName, APIVersion, providerName);
    apiPublisher.addAPI(apiRequest);
    APIBean apiBean =
        APIMTestCaseUtils.getAPIBeanFromHttpResponse(apiPublisher.getAPI(APIName, providerName));
    APILifeCycleStateRequest updateRequest =
        new APILifeCycleStateRequest(APIName, providerName, APILifeCycleState.PUBLISHED);
    apiPublisher.changeAPILifeCycleStatus(updateRequest);
    // Test API properties
    assertEquals(apiBean.getId().getApiName(), APIName, "API Name mismatch");
    assertTrue(apiBean.getContext().contains(apiContextAddedValue), "API context mismatch");
    assertEquals(apiBean.getId().getVersion(), APIVersion, "API version mismatch");
    assertEquals(apiBean.getId().getProviderName(), providerName, "Provider Name mismatch");
    for (String tag : apiBean.getTags()) {
      assertTrue(tags.contains(tag), "API tag data mismatched");
    }
    assertEquals(apiBean.getDescription(), description, "API description mismatch");

    apiStore.addApplication("DAOTestAPI-Application", "Gold", "", "this-is-test");
    SubscriptionRequest subscriptionRequest =
        new SubscriptionRequest(
            APIName, storeContext.getContextTenant().getContextUser().getUserName());
    subscriptionRequest.setApplicationName("DAOTestAPI-Application");
    apiStore.subscribe(subscriptionRequest);

    APPKeyRequestGenerator generateAppKeyRequest =
        new APPKeyRequestGenerator("DAOTestAPI-Application");
    String responseString = apiStore.generateApplicationKey(generateAppKeyRequest).getData();
    JSONObject response = new JSONObject(responseString);
    String accessToken =
        response.getJSONObject("data").getJSONObject("key").get("accessToken").toString();
    Map<String, String> requestHeaders = new HashMap<String, String>();
    requestHeaders.put("Authorization", "Bearer " + accessToken);
    Thread.sleep(2000);
  }
예제 #2
0
  @BeforeClass(alwaysRun = true)
  public void setEnvironment() throws Exception {
    super.init(userMode);
    apiPublisher = new APIPublisherRestClient(getPublisherURLHttp());
    apiStore = new APIStoreRestClient(getStoreURLHttp());
    providerName = user.getUserName();

    apiPublisher.login(user.getUserName(), user.getPassword());

    apiStore.login(user.getUserName(), user.getPassword());
  }
  @BeforeClass(alwaysRun = true)
  public void initialize()
      throws APIManagerIntegrationTestException, XPathExpressionException, RemoteException,
          ResourceAdminServiceExceptionException, MalformedURLException {
    super.init();
    apiEndPointUrl = getGatewayURLHttp() + API_END_POINT_POSTFIX_URL;
    providerName = user.getUserName();
    apiCreationRequestBean =
        new APICreationRequestBean(
            API_NAME, API_CONTEXT, API_VERSION_1_0_0, providerName, new URL(apiEndPointUrl));
    apiCreationRequestBean.setTags(API_TAGS);
    apiCreationRequestBean.setDescription(API_DESCRIPTION);
    String publisherURLHttp = getPublisherURLHttp();
    String storeURLHttp = getStoreURLHttp();
    apiPublisherClientUser1 = new APIPublisherRestClient(publisherURLHttp);
    APIStoreRestClient apiStoreClientUser1 = new APIStoreRestClient(storeURLHttp);

    // Login to API Publisher with  admin
    apiPublisherClientUser1.login(user.getUserName(), user.getPassword());

    // Login to API Store with  admin
    apiStoreClientUser1.login(user.getUserName(), user.getPassword());

    apiIdentifier = new APIIdentifier(providerName, API_NAME, API_VERSION_1_0_0);
    String artifactsLocation =
        TestConfigurationProvider.getResourceLocation()
            + File.separator
            + "artifacts"
            + File.separator
            + "AM"
            + File.separator
            + "lifecycletest"
            + File.separator
            + "tiers.xml";
    resourceAdminServiceClient =
        new ResourceAdminServiceClient(
            publisherContext.getContextUrls().getBackEndUrl(), createSession(publisherContext));
    originalTiersXML = resourceAdminServiceClient.getTextContent(TIER_XML_REG_CONFIG_LOCATION);
    newTiersXML = readFile(artifactsLocation);
  }
 @BeforeClass(alwaysRun = true)
 public void initialize()
     throws APIManagerIntegrationTestException, XPathExpressionException, MalformedURLException {
   super.init();
   api1EndPointUrl = getGatewayURLHttp() + API_END_POINT_POSTFIX_URL;
   providerName = user.getUserName();
   apiCreationRequestBean =
       new APICreationRequestBean(
           API_NAME, API_CONTEXT, API_VERSION_1_0_0, providerName, new URL(api1EndPointUrl));
   apiCreationRequestBean.setTags(API_TAGS);
   apiCreationRequestBean.setDescription(API_DESCRIPTION);
   String publisherURLHttp = getPublisherURLHttp();
   String storeURLHttp = getStoreURLHttp();
   apiPublisherClientUser1 = new APIPublisherRestClient(publisherURLHttp);
   apiStoreClientUser1 = new APIStoreRestClient(storeURLHttp);
   // Login to API Publisher with  admin
   apiPublisherClientUser1.login(user.getUserName(), user.getPassword());
   // Login to API Store with  admin
   apiStoreClientUser1.login(user.getUserName(), user.getPassword());
   apiIdentifier = new APIIdentifier(providerName, API_NAME, API_VERSION_1_0_0);
   apiStoreClientUser1.addApplication(APPLICATION_NAME, TIER_UNLIMITED, "", "");
 }
  @BeforeClass(alwaysRun = true)
  public void initialize()
      throws APIManagerIntegrationTestException, XPathExpressionException, RemoteException {
    super.init();
    apiEndPointUrl = getGatewayURLHttp() + API_END_POINT_POSTFIX_URL;
    providerName = user.getUserName();
    String publisherURLHttp = getPublisherURLHttp();
    String storeURLHttp = getStoreURLHttp();
    apiPublisherClientUser1 = new APIPublisherRestClient(publisherURLHttp);
    apiStoreClientUser1 = new APIStoreRestClient(storeURLHttp);

    // Login to API Publisher with  admin
    apiPublisherClientUser1.login(user.getUserName(), user.getPassword());

    // Login to API Store with  admin
    apiStoreClientUser1.login(user.getUserName(), user.getPassword());
    requestHeadersGet = new HashMap<String, String>();
    requestHeadersGet.put("accept", "text/plain");
    requestHeadersGet.put("Content-Type", "text/plain");
    apiIdentifier = new APIIdentifier(providerName, API_NAME, API_VERSION_1_0_0);
    // Create application
    apiStoreClientUser1.addApplication(
        APPLICATION_NAME, APIMIntegrationConstants.APPLICATION_TIER.UNLIMITED, "", "");
  }
  @BeforeClass(alwaysRun = true)
  public void setEnvironment() throws Exception {
    super.init();
    String publisherURLHttp = publisherUrls.getWebAppURLHttp();
    String storeURLHttp = storeUrls.getWebAppURLHttp();

    apiStore = new APIStoreRestClient(storeURLHttp);
    apiPublisher = new APIPublisherRestClient(publisherURLHttp);

    apiPublisher.login(
        publisherContext.getContextTenant().getContextUser().getUserName(),
        publisherContext.getContextTenant().getContextUser().getPassword());
    apiStore.login(
        storeContext.getContextTenant().getContextUser().getUserName(),
        storeContext.getContextTenant().getContextUser().getPassword());
  }
  @Test(description = "List all Subscriptions By by calling the getAllSubscriptionsOfApplication")
  public void testGetAllSubscriptionsOfApplication() throws Exception {
    String subscriptionData = apiStore.getAllSubscriptionsOfApplication().getData();
    JSONObject jsonSubscription = new JSONObject(subscriptionData);

    int returnedSubscriptions = 0;
    if (jsonSubscription.getString("error").equals("false")) {
      JSONObject jsonSubscriptionsObject = jsonSubscription.getJSONObject("subscriptions");
      JSONArray jsonApplicationsArray = jsonSubscriptionsObject.getJSONArray("applications");

      // Remove API Subscriptions
      for (int i = 0; i < jsonApplicationsArray.length(); i++) {
        JSONObject appObject = jsonApplicationsArray.getJSONObject(i);
        String applicationName = appObject.getString("name");
        if ("DefaultApplication".equals(applicationName)) {
          // This is the default application. We have not added any subscriptions for this. Hence
          // skipping
          // this one
          continue;
        }
        JSONArray subscribedAPIJSONArray = appObject.getJSONArray("subscriptions");
        int length = subscribedAPIJSONArray.length();
        if (i == 0) {
          // We are checking the first application as the method should return that.
          // check whether the subscriptions are empty.
          assertEquals(1, length, "No subscriptions found for application : " + applicationName);
        } else {
          // If there are subscriptions for other applications returned, that is wrong
          assertEquals(0, length, "Subscriptions found for application : " + applicationName);
        }

        if (length > 0) {
          returnedSubscriptions++;
        }
        // We do not check whether the subscriptions are correct or not since that is covered from
        // the other
        // test cases. What we are interested is that, the testGetAllSubscriptionsOfApplication() is
        // returning
        // subscription details for first application. If they are found, then our test case is
        // successful.
      }
      assertEquals(
          1, returnedSubscriptions, "More than the number of expected subscriptions were returned");
    } else {
      throw new Exception("Unable to get the list of subscriptions.");
    }
  }
  @Test(
      description =
          "List all Subscriptions By by calling the getAllSubscriptionsOfApplication with application name")
  public void testGetAllSubscriptionsOfApplicationWithSelectedApp() throws Exception {
    String selectedApplication = applicationNamePrefix + 1;
    String subscriptionData =
        apiStore.getAllSubscriptionsOfApplication(selectedApplication).getData();
    JSONObject jsonSubscription = new JSONObject(subscriptionData);

    if (jsonSubscription.getString("error").equals("false")) {
      JSONObject jsonSubscriptionsObject = jsonSubscription.getJSONObject("subscriptions");
      JSONArray jsonApplicationsArray = jsonSubscriptionsObject.getJSONArray("applications");

      // Remove API Subscriptions
      for (int i = 0; i < jsonApplicationsArray.length(); i++) {
        JSONObject appObject = jsonApplicationsArray.getJSONObject(i);
        String applicationName = appObject.getString("name");

        JSONArray subscribedAPIJSONArray = appObject.getJSONArray("subscriptions");
        int length = subscribedAPIJSONArray.length();
        if ("DefaultApplication".equals(applicationName)) {
          // This is the default application. We have not added any subscriptions for this. Hence
          // should be 0
          assertEquals(
              0, length, "subscriptions found for the default application : " + applicationName);
        } else if (selectedApplication.equals(applicationName)) {
          // check whether the subscriptions are empty.
          assertEquals(
              1,
              length,
              "No subscriptions found for the selected application : " + applicationName);
        } else {
          // check whether the subscriptions are empty.
          assertEquals(
              0, length, "subscriptions found for invalid application : " + applicationName);
        }
        // We do not check whether the subscriptions are correct or not since that is covered from
        // the other
        // test cases. What we are interested is that, the
        // testGetAllSubscriptionsOfApplication(selectedApplication) is returning subscription
        // details for given application. If they are found, then our test case is successful.
      }
    } else {
      throw new Exception("Unable to get the list of subscriptions.");
    }
  }
 @BeforeClass(alwaysRun = true)
 public void initialize() throws APIManagerIntegrationTestException, XPathExpressionException {
   super.init();
   apiEndPointUrl = gatewayUrls.getWebAppURLHttp() + API_END_POINT_POSTFIX_URL;
   providerName = publisherContext.getContextTenant().getContextUser().getUserName();
   String publisherURLHttp = publisherUrls.getWebAppURLHttp();
   String storeURLHttp = storeUrls.getWebAppURLHttp();
   apiPublisherClientUser1 = new APIPublisherRestClient(publisherURLHttp);
   apiStoreClientUser1 = new APIStoreRestClient(storeURLHttp);
   // Login to API Publisher with  admin
   apiPublisherClientUser1.login(
       publisherContext.getContextTenant().getContextUser().getUserName(),
       publisherContext.getContextTenant().getContextUser().getPassword());
   // Login to API Store with  admin
   apiStoreClientUser1.login(
       storeContext.getContextTenant().getContextUser().getUserName(),
       storeContext.getContextTenant().getContextUser().getPassword());
   apiIdentifier = new APIIdentifier(providerName, API_NAME, API_VERSION_1_0_0);
 }
  @Test(
      groups = {"wso2.am"},
      description = "Pizzashack Test")
  public void testPizzashackApiSample() throws Exception {

    List<APIResourceBean> resourceBeanList = new ArrayList<APIResourceBean>();

    APICreationRequestBean apiCreationRequestBean =
        new APICreationRequestBean(
            "PizzaAPI",
            "pizzashack",
            "1.0.0",
            "admin",
            new URL("http://localhost:9766/pizzashack-api-1.0.0/api/"));

    apiCreationRequestBean.setThumbUrl("/home/bhagya/WS/Pizza_Shack_Logo.jpeg");
    apiCreationRequestBean.setDescription(
        "Pizza API:Allows to manage pizza orders (create, update, retrieve orders)");
    apiCreationRequestBean.setTags("pizza, order, pizza-menu");
    apiCreationRequestBean.setResourceCount("4");

    resourceBeanList.add(
        new APIResourceBean("GET", "Application & Application User", "Unlimited", "/menu"));
    resourceBeanList.add(
        new APIResourceBean("POST", "Application & Application User", "Unlimited", "/order"));
    resourceBeanList.add(
        new APIResourceBean(
            "GET", "Application & Application User", "Unlimited", "/order/{orderid}"));
    resourceBeanList.add(
        new APIResourceBean("GET", "Application & Application User", "Unlimited", "/delivery"));
    apiCreationRequestBean.setResourceBeanList(resourceBeanList);

    apiCreationRequestBean.setTier("Unlimited");
    apiCreationRequestBean.setTiersCollection("Unlimited");

    apiPublisher.addAPI(apiCreationRequestBean);
    APILifeCycleStateRequest updateRequest =
        new APILifeCycleStateRequest(
            "PizzaAPI",
            publisherContext.getContextTenant().getContextUser().getUserName(),
            APILifeCycleState.PUBLISHED);
    apiPublisher.changeAPILifeCycleStatus(updateRequest);
    apiStore.addApplication("PizzaShack", "Unlimited", "", "");
    SubscriptionRequest subscriptionRequest =
        new SubscriptionRequest(
            "PizzaAPI", storeContext.getContextTenant().getContextUser().getUserName());
    subscriptionRequest.setApplicationName("PizzaShack");
    apiStore.subscribe(subscriptionRequest);

    APPKeyRequestGenerator generateAppKeyRequest = new APPKeyRequestGenerator("PizzaShack");
    String responseString = apiStore.generateApplicationKey(generateAppKeyRequest).getData();
    JSONObject response = new JSONObject(responseString);
    String accessToken =
        response.getJSONObject("data").getJSONObject("key").get("accessToken").toString();
    Map<String, String> requestHeaders = new HashMap<String, String>();
    requestHeaders.put("Authorization", "Bearer " + accessToken);

    Thread.sleep(2000);

    HttpResponse pizzaShackResponse =
        HttpRequestUtil.doGet(
            gatewayUrlsMgt.getWebAppURLNhttp() + "pizzashack/1.0.0/menu", requestHeaders);
    assertEquals(
        pizzaShackResponse.getResponseCode(),
        Response.Status.OK.getStatusCode(),
        "Response code mismatched when api invocation");
    System.out.println("My Response Code is " + pizzaShackResponse.getResponseCode());

    assertTrue(
        pizzaShackResponse.getData().contains("BBQ Chicken Bacon"),
        "Response data mismatched when api invocation");
    assertTrue(
        pizzaShackResponse.getData().contains("Grilled white chicken"),
        "Response data mismatched when api invocation");
    assertTrue(
        pizzaShackResponse.getData().contains("Chicken Parmesan"),
        "Response data mismatched when api invocation");
    assertTrue(
        pizzaShackResponse.getData().contains("Tuscan Six Cheese"),
        "Response data mismatched when api invocation");
    assertTrue(
        pizzaShackResponse.getData().contains("Asiago and Fontina"),
        "Response data mismatched when api invocation");
  }
  @BeforeClass(alwaysRun = true)
  public void setEnvironment() throws Exception {
    super.init(userMode);
    // Load the back-end dummy API
    if (TestUserMode.SUPER_TENANT_ADMIN == userMode) {
      String gatewaySessionCookie = createSession(gatewayContextMgt);
      loadSynapseConfigurationFromClasspath(
          "artifacts"
              + File.separator
              + "AM"
              + File.separator
              + "synapseconfigs"
              + File.separator
              + "rest"
              + File.separator
              + "dummy_api.xml",
          gatewayContextMgt,
          gatewaySessionCookie);
    }
    publisherURLHttp = getPublisherURLHttp();
    apiPublisher = new APIPublisherRestClient(publisherURLHttp);
    apiPublisher.login(user.getUserName(), user.getPassword());

    String providerName = user.getUserName();
    URL endpointUrl = new URL(getSuperTenantAPIInvocationURLHttp("response", "1.0.0"));
    ArrayList<APIResourceBean> resourceBeanList = new ArrayList<APIResourceBean>();
    resourceBeanList.add(
        new APIResourceBean(
            APIMIntegrationConstants.HTTP_VERB_GET,
            APIMIntegrationConstants.RESOURCE_AUTH_TYPE_APPLICATION_AND_APPLICATION_USER,
            APIMIntegrationConstants.RESOURCE_TIER.UNLIMITED,
            "/*"));
    apiCreationRequestBean =
        new APICreationRequestBean(
            API_NAME, API_CONTEXT, API_VERSION, providerName, endpointUrl, resourceBeanList);
    apiCreationRequestBean.setTags(TAGS);
    apiCreationRequestBean.setDescription(DESCRIPTION);
    String publisherURLHttp = getPublisherURLHttp();
    String storeURLHttp = getStoreURLHttp();
    apiPublisherClientUser1 = new APIPublisherRestClient(publisherURLHttp);
    apiStoreClientUser1 = new APIStoreRestClient(storeURLHttp);
    // Login to API Publisher with admin
    apiPublisherClientUser1.login(user.getUserName(), user.getPassword());
    // Login to API Store with  admin
    apiStoreClientUser1.login(user.getUserName(), user.getPassword());
    apiIdentifier = new APIIdentifier(providerName, API_NAME, API_VERSION);
    apiIdentifier.setTier(APIMIntegrationConstants.API_TIER.GOLD);
    // Create application
    apiStoreClientUser1.addApplication(
        APPLICATION_NAME, APIMIntegrationConstants.APPLICATION_TIER.LARGE, "", "");
    accessToken = generateApplicationKeys(apiStoreClientUser1, APPLICATION_NAME).getAccessToken();

    createPublishAndSubscribeToAPI(
        apiIdentifier,
        apiCreationRequestBean,
        apiPublisherClientUser1,
        apiStoreClientUser1,
        APPLICATION_NAME);
    waitForAPIDeploymentSync(
        user.getUserName(), API_NAME, API_VERSION, APIMIntegrationConstants.IS_API_EXISTS);
  }
 @AfterClass(alwaysRun = true)
 public void cleanUpArtifacts()
     throws APIManagerIntegrationTestException, XPathExpressionException {
   apiStoreClientUser1.removeApplication(APPLICATION_NAME);
   deleteAPI(apiIdentifier, apiPublisherClientUser1);
 }
 @Test(
     groups = {"wso2.am"},
     description = "test  invocation of  api under tier Silver.",
     dependsOnMethods = "testEditAPITierToSilver")
 public void testInvokingWithSilverTier()
     throws APIManagerIntegrationTestException, InterruptedException, IOException {
   applicationNameSilver = APPLICATION_NAME + TIER_SILVER;
   // create new application
   apiStoreClientUser1.addApplication(applicationNameSilver, TIER_GOLD, "", "");
   apiIdentifier.setTier(TIER_SILVER);
   // Do a API Silver subscription.
   subscribeToAPI(apiIdentifier, applicationNameSilver, apiStoreClientUser1);
   // get access token
   String accessToken =
       generateApplicationKeys(apiStoreClientUser1, applicationNameSilver).getAccessToken();
   // Create requestHeaders
   Map<String, String> requestHeadersSilverTier = new HashMap<String, String>();
   requestHeadersSilverTier.put("accept", "text/xml");
   requestHeadersSilverTier.put("Authorization", "Bearer " + accessToken);
   // millisecond to expire the throttling block
   Thread.sleep(THROTTLING_UNIT_TIME + THROTTLING_ADDITIONAL_WAIT_TIME);
   long startTime = System.currentTimeMillis();
   long currentTime;
   for (int invocationCount = 1;
       invocationCount <= SILVER_INVOCATION_LIMIT_PER_MIN;
       invocationCount++) {
     currentTime = System.currentTimeMillis();
     // Invoke  API
     HttpResponse invokeResponse =
         HttpRequestUtil.doGet(
             gatewayWebAppUrl + API_CONTEXT + "/" + API_VERSION_1_0_0 + API_END_POINT_METHOD,
             requestHeadersSilverTier);
     assertEquals(
         invokeResponse.getResponseCode(),
         HTTP_RESPONSE_CODE_OK,
         "Response code mismatched. "
             + "Invocation attempt:"
             + invocationCount
             + " failed  during :"
             + (currentTime - startTime)
             + " milliseconds under Silver API level tier");
     assertTrue(
         invokeResponse.getData().contains(API_RESPONSE_DATA),
         "Response data mismatched."
             + " Invocation attempt:"
             + invocationCount
             + " failed  during :"
             + (currentTime - startTime)
             + " milliseconds under Silver API level tier");
   }
   currentTime = System.currentTimeMillis();
   HttpResponse invokeResponse =
       HttpRequestUtil.doGet(
           gatewayWebAppUrl + API_CONTEXT + "/" + API_VERSION_1_0_0 + API_END_POINT_METHOD,
           requestHeadersSilverTier);
   assertEquals(
       invokeResponse.getResponseCode(),
       HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE,
       "Response code mismatched. Invocation attempt:"
           + (SILVER_INVOCATION_LIMIT_PER_MIN + 1)
           + " passed  during :"
           + (currentTime - startTime)
           + " milliseconds under Silver API level tier");
   assertTrue(
       invokeResponse.getData().contains(MESSAGE_THROTTLED_OUT),
       "Response data mismatched. Invocation attempt:"
           + (SILVER_INVOCATION_LIMIT_PER_MIN + 1)
           + " passed  during :"
           + (currentTime - startTime)
           + " milliseconds under Silver API level tier");
 }
예제 #14
0
 @AfterClass(alwaysRun = true)
 public void destroy() throws Exception {
   apiStore.removeApplication("DAOTestAPI-Application");
 }
 @AfterClass(alwaysRun = true)
 public void cleanUpArtifacts() throws APIManagerIntegrationTestException {
   apiStoreClientUser1.removeApplication(applicationNameGold);
   apiStoreClientUser1.removeApplication(applicationNameSilver);
   deleteAPI(apiIdentifier, apiPublisherClientUser1);
 }
  @Test(
      groups = {"wso2.am"},
      description = "test  invocation of  api under tier Gold.")
  public void testInvokingWithGoldTier() throws APIManagerIntegrationTestException, IOException {

    applicationNameGold = APPLICATION_NAME + TIER_GOLD;
    apiStoreClientUser1.addApplication(applicationNameGold, TIER_GOLD, "", "");
    apiCreationRequestBean =
        new APICreationRequestBean(
            API_NAME, API_CONTEXT, API_VERSION_1_0_0, providerName, new URL(apiEndPointUrl));
    apiCreationRequestBean.setTags(API_TAGS);
    apiCreationRequestBean.setDescription(API_DESCRIPTION);
    apiCreationRequestBean.setTier(TIER_GOLD);
    createPublishAndSubscribeToAPI(
        apiIdentifier,
        apiCreationRequestBean,
        apiPublisherClientUser1,
        apiStoreClientUser1,
        applicationNameGold);

    // get access token
    String accessToken =
        generateApplicationKeys(apiStoreClientUser1, applicationNameGold).getAccessToken();

    // Create requestHeaders
    requestHeadersGoldTier = new HashMap<String, String>();
    requestHeadersGoldTier.put("Authorization", "Bearer " + accessToken);
    requestHeadersGoldTier.put("accept", "text/xml");
    long startTime = System.currentTimeMillis();
    long currentTime;
    for (int invocationCount = 1;
        invocationCount <= GOLD_INVOCATION_LIMIT_PER_MIN;
        invocationCount++) {
      currentTime = System.currentTimeMillis();
      // Invoke  API
      HttpResponse invokeResponse =
          HttpRequestUtil.doGet(
              gatewayWebAppUrl + API_CONTEXT + "/" + API_VERSION_1_0_0 + API_END_POINT_METHOD,
              requestHeadersGoldTier);
      assertEquals(
          invokeResponse.getResponseCode(),
          HTTP_RESPONSE_CODE_OK,
          "Response code mismatched. Invocation attempt:"
              + invocationCount
              + " failed  during :"
              + (currentTime - startTime)
              + " milliseconds under Gold API level tier");
      assertTrue(
          invokeResponse.getData().contains(API_RESPONSE_DATA),
          "Response data mismatched. Invocation attempt:"
              + invocationCount
              + " failed  during :"
              + (currentTime - startTime)
              + " milliseconds under Gold API level tier");
    }
    currentTime = System.currentTimeMillis();
    HttpResponse invokeResponse =
        HttpRequestUtil.doGet(
            gatewayWebAppUrl + API_CONTEXT + "/" + API_VERSION_1_0_0 + API_END_POINT_METHOD,
            requestHeadersGoldTier);
    assertEquals(
        invokeResponse.getResponseCode(),
        HTTP_RESPONSE_CODE_SERVICE_UNAVAILABLE,
        "Response code mismatched. Invocation attempt:"
            + (GOLD_INVOCATION_LIMIT_PER_MIN + 1)
            + " passed  during :"
            + (currentTime - startTime)
            + " milliseconds under Gold API level tier");
    assertTrue(
        invokeResponse.getData().contains(MESSAGE_THROTTLED_OUT),
        "Response data mismatched. Invocation attempt:"
            + (GOLD_INVOCATION_LIMIT_PER_MIN + 1)
            + " passed  during :"
            + (currentTime - startTime)
            + " milliseconds under Gold API level tier");
  }
 @AfterClass(alwaysRun = true)
 public void destroy() throws Exception {
   apiStore.removeApplication("PizzaShack");
 }
  @BeforeClass(alwaysRun = true)
  public void setEnvironment() throws Exception {

    super.init(userMode);
    String publisherURLHttp = publisherUrls.getWebAppURLHttp();
    String storeURLHttp = storeUrls.getWebAppURLHttp();

    apiStore = new APIStoreRestClient(storeURLHttp);
    APIPublisherRestClient apiPublisher = new APIPublisherRestClient(publisherURLHttp);

    String APIName = "APIGetAllSubscriptionsTestAPI";
    String APIContext = "getAllSubscriptionsTestAPI";
    String tags = "youtube, video, media";
    String url = "http://gdata.youtube.com/feeds/api/standardfeeds";
    String description = "This is test API create by API manager integration test";
    String providerName = "admin";
    String APIVersion = "1.0.0";

    apiPublisher.login(
        publisherContext.getContextTenant().getContextUser().getUserName(),
        publisherContext.getContextTenant().getContextUser().getPassword());
    APIRequest apiRequest = new APIRequest(APIName, APIContext, new URL(url));
    apiRequest.setTags(tags);
    apiRequest.setDescription(description);
    apiRequest.setVersion(APIVersion);
    apiRequest.setVisibility("restricted");
    apiRequest.setRoles("admin");

    apiRequest.setTiersCollection(SILVER);
    apiRequest.setTier(SILVER);

    apiPublisher.addAPI(apiRequest);
    APILifeCycleStateRequest updateRequest =
        new APILifeCycleStateRequest(APIName, providerName, APILifeCycleState.PUBLISHED);
    apiPublisher.changeAPILifeCycleStatus(updateRequest);

    apiStore.login(
        storeContext.getContextTenant().getContextUser().getUserName(),
        storeContext.getContextTenant().getContextUser().getPassword());

    for (int i = 0; i < numberOfApplications; i++) {
      String applicationName = applicationNamePrefix + i;
      apiStore.addApplication(
          applicationName,
          APIMIntegrationConstants.APPLICATION_TIER.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN,
          "",
          "this-is-test");

      SubscriptionRequest subscriptionRequest =
          new SubscriptionRequest(
              APIName, storeContext.getContextTenant().getContextUser().getUserName());
      subscriptionRequest.setApplicationName(applicationName);
      subscriptionRequest.setTier(SILVER);
      apiStore.subscribe(subscriptionRequest);

      APPKeyRequestGenerator generateAppKeyRequest = new APPKeyRequestGenerator(applicationName);
      String responseString = apiStore.generateApplicationKey(generateAppKeyRequest).getData();

      JSONObject response = new JSONObject(responseString);
      String error = response.getString("error");
      if ("true".equals(error)) {
        throw new Exception("Unable to generate the tokens. Hence unable to execute the test case");
      }
    }
    Thread.sleep(60000);
  }
  @Test(groups = "wso2.am", description = "Check functionality of the default version API")
  public void testDefaultVersionAPI() throws Exception {

    // Login to the API Publisher
    apiPublisher.login(user.getUserName(), user.getPassword());

    String apiName = "DefaultVersionAPI";
    String apiVersion = "1.0.0";
    String apiContext = "defaultversion";
    String endpointUrl = getGatewayURLNhttp() + "response";

    // Create the api creation request object
    APIRequest apiRequest = new APIRequest(apiName, apiContext, new URL(endpointUrl));
    apiRequest.setDefault_version("default_version");
    apiRequest.setDefault_version_checked("default_version");
    apiRequest.setVersion(apiVersion);
    apiRequest.setTiersCollection("Unlimited");
    apiRequest.setTier("Unlimited");
    apiRequest.setProvider(provider);

    // Add the API using the API publisher.
    HttpResponse response = apiPublisher.addAPI(apiRequest);

    APILifeCycleStateRequest updateRequest =
        new APILifeCycleStateRequest(apiName, user.getUserName(), APILifeCycleState.PUBLISHED);
    // Publish the API
    response = apiPublisher.changeAPILifeCycleStatus(updateRequest);

    // Login to the API Store
    apiStore.login(user.getUserName(), user.getPassword());

    // Add an Application in the Store.
    response = apiStore.addApplication("DefaultVersionAPP", "Unlimited", "", "");
    verifyResponse(response);

    // Subscribe the API to the DefaultApplication
    SubscriptionRequest subscriptionRequest =
        new SubscriptionRequest(apiName, apiVersion, provider, "DefaultVersionAPP", "Unlimited");
    response = apiStore.subscribe(subscriptionRequest);

    // Generate production token and invoke with that
    APPKeyRequestGenerator generateAppKeyRequest = new APPKeyRequestGenerator("DefaultVersionAPP");
    String responseString = apiStore.generateApplicationKey(generateAppKeyRequest).getData();
    JSONObject jsonResponse = new JSONObject(responseString);

    // Get the accessToken which was generated.
    String accessToken =
        jsonResponse.getJSONObject("data").getJSONObject("key").getString("accessToken");

    String apiInvocationUrl = getAPIInvocationURLHttp(apiContext);

    // Going to access the API without the version in the request url.
    HttpResponse directResponse = HttpRequestUtil.doGet(endpointUrl, new HashMap<String, String>());

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Authorization", "Bearer " + accessToken);
    // Invoke the API
    HttpResponse httpResponse = HttpRequestUtil.doGet(apiInvocationUrl, headers);

    // Check if accessing the back-end directly and accessing it via the API yield the same
    // responses.
    assertEquals(
        httpResponse.getData(),
        directResponse.getData(),
        "Default version API test failed while " + "invoking the API.");
  }