Java Code Examples for org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil#doGet()

The following examples show how to use org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil#doGet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ESBJAVA4721PIWithCacheTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description = "Test cache mediator with  Json response having a single element array with PI enabled")
public void testJsonResponseWithCacheMediator() throws IOException, AutomationFrameworkException {

    Map<String, String> requestHeader = new HashMap<>();
    requestHeader.put("Content-type", "application/json");

    //will not be a cache hit
    HttpRequestUtil.doGet((getApiInvocationURL("cachingEnabledApi") + "/singleElementArrayBackend"), requestHeader);

    //will be a cache hit
    HttpResponse response = HttpRequestUtil.
            doGet((getApiInvocationURL("cachingEnabledApi") + "/singleElementArrayBackend"), requestHeader);

    //check if [] are preserved in response
    Assert.assertTrue(response.getData().contains("[ \"water\" ]"),
            "Expected response was not" + " received. Got " + response.getData());
}
 
Example 2
Source File: JsonResponseWithCacheTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description = "Test cache mediator with  Json response having a single element array", enabled = false)
public void testJsonResponseWithCacheMediator() throws IOException, AutomationFrameworkException {

    Map<String, String> requestHeader = new HashMap<>();
    requestHeader.put("Content-type", "application/json");

    //will not be a cache hit
    HttpRequestUtil.doGet((getApiInvocationURL("cachingEnabledApi") + "/singleElementArrayBackend"), requestHeader);

    //will be a cache hit
    HttpResponse response = HttpRequestUtil.
            doGet((getApiInvocationURL("cachingEnabledApi") + "/singleElementArrayBackend"), requestHeader);

    //check if [] are preserved in response
    Assert.assertTrue(response.getData().contains("[ \"water\" ]"),
            "Expected response was not" + " received. Got " + response.getData());
}
 
Example 3
Source File: ESBJAVA4721PIWithCacheTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb",
      description = "Test cache mediator with  Json response having a single element array with PI enabled")
public void testJsonResponseWithCacheMediator() throws IOException, AutomationFrameworkException {

    Map<String, String> requestHeader = new HashMap<>();
    requestHeader.put("Content-type", "application/json");

    //will not be a cache hit
    HttpRequestUtil.doGet((getApiInvocationURL("cachingEnabledApi") + "/singleElementArrayBackend"), requestHeader);

    //will be a cache hit
    HttpResponse response = HttpRequestUtil.
            doGet((getApiInvocationURL("cachingEnabledApi") + "/singleElementArrayBackend"), requestHeader);

    //check if [] are preserved in response
    Assert.assertTrue(response.getData().contains("[ \"water\" ]"),
            "Expected response was not" + " received. Got " + response.getData());
}
 
Example 4
Source File: JsonResponseWithCacheTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description = "Test cache mediator with  Json response having a single element array", enabled = false)
public void testJsonResponseWithCacheMediator() throws IOException, AutomationFrameworkException {

    Map<String, String> requestHeader = new HashMap<>();
    requestHeader.put("Content-type", "application/json");

    //will not be a cache hit
    HttpRequestUtil.doGet((getApiInvocationURL("cachingEnabledApi") + "/singleElementArrayBackend"), requestHeader);

    //will be a cache hit
    HttpResponse response = HttpRequestUtil.
            doGet((getApiInvocationURL("cachingEnabledApi") + "/singleElementArrayBackend"), requestHeader);

    //check if [] are preserved in response
    Assert.assertTrue(response.getData().contains("[ \"water\" ]"), "Expected response was not"
            + " received. Got " + response.getData());
}
 
Example 5
Source File: SwaggerGenerationTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"wso2.dss"}, description = "Check swagger generation feature")
public void swaggerDataServiceWithResourcesTestCase() throws Exception {

    String serviceEndPoint = "http://localhost:8480/services/ResourcesServiceTest?swagger.json";
    HttpResponse response = HttpRequestUtil.doGet(serviceEndPoint, requestHeader);
    String responseString = response.getData();
    assertNotNull(responseString, "Failed to get the swagger response.");
    JSONObject result = new JSONObject(responseString);
    assertNotNull(result, "Response is null");
    assertTrue(result.has("paths"), "Swagger information should be available on all paths");
    String pathDetails = result.get("paths").toString();
    Assert.assertEquals(pathDetails, SWAGGER_RESPONSE, "Response mismatch");
}
 
Example 6
Source File: SwaggerGenerationTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"wso2.dss"}, description = "Check swagger generation for dataservice without resources")
public void swaggerDataServiceWithoutResourcesTestCase() throws Exception {

    String serviceEndPoint = "http://localhost:8480/services/CSVDataService?swagger.json";
    HttpResponse response = HttpRequestUtil.doGet(serviceEndPoint, requestHeader);
    String responseString = response.getData();
    assertNotNull(responseString, "Failed to get the swagger response.");
    JSONObject result = new JSONObject(responseString);
    assertNotNull(result, "Response is null");
    assertTrue(result.has("paths"), "Path section of the swagger definition is missing");
    String pathDetails = result.get("paths").toString();
    Assert.assertEquals(pathDetails, "{}", "Should not contain resource path details");
}
 
Example 7
Source File: XMLToJsonNilTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Test XML to JSON with nil='true'")
public void testXmlToJsonNil() throws Exception {

    Map<String, String> requestHeader = new HashMap<>();
    requestHeader.put("Content-Type", "text/xml");
    HttpResponse response = HttpRequestUtil.
            doGet(getApiInvocationURL("xmltoJsonNilTestAPI"), requestHeader);

    Assert.assertTrue(response.getData().contains("\"ResponseDescription\":null"),
            "Invalid XML to JSON transformation. " + response.getData());
}
 
Example 8
Source File: MessageProcessorTests.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private String getMpStatus(String mpName, int managementApiPort) throws Exception {

        Map<String, String> headers = new HashMap<>();
        headers.put("Accept", "application/json");
        String url = "https://localhost:" + managementApiPort + "/management/message-processors?name=" + mpName;
        HttpResponse response = HttpRequestUtil.doGet(url, headers);
        JSONObject jsonObject = new JSONObject(response.getData());
        return jsonObject.getString("status");
    }
 
Example 9
Source File: XMLToJsonNilTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"wso2.esb"}, description = "Test XML to JSON with nil='true'")
public void testXmlToJsonNil() throws Exception {

    Map<String, String> requestHeader = new HashMap<>();
    requestHeader.put("Content-Type", "text/xml");
    HttpResponse response = HttpRequestUtil.
            doGet(getApiInvocationURL("xmltoJsonNilTestAPI"), requestHeader);

    Assert.assertTrue(response.getData().contains("\"ResponseDescription\":null"),
            "Invalid XML to JSON transformation. " + response.getData());
}
 
Example 10
Source File: CacheResponseCodeRegexTestCase.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = "wso2.esb", description = "Verify caching works for the defined response code regex")
public void testCachingResponseCodeRegex() throws Exception {

    Map<String, String> requestHeader = new HashMap<>();
    requestHeader.put("CODE", "202");
    requestHeader.put("symbol", "RegexPattern");

    // Backend respond with 202 status code
    HttpResponse response1 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader);
    assertNotNull(response1, "Response is null");
    String[] firstmsg1 = response1.getData().split("<ax21:change>");
    String[] secondmsg1 = firstmsg1[1].split("</ax21:change>");
    String change1 = secondmsg1[0];
    assertNotNull(change1, "change value is null");
    assertEquals(response1.getResponseCode(), 202, "Unexpected response code");

    HttpResponse response2 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader);
    assertNotNull(response2, "Response is null");
    String[] firstmsg2 = response2.getData().split("<ax21:change>");
    String[] secondmsg2 = firstmsg2[1].split("</ax21:change>");
    String change2 = secondmsg2[0];
    assertNotNull(change2, "change value is null");
    assertEquals(response2.getResponseCode(), 202, "Unexpected response code");

    assertEquals(change1, change2, "Response caching did not work for the defined response code regex ");

    Map<String, String> requestHeader2 = new HashMap<>();
    requestHeader2.put("CODE", "401");
    requestHeader2.put("symbol", "RegexPattern");

    // Backend respond with 401 status code
    HttpResponse response3 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader2);
    assertNotNull(response3, "Response is null");
    String[] firstmsg3 = response3.getData().split("<ax21:change>");
    String[] secondmsg3 = firstmsg3[1].split("</ax21:change>");
    String change3 = secondmsg3[0];
    assertNotNull(change3, "change value is null");
    assertEquals(response3.getResponseCode(), 401, "Unexpected response code");

    HttpResponse response4 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader2);
    assertNotNull(response4, "Response is null");
    String[] firstmsg4 = response4.getData().split("<ax21:change>");
    String[] secondmsg4 = firstmsg4[1].split("</ax21:change>");
    String change4 = secondmsg4[0];
    assertNotNull(change4, "change value is null");
    assertEquals(response4.getResponseCode(), 401, "Unexpected response code");

    assertEquals(change3, change4, "Response caching did not work for the defined response code regex ");

    Map<String, String> requestHeader3 = new HashMap<>();
    requestHeader3.put("CODE", "500");
    requestHeader3.put("symbol", "RegexPattern");

    // Backend respond with 500 status code
    HttpResponse response5 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader3);
    assertNotNull(response5, "Response is null");
    String[] firstmsg5 = response5.getData().split("<ax21:change>");
    String[] secondmsg5 = firstmsg5[1].split("</ax21:change>");
    String change5 = secondmsg5[0];
    assertNotNull(change5, "change value is null");
    assertEquals(response5.getResponseCode(), 500, "Unexpected response code");

    HttpResponse response6 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader3);
    assertNotNull(response6, "Response is null");
    String[] firstmsg6 = response6.getData().split("<ax21:change>");
    String[] secondmsg6 = firstmsg6[1].split("</ax21:change>");
    String change6 = secondmsg6[0];
    assertNotNull(change6, "change value is null");
    assertEquals(response6.getResponseCode(), 500, "Unexpected response code");

    assertNotEquals(change5, change6, "Response caching works for the undefined response code");
}
 
Example 11
Source File: CacheResponseCodeRegexTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = "wso2.esb",
      description = "Verify caching works for the defined response code regex")
public void testCachingResponseCodeRegex() throws Exception {

    Map<String, String> requestHeader = new HashMap<>();
    requestHeader.put("CODE", "202");
    requestHeader.put("symbol", "RegexPattern");

    // Backend respond with 202 status code
    HttpResponse response1 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader);
    assertNotNull(response1, "Response is null");
    String[] firstmsg1 = response1.getData().split("<ax21:change>");
    String[] secondmsg1 = firstmsg1[1].split("</ax21:change>");
    String change1 = secondmsg1[0];
    assertNotNull(change1, "change value is null");
    assertEquals(response1.getResponseCode(), 202, "Unexpected response code");

    HttpResponse response2 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader);
    assertNotNull(response2, "Response is null");
    String[] firstmsg2 = response2.getData().split("<ax21:change>");
    String[] secondmsg2 = firstmsg2[1].split("</ax21:change>");
    String change2 = secondmsg2[0];
    assertNotNull(change2, "change value is null");
    assertEquals(response2.getResponseCode(), 202, "Unexpected response code");

    assertEquals(change1, change2, "Response caching did not work for the defined response code regex ");

    Map<String, String> requestHeader2 = new HashMap<>();
    requestHeader2.put("CODE", "401");
    requestHeader2.put("symbol", "RegexPattern");

    // Backend respond with 401 status code
    HttpResponse response3 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader2);
    assertNotNull(response3, "Response is null");
    String[] firstmsg3 = response3.getData().split("<ax21:change>");
    String[] secondmsg3 = firstmsg3[1].split("</ax21:change>");
    String change3 = secondmsg3[0];
    assertNotNull(change3, "change value is null");
    assertEquals(response3.getResponseCode(), 401, "Unexpected response code");

    HttpResponse response4 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader2);
    assertNotNull(response4, "Response is null");
    String[] firstmsg4 = response4.getData().split("<ax21:change>");
    String[] secondmsg4 = firstmsg4[1].split("</ax21:change>");
    String change4 = secondmsg4[0];
    assertNotNull(change4, "change value is null");
    assertEquals(response4.getResponseCode(), 401, "Unexpected response code");

    assertEquals(change3, change4, "Response caching did not work for the defined response code regex ");

    Map<String, String> requestHeader3 = new HashMap<>();
    requestHeader3.put("CODE", "500");
    requestHeader3.put("symbol", "RegexPattern");

    // Backend respond with 500 status code
    HttpResponse response5 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader3);
    assertNotNull(response5, "Response is null");
    String[] firstmsg5 = response5.getData().split("<ax21:change>");
    String[] secondmsg5 = firstmsg5[1].split("</ax21:change>");
    String change5 = secondmsg5[0];
    assertNotNull(change5, "change value is null");
    assertEquals(response5.getResponseCode(), 500, "Unexpected response code");

    HttpResponse response6 = HttpRequestUtil.doGet((getApiInvocationURL("ResponseCodeRegex")), requestHeader3);
    assertNotNull(response6, "Response is null");
    String[] firstmsg6 = response6.getData().split("<ax21:change>");
    String[] secondmsg6 = firstmsg6[1].split("</ax21:change>");
    String change6 = secondmsg6[0];
    assertNotNull(change6, "change value is null");
    assertEquals(response6.getResponseCode(), 500, "Unexpected response code");

    assertNotEquals(change5, change6, "Response caching works for the undefined response code");
}
 
Example 12
Source File: RestClient.java    From product-iots with Apache License 2.0 4 votes vote down vote up
public HttpResponse get(String endpoint) throws Exception {
    return HttpRequestUtil.doGet(backEndUrl + endpoint, requestHeaders);
}
 
Example 13
Source File: RestClient.java    From product-emm with Apache License 2.0 4 votes vote down vote up
public HttpResponse get(String endpoint) throws Exception {
    return HttpRequestUtil.doGet(backEndUrl + endpoint, requestHeaders);
}