コード例 #1
0
 @Test(
     groups = {"wso2.esb"},
     description = "Sending a Message Via REST to test uri template fix")
 public void testRESTURITemplate() throws Exception {
   /*
   sending parameter /view/WSO2 to match /view/{symbol} in uri-template
    */
   HttpResponse response =
       HttpRequestUtil.sendGetRequest(getApiInvocationURL("stockquote") + "/view/WSO2", null);
   Assert.assertEquals(response.getResponseCode(), 200, "Response code mismatch");
   Assert.assertTrue(response.getData().contains("WSO2"), "Response message is not as expected.");
   Assert.assertTrue(
       response.getData().contains("WSO2 Company"), "Response message is not as expected");
 }
コード例 #2
0
  @Test(
      groups = {"wso2.am"},
      description = "You Tube sample")
  public void testYouTubeApiSample() throws Exception {
    apiPublisher.login(userInfo.getUserName(), userInfo.getPassword());
    APIRequest apiRequest =
        new APIRequest(
            "YoutubeFeeds", "youtube", new URL("http://gdata.youtube.com/feeds/api/standardfeeds"));
    apiPublisher.addAPI(apiRequest);

    APILifeCycleStateRequest updateRequest =
        new APILifeCycleStateRequest(
            "YoutubeFeeds", userInfo.getUserName(), APILifeCycleState.PUBLISHED);
    apiPublisher.changeAPILifeCycleStatusTo(updateRequest);

    apiStore.login(userInfo.getUserName(), userInfo.getPassword());
    SubscriptionRequest subscriptionRequest =
        new SubscriptionRequest("YoutubeFeeds", userInfo.getUserName());
    apiStore.subscribe(subscriptionRequest);

    GenerateAppKeyRequest generateAppKeyRequest = new GenerateAppKeyRequest("DefaultApplication");
    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 youTubeResponse =
        HttpRequestUtil.doGet(
            getApiInvocationURLHttp("youtube/1.0.0/most_popular"), requestHeaders);
    Assert.assertEquals(
        youTubeResponse.getResponseCode(), 200, "Response code mismatched when api invocation");
    Assert.assertTrue(
        youTubeResponse.getData().contains("<feed"),
        "Response data mismatched when api invocation");
    Assert.assertTrue(
        youTubeResponse.getData().contains("<category"),
        "Response data mismatched when api invocation");
    Assert.assertTrue(
        youTubeResponse.getData().contains("<entry>"),
        "Response data mismatched when api invocation");
  }