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

The following examples show how to use org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil#sendGetRequest() . 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: APIMANAGER1838RequestHashGeneratorTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = {
        "wso2.esb" }, dependsOnMethods = "addPeople", description = "Retrieving people from PeopleRestService")
public void getPeople() throws Exception {

    if (isTomcatServerRunning(tomcatServerManager, 5000)) {
        HttpResponse response1 = HttpRequestUtil
                .sendGetRequest(getApiInvocationURL("APIM1838getPerson") + "/[email protected]", null);
        assertEquals(response1.getResponseCode(), 200, "Response code mismatch");
        assertTrue(response1.getData().contains("John"), "Response message is not as expected.");
        assertTrue(response1.getData().contains("Doe"), "Response message is not as expected");

        HttpResponse response2 = HttpRequestUtil
                .sendGetRequest(getApiInvocationURL("APIM1838getPerson") + "/[email protected]", null);
        assertEquals(response2.getResponseCode(), 200, "Response code mismatch");
        assertTrue(response2.getData().contains("Jane"), "Response message is not as expected.");
        assertTrue(response2.getData().contains("Doe"), "Response message is not as expected");
    } else {
        Assert.fail("Jaxrs Service Startup failed");
    }
}
 
Example 2
Source File: ESBJAVA3751UriTemplateReservedCharacterEncodingTest.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Sending http request with a path param consist of" +
        " whole URL including protocol , host , port etc. ")
public void testURITemplateSpecialCaseVariableWithFullURL() throws Exception {
    boolean isPercentEncoded = false;
    logViewerClient.clearLogs();
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("services/client/special_case/http://localhost:8480/services/test_2/special_case"),
            null);
    LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();
    for (LogEvent logEvent : logs) {
        String message = logEvent.getMessage();
        if (message.contains("To: /services/test_2/special_case")) {
            isPercentEncoded = true;
            break;
        }
    }
    Assert.assertTrue(isPercentEncoded,
            "The Special case of of Full URL expansion should be identified and should not percent encode full URL");

}
 
Example 3
Source File: ESBJAVA5217NoDefaultContentTypeTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb",
      description = "Test to verify whether bocking enabled calls not going to set default content type")
public void testSettingDefaultContentType() throws Exception {
    boolean isContentTypeAvailable = false;
    logViewerClient.clearLogs();
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getProxyServiceURLHttp("CallMediatorNoDefaultContentTypeTestProxy"),
                    null);
    LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();
    for (LogEvent logEvent : logs) {
        if (logEvent.getPriority().equals("INFO")) {
            String message = logEvent.getMessage();
            if (message.contains("Default_ContentType_Test_ContentType = null")) {
                isContentTypeAvailable = true;
                break;
            }
        }
    }
    Assert.assertTrue(isContentTypeAvailable, "Call mediator set default content type for get a request");
}
 
Example 4
Source File: ESBJAVA3751UriTemplateReservedCharacterEncodingTest.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Sending http request with a query param consist of"
        + " reserved + character ")
public void testURITemplateParameterDecodingPlusCharacterCase() throws Exception {
    carbonLogReader.clearLogs();
    boolean isPercentEncoded = false;
    boolean isMessageContextPropertyPercentDecoded = false;
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getApiInvocationURL("services/client/urlEncoded?queryParam=ESB+WSO2"), null);
    String decodedMessageContextProperty = "decodedQueryParamValue = ESB+WSO2";
    isMessageContextPropertyPercentDecoded =
            carbonLogReader.checkForLog(decodedMessageContextProperty, DEFAULT_TIMEOUT);
    isPercentEncoded = carbonLogReader.checkForLog("ESB%2BWSO2", DEFAULT_TIMEOUT);
    Assert.assertTrue(isMessageContextPropertyPercentDecoded,
            "Uri-Template parameters should be percent decoded at message context property");
    Assert.assertTrue(isPercentEncoded,
            "Reserved character should be percent encoded while uri-template expansion");
}
 
Example 5
Source File: ESBJAVA3751UriTemplateReservedCharacterEncodingTest.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Sending http request with a query param consist of"
        + " reserved + character ")
public void testURITemplateParameterDecodingWithPercentEncodingEscapedAtExpansion() throws Exception {
    carbonLogReader.clearLogs();
    boolean isPercentEncoded = false;
    boolean isMessageContextPropertyPercentDecoded = false;
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getApiInvocationURL("services/client/escapeUrlEncoded?queryParam=ESB+WSO2"), null);
    String decodedMessageContextProperty = "decodedQueryParamValue = ESB+WSO2";
    isMessageContextPropertyPercentDecoded = carbonLogReader.checkForLog(decodedMessageContextProperty, DEFAULT_TIMEOUT);
    isPercentEncoded = carbonLogReader.checkForLog("ESB%2BWSO2", DEFAULT_TIMEOUT);
    Assert.assertTrue(isMessageContextPropertyPercentDecoded,
            "Uri-Template parameters should be percent decoded at message context property");
    Assert.assertFalse(isPercentEncoded,
            "Reserved character should not be percent encoded while uri-template expansion");
}
 
Example 6
Source File: ESBJAVA4913HandleExceptionTest.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies whether the mediator reach error sequence on error while executing.
 */
@Test(groups = "wso2.esb", description = "Check if clone mediator reach error sequence on error.")
public void testExceptionHandlingInCloneMediator() throws Exception{

    final String expectedErrorMsg = "This is error sequence from sequenceOne";
    CarbonLogReader carbonLogReader = new CarbonLogReader();
    carbonLogReader.start();
    // invoking the service through the test api.
    try {
        HttpRequestUtil.sendGetRequest(getApiInvocationURL("clonetest"), "");
    } catch (Exception e) {
        // Ignore read timeout from get request.
    }
    boolean isExpectedErrorMessageFound = carbonLogReader.checkForLog(expectedErrorMsg, DEFAULT_TIMEOUT);
    carbonLogReader.stop();
    /*
     * Asserting the results here. If there's no logs from error sequence, then the
     * assertion should fail.
     */
    Assert.assertTrue(isExpectedErrorMessageFound, "Error sequence logs not found in the LOG stream.");
}
 
Example 7
Source File: ESBJAVA4781EscapeAutoPrimitiveTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description =
        "Check whether JSON field value auto primitive is escaped if field value starting region "
                + "is matched with replace regex after flowing through Staxon formatter in passthrough transport | matched starting region"
                + "will be replaced")
public void testJSONEmptyArrayMissingNHTTPTransport() throws Exception {
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getApiInvocationURL("formatterEscapePrimitiveSequenceAPI/escapePrimitive"), null);
    String expected =
            "{\"testEscapePrimitive\":{\"integer\":1989,\"float\":1989.9,\"null\":null,\"boolean_true\":true,"
                    + "\"boolean_false\":false,\"string\":\"string\",\"integer_escaped\":\"1989\",\"float_escaped\":\"1989.9\",\"null_escaped\":\"null\","
                    + "\"boolean_true_escaped\":\"true\",\"boolean_false_escaped\":\"false\",\"string_escaped\":\"string\"}}";

    Assert.assertTrue(expected.equals(response.getData()),
                      "JSON field value auto primitive has not not been escaped from formatter"
                    + " when if field value starting region is matched with replace regex.");

}
 
Example 8
Source File: ESBJAVA4176MethodNotAllowedTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Sending http GET request for a POST resource")
public void testMethodNotAllowed() {
    try {
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("method/post"),
            null);
    Assert.fail("Method should be not found. But got a response with response code " + response.getResponseCode());
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("405"), "The method should be not found. But instead " +
                "got an error message " + e.getMessage());
    }
}
 
Example 9
Source File: RestPostFixUrlTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Sending a Message Via REST with additional resource")
public void testRESTURITemplateWithAdditionalParam() throws Exception {

	/** To check whether the Context URL part "anotherParam" available
	 *  sending request from Client API with additional resource - "anotherParam"
	 *  & prameter - "foo"
	 *  services/client/anotherParam/foo
	 */

	HttpRequestUtil.sendGetRequest(
			getApiInvocationURL("services/client/anotherParam/foo"), null);
	Assert.assertTrue(Utils.checkForLog(logViewerClient, "/services/testAPI/foo", 10),
			" Target URL is wrong. expected /services/testAPI/foo ");

}
 
Example 10
Source File: LastQueryParamEmptyTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * This test method verify all query params empty return expected response for given resource template
 *
 * Resource - /pattern1?latitude={+latitude}&longitude={+longitude}&floor={+floor}
 *
 * @throws Exception
 */
@Test(groups = { "wso2.esb" })
public void testResourcePattern1WithAllParametersEmpty() throws Exception {
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("last-query-param-empty/pattern1?latitude=&longitude=&floor="),
            null);
    Assert.assertNotNull(response);
    int responseCode = response.getResponseCode();
    String responseData = response.getData();
    Assert.assertEquals(responseCode, 200);
    Assert.assertEquals(responseData, "<m:checkQueryParam xmlns:m=\"http://services.samples/xsd\">" +
            "<m:latitude/><m:longitude/><m:floor/></m:checkQueryParam>");
}
 
Example 11
Source File: LastQueryParamEmptyTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This test method verify all query params return expected response for given resource template
 * <p>
 * Resource - /pattern1?latitude={+latitude}&longitude={+longitude}&floor={+floor}
 *
 * @throws Exception
 */
@Test(groups = { "wso2.esb" })
public void testResourcePattern1WithParameters() throws Exception {
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("last-query-param-empty/pattern1?latitude=10&longitude=20&floor=30"), null);
    Assert.assertNotNull(response);
    int responseCode = response.getResponseCode();
    String responseData = response.getData();
    Assert.assertEquals(responseCode, 200);
    Assert.assertEquals(responseData, "<m:checkQueryParam xmlns:m=\"http://services.samples/xsd\">"
            + "<m:latitude>10</m:latitude><m:longitude>20</m:longitude><m:floor>30</m:floor></m:checkQueryParam>");
}
 
Example 12
Source File: LastQueryParamEmptyTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * This test method verify last query param empty return expected response for given resource template
 *
 * Resource - /pattern1?latitude={+latitude}&longitude={+longitude}&floor={+floor}
 *
 * @throws Exception
 */
@Test(groups = { "wso2.esb" })
public void testResourcePattern1WithLastParameterEmpty() throws Exception {
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("last-query-param-empty/pattern1?latitude=10&longitude=20&floor="),
            null);
    Assert.assertNotNull(response);
    int responseCode = response.getResponseCode();
    String responseData = response.getData();
    Assert.assertEquals(responseCode, 200);
    Assert.assertEquals(responseData, "<m:checkQueryParam xmlns:m=\"http://services.samples/xsd\">" +
            "<m:latitude>10</m:latitude><m:longitude>20</m:longitude><m:floor/></m:checkQueryParam>");
}
 
Example 13
Source File: LastQueryParamEmptyTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * This test method verify second query param empty return expected response for given resource template
 *
 * Resource - /pattern1?latitude={+latitude}&longitude={+longitude}&floor={+floor}
 *
 * @throws Exception
 */
@Test(groups = { "wso2.esb" })
public void testResourcePattern1WithSecondtParameterEmpty() throws Exception {
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("last-query-param-empty/pattern1?latitude=10&longitude=&floor=30"),
            null);
    Assert.assertNotNull(response);
    int responseCode = response.getResponseCode();
    String responseData = response.getData();
    Assert.assertEquals(responseCode, 200);
    Assert.assertEquals(responseData, "<m:checkQueryParam xmlns:m=\"http://services.samples/xsd\">" +
            "<m:latitude>10</m:latitude><m:longitude/><m:floor>30</m:floor></m:checkQueryParam>");
}
 
Example 14
Source File: ESBJAVA4331MissingJSONEmptyArrayNHTTPTransport.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = "wso2.esb", description = "check whether Backend JSON payload is missing Json empty array elements "
        + "after flowing through NHTTP transport in response path back to client")
public void testJSONEmptyArrayMissingNHTTPTransport() throws Exception {
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getApiInvocationURL("testJsonEmptyArray/testapi1"), null);
    Assert.assertTrue(response.getData().contains("\"zeroElementArrayField\": []"),
                      "Backend JSON payload is missing [] in Json empty array units after flowing through NHTTP "
                      + "transportin response path back to client");

    response = HttpRequestUtil.sendGetRequest(getApiInvocationURL("testJsonEmptyArray/testapi2"), null);
    Assert.assertTrue(response.getData().replaceAll("\\s", "").contains(
            "[{\"numField1\":\"1\"},{\"numField2\":\"2\"},{\"numField3\":\"3\"},{\"numField4\":\"4\"}]"),
                      "All number fields are not treated equally by Auto primitive function after flowing through"
                      + " NHTTP transportin response path back to client");

    response = HttpRequestUtil.sendGetRequest(getApiInvocationURL("testJsonEmptyArray/testapi3"), null);
    Assert.assertTrue(response.getData().replaceAll("\\s", "")
                              .contains("\"singleElementArrayField\":[{\"numField1\":\"1\"}]"),
                      "Backend JSON payload is missing [] in Json single element array units after flowing "
                      + "through NHTTP transport"
                      + "in response path back to client");

    response = HttpRequestUtil.sendGetRequest(getApiInvocationURL("testJsonEmptyArray/testapi4"), null);
    Assert.assertTrue(response.getData().replaceAll("\\s", "").contains(
            "\"multipleElementArrayField\":[{\"numField1\":\"1\"},{\"numField2\":\"2\"},"
            + "{\"numField3\":\"3\"}]"),
                      "Backend JSON payload is missing [] in Json multiple element array units after flowing "
                      + "through NHTTP transport in response path back to client");

}
 
Example 15
Source File: ESBJAVA4331MissingJSONEmptyArrayNHTTPTransport.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = "wso2.esb", description = "check whether Backend JSON payload is missing Json empty array elements " +
        "after flowing through NHTTP transport in response path back to client")
public void testJSONEmptyArrayMissingNHTTPTransport() throws Exception {
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("testJsonEmptyArray/testapi1"), null);
    Assert.assertTrue("Backend JSON payload is missing [] in Json empty array units after flowing through NHTTP transport"
            + "in response path back to client", response.getData()
            .contains("\"zeroElementArrayField\": []"));

    response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("testJsonEmptyArray/testapi2"), null);
    Assert.assertTrue(
            "All number fields are not treated equally by Auto primitive function after flowing through NHTTP transport"
                    + "in response path back to client", response.getData().replaceAll("\\s", "").contains(
                    "[{\"numField1\":\"1\"},{\"numField2\":\"2\"},{\"numField3\":\"3\"},{\"numField4\":\"4\"}]"));

    response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("testJsonEmptyArray/testapi3"), null);
    Assert.assertTrue("Backend JSON payload is missing [] in Json single element array units after flowing through NHTTP transport"
            + "in response path back to client", response.getData().replaceAll("\\s", "")
            .contains("\"singleElementArrayField\":[{\"numField1\":\"1\"}]"));

    response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("testJsonEmptyArray/testapi4"), null);
    Assert.assertTrue("Backend JSON payload is missing [] in Json multiple element array units after flowing through NHTTP transport"
            + "in response path back to client", response.getData().replaceAll("\\s", "")
            .contains("\"multipleElementArrayField\":[{\"numField1\":\"1\"},{\"numField2\":\"2\"},"
                    + "{\"numField3\":\"3\"}]"));

}
 
Example 16
Source File: ESBJAVA3751UriTemplateReservedCharacterEncodingTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Sending http request with a query param consist of" +
        " reserved + character ")
public void testURITemplateParameterDecodingWithPercentEncodingEscapedAtExpansion() throws Exception {
    boolean isPercentEncoded = false;
    boolean isMessageContextPropertyPercentDecoded = false;
    logViewerClient.clearLogs();
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("services/client/escapeUrlEncoded?queryParam=ESB+WSO2"),
            null);
    String decodedMessageContextProperty="decodedQueryParamValue = ESB+WSO2";
    LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();

    //introduced since clearLogs() is not clearing previoues URL call logs, and need to stop
    // searching after 4 messages
    int count = 0;
    for (LogEvent logEvent : logs) {
        String message = logEvent.getMessage();
        if (count++ >= 4) {
            break;
        }
        if (message.contains(decodedMessageContextProperty)) {
            isMessageContextPropertyPercentDecoded = true;
            continue;
        }
        if (message.contains("ESB%2BWSO2")) {
            isPercentEncoded = true;
            continue;
        }
    }
    Assert.assertTrue(isMessageContextPropertyPercentDecoded,
            "Uri-Template parameters should be percent decoded at message context property");
    Assert.assertFalse(isPercentEncoded,
            "Reserved character should not be percent encoded while uri-template expansion");
}
 
Example 17
Source File: LastQueryParamEmptyTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This test method verify last query param empty and missing equal sign return expected response for given
 * resource template
 * <p>
 * Resource - /pattern3/*
 *
 * @throws Exception
 */
@Test(groups = { "wso2.esb" })
public void testResourcePattern3WithLastParameterEmptyAndMissingEqualSign() throws Exception {
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("last-query-param-empty/pattern3/sample?latitude=10&longitude=20&floor"), null);
    Assert.assertNotNull(response);
    int responseCode = response.getResponseCode();
    String responseData = response.getData();
    Assert.assertEquals(responseCode, 200);
    Assert.assertEquals(responseData, "<m:checkQueryParam xmlns:m=\"http://services.samples/xsd\">"
                    + "<m:latitude>10</m:latitude><m:longitude>20&amp;floor</m:longitude><m:floor/></m:checkQueryParam>",
            "Query Parameter isn't evaluated according the standard");
}
 
Example 18
Source File: LastQueryParamEmptyTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This test method verify last query param empty and missing equal sign return expected response for given
 * resource template
 * <p>
 * Resource - /pattern2*
 *
 * @throws Exception
 */
@Test(groups = { "wso2.esb" })
public void testResourcePattern2WithLastParameterEmptyAndMissingEqualSign() throws Exception {
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getApiInvocationURL("last-query-param-empty/pattern2?latitude=10&longitude=20&floor"),
                    null);
    Assert.assertNotNull(response);
    int responseCode = response.getResponseCode();
    String responseData = response.getData();
    Assert.assertEquals(responseCode, 200);
    Assert.assertEquals(responseData, "<m:checkQueryParam xmlns:m=\"http://services.samples/xsd\">"
                    + "<m:latitude>10</m:latitude><m:longitude>20&amp;floor</m:longitude><m:floor/></m:checkQueryParam>",
            "Query Parameter isn't evaluated according the standard");
}
 
Example 19
Source File: APIMANAGER1838RequestHashGeneratorTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Adding people to PeopleRestService", enabled = false)
public void addPeople() throws Exception {
    if (isTomcatServerRunning(tomcatServerManager, 5000)) {
        HttpResponse response1 = HttpRequestUtil.sendGetRequest(getApiInvocationURL("APIM1838addPerson")
                + "/[email protected]&firstName=John&lastName=Doe", null);
        assertEquals(response1.getResponseCode(), 201, "Response code mismatch");

        HttpResponse response2 = HttpRequestUtil.sendGetRequest(getApiInvocationURL("APIM1838addPerson")
                + "/[email protected]&firstName=Jane&lastName=Doe", null);
        assertEquals(response2.getResponseCode(), 201, "Response code mismatch");
    } else {
        Assert.fail("Jaxrs Service Startup failed");
    }
}
 
Example 20
Source File: ESBJAVA4760ContentLengthHeaderTest.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Test(groups = "wso2.esb", description = "Test 204 status code  with disable chunking", enabled = true)
public void testContentLengthWithDisableChunking() throws IOException {
    HttpResponse response = HttpRequestUtil.sendGetRequest(getApiInvocationURL("StockQuoteAPIESBJAVA4760") + "/view/IBM", null);
    Assert.assertEquals(response.getResponseCode(), EXPECTED_HTTP_SC, "Expected response code didn't match");
}