org.wso2.carbon.automation.test.utils.http.client.HttpResponse Java Examples

The following examples show how to use org.wso2.carbon.automation.test.utils.http.client.HttpResponse. 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: JsonSupportByScriptMediatorTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.esb"}, description = "Serialize JSON payload with JS")
public void testSerializingJson() throws Exception {
    logViewerClient.clearLogs();
    Map<String, String> httpHeaders = new HashMap<>();
    httpHeaders.put("Content-Type", "application/json");
    String payload = "{\n" + "\"name\": \"John Doe\",\n" + "\"dob\": \"1990-03-19\",\n" + "\"ssn\": "
            + "\"234-23" + "-525\",\n" + "\"address\": \"California\",\n" + "\"phone\": \"8770586755\",\n"
            + "\"email\":" + " \"[email protected]\",\n" + "\"doctor\": \"thomas collins\",\n" + "\"hospital\": "
            + "\"grand oak " + "community hospital\",\n" + "\"cardNo\": \"7844481124110331\",\n"
            + "\"appointment_date\": " + "\"2017-04-02\"\n" + "}";
    HttpResponse response = doPost(new URL(getApiInvocationURL("scriptMediatorJsStringifyAPI")), payload,
            httpHeaders);
    boolean propertySet;
    assertNotNull(response, "Response message null");
    propertySet = isPropertyContainedInLog("JSON_TEXT = {\"name\":\"John Doe\",\"address\":\"California\","
            + "\"dob\":\"1990-03-19\"}");
    Assert.assertTrue(propertySet, " The serialized json payload is not set as a property ");

}
 
Example #2
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 #3
Source File: JSONPayloadProperFormatTenantModeTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb",
      description = "Check whether JSON message formatting works properly in tenant mode")
public void testJSONFormattingInTenantMode() throws MalformedURLException, AutomationFrameworkException {
    String JSON_PAYLOAD = "{\"emails\": [{\"value\": \"[email protected]\"}]}";
    Map<String, String> headers = new HashMap<>();
    headers.put("Content-Type", "application/json");
    HttpResponse response = HttpRequestUtil
            .doPost(new URL("http://localhost:8480/json/payload"), JSON_PAYLOAD, headers);

    //checking whether JSON payload of wrong format is received
    assertFalse(response.getData().equals("{\"emails\":{\"value\":\"[email protected]\"}}"),
            "Incorrect format received!");

    //checking whether JSON payload of correct format is present
    assertTrue(response.getData().equals("{\"emails\": [{\"value\": \"[email protected]\"}]}"),
            "Expected format not received!");
}
 
Example #4
Source File: JSONTransformSynapsePropertiesTestCases.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description = "Do XML to JSON transformation with overridden namespace synapse property")
public void testSimpleNamespaceProperty() throws Exception {
    String payload = "<ns:stock xmlns:ns='http://services.samples'>\n" +
            "    <ns:name>WSO2</ns:name>\n" +
            "</ns:stock>";
    Map<String, String> httpHeaders = new HashMap<>();
    httpHeaders.put("Content-Type", "application/xml");
    String expectedOutput = "{\n" +
            "    \"ns^stock\": {\n" +
            "        \"@xmlns^ns\": \"http://services.samples\",\n" +
            "        \"ns^name\": \"WSO2\"\n" +
            "    }\n" +
            "}";
    HttpResponse response = HttpRequestUtil.doPost(
            new URL(getProxyServiceURLHttp("transformMediatorNamespaceProperties")), payload, httpHeaders);
    assertEqualJsonObjects(response.getData(), expectedOutput,
            "XML to JSON transformation with namespace synapse properties overridden did not occur properly");
}
 
Example #5
Source File: NativeJsonSupportByNashornJsTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.esb"}, description = "Serialize JSON payload with NashornJS")
public void testSerializingJson() throws Exception {
    logViewerClient.clearLogs();
    Map<String, String> httpHeaders = new HashMap<>();
    httpHeaders.put("Content-Type", "application/json");
    String payload = "{\n" + "\"name\": \"John Doe\",\n" + "\"dob\": \"1990-03-19\",\n" + "\"ssn\": "
            + "\"234-23" + "-525\",\n" + "\"address\": \"California\",\n" + "\"phone\": \"8770586755\",\n"
            + "\"email\":" + " \"[email protected]\",\n" + "\"doctor\": \"thomas collins\",\n" + "\"hospital\": "
            + "\"grand oak " + "community hospital\",\n" + "\"cardNo\": \"7844481124110331\",\n"
            + "\"appointment_date\": " + "\"2017-04-02\"\n" + "}";
    HttpResponse response = doPost(new URL(getApiInvocationURL("nashornJsStringifyAPI")), payload,
            httpHeaders);
    boolean propertySet;
    assertNotNull(response, "Response message null");
    propertySet = isPropertyContainedInLog("JSON_TEXT = {\"name\":\"John Doe\",\"address\":\"California\","
            + "\"dob\":\"1990-03-19\"}");
    Assert.assertTrue(propertySet, " The serialized json payload is not set as a property ");

}
 
Example #6
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 reserved " +
        "character : with percent encoding escaped at uri-template expansion")
public void testURITemplateExpandWithEscapedPercentEncodingPathParam() throws Exception {
    boolean isPercentEncoded = false;
    logViewerClient.clearLogs();
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("services/client/escapeUrlEncoded/ESB:WSO2"),
            null);
    LogEvent[] logs = logViewerClient.getAllRemoteSystemLogs();
    for (LogEvent logEvent : logs) {
        String message = logEvent.getMessage();
        if (message.contains("To: /services/test_2/ESB%3AWSO2")) {
            isPercentEncoded = true;
            break;
        }
    }
    Assert.assertFalse(isPercentEncoded,
            "Reserved character should not be percent encoded while uri-template expansion as escape enabled");

}
 
Example #7
Source File: ESBJAVA4469CallMediatorWithOutOnlyTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.esb"})
public void outOnlyWithoutContentAwareMediatorTest() throws Exception {
    WireMonitorServer wireMonitorServer = new WireMonitorServer(3828);
    Map<String, String> headers = new HashMap<>();

    wireMonitorServer.start();

    headers.put(HttpHeaders.CONTENT_TYPE, "text/xml");
    headers.put(HTTPConstants.HEADER_SOAP_ACTION, "urn:placeOrder");

    HttpResponse response = HttpRequestUtil.doPost(new URL(getProxyServiceURLHttp("ESBJAVA4469"))
            , messageBody, headers);

    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED, "Response code should be 202");
    String outGoingMessage = wireMonitorServer.getCapturedMessage();
    Assert.assertTrue(outGoingMessage.contains(">WSO2<")
            , "Outgoing message is empty or invalid content " + outGoingMessage);

}
 
Example #8
Source File: JsonSupportByScriptMediatorTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Handling null JSON objects with JS")
public void testHandlingNullJsonObjects() throws Exception {

    Map<String, String> httpHeaders = new HashMap<>();
    httpHeaders.put("Content-Type", "application/json");
    String payload = "{\n" + "\"name\": \"John Doe\",\n" + "\"dob\": \"1990-03-19\",\n" + "\"ssn\": " + "\"234-23"
            + "-525\",\n" + "\"address\": \"California\",\n" + "\"phone\": \"8770586755\",\n" + "\"email\":"
            + " \"[email protected]\",\n" + "\"doctor\": \"thomas collins\",\n" + "\"hospital\": " + "\"grand oak "
            + "community hospital\",\n" + "\"cardNo\": \"7844481124110331\",\n" + "\"appointment_date\": "
            + "\"2017-04-02\"\n" + "}";
    HttpResponse response = doPost(new URL(getApiInvocationURL("scriptMediatorJsHandlingNullJsonObjectAPI")),
            payload, httpHeaders);
    Assert.assertTrue((response.getData().contains("{}")),
            "Response does not contain " + "the keyword \"{}\". Response: " + response.getData());

}
 
Example #9
Source File: JSONTransformSynapsePropertiesTestCases.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = "wso2.esb", description = "Do XML to JSON transformation with overridden autoprimitive" +
        " synapse property")
public void testSimpleAutoPrimitiveProperty() throws Exception {
    String payload = "<jsonObject>\n" +
            "    <fruit>12345</fruit>\n" +
            "    <price>7.5</price>\n" +
            "</jsonObject>";
    Map<String, String> httpHeaders = new HashMap<>();
    httpHeaders.put("Content-Type", "application/xml");
    String expectedOutput = "{\n" +
            "    \"fruit\": \"12345\",\n" +
            "    \"price\": \"7.5\"\n" +
            "}";
    HttpResponse response = HttpRequestUtil.doPost(
            new URL(getProxyServiceURLHttp("transformMediatorSimpleAutoPrimitive")), payload, httpHeaders);
    assertEqualJsonObjects(response.getData(), expectedOutput,
            "XML to JSON transformation with a simple synapse property overridden did not occur properly");
}
 
Example #10
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 #11
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 #12
Source File: NativeJsonSupportByNashornJsTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.esb"}, description = "Handling null JSON objects with NashornJS")
public void testHandlingNullJsonObjects() throws Exception {

    Map<String, String> httpHeaders = new HashMap<>();
    httpHeaders.put("Content-Type", "application/json");
    String payload = "{\n" + "\"name\": \"John Doe\",\n" + "\"dob\": \"1990-03-19\",\n" + "\"ssn\": "
            + "\"234-23" + "-525\",\n" + "\"address\": \"California\",\n" + "\"phone\": \"8770586755\",\n"
            + "\"email\":" + " \"[email protected]\",\n" + "\"doctor\": \"thomas collins\",\n" + "\"hospital\": "
            + "\"grand oak " + "community hospital\",\n" + "\"cardNo\": \"7844481124110331\",\n"
            + "\"appointment_date\": " + "\"2017-04-02\"\n" + "}";
    HttpResponse response = doPost(new URL(getApiInvocationURL("nashornJsHandlingNullJsonObjectAPI")), payload,
            httpHeaders);
    Assert.assertTrue((response.getData().contains("{}")), "Response does not contain "
            + "the keyword \"{}\". Response: " + response.getData());

}
 
Example #13
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 #14
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 #15
Source File: CARBON15046JsonGsonNUllValueTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.dss" }, description = "Check whether the null received successfully", alwaysRun = true)
public void returnNullValueInJsonObjectsOnGETTestCase() throws Exception {
    HttpResponse response = this.getHttpResponse(serviceEndPoint + "_getbird", "application/json");
    JSONObject result = new JSONObject(response.getData());
    assertNotNull(result, "Response is null");
    //Response JSON object will be {"Birds":{"Bird":[{"weight":"30","color":null,"name":"Bird1"}]}}
    JSONArray bidsList = (JSONArray) ((JSONObject) result.get("Birds")).get("Bird");
    JSONObject birdDetails = (JSONObject) bidsList.get(0);
    assertTrue(birdDetails.isNull("color"), "Null value retrieved successful");
    log.info("Null value retrieved from GET successful");
}
 
Example #16
Source File: ValidateJSONSchemaTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = "wso2.esb", description = "Validating the request payload against the JSON Schema " +
                                         "stored in config registry")
public void validRequestTest2() throws Exception {
    String payload = "{" +
                     "  \"getQuote\": {" +
                     "    \"request\": { \"symbol\": \"WSO2\" }" +
                     "  }" +
                     "}";
    HttpResponse response = doPost(new URL(getProxyServiceURLHttp("validateMediatorJsonSchemaFromRegTestProxy"))
            , payload, httpHeaders);
    Assert.assertTrue((!response.getData().equals("") && response.getData().contains("getQuote"))
            , "Valid Request failed. " + response.getData());
}
 
Example #17
Source File: DS1042GetContentTypeSpecifiedTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = "wso2.dss", description = "test the service when Content-Type is specified in GET resource requests - xml",
		alwaysRun = true)
public void testWithXML() throws Exception {
	HttpResponse result = getHttpResponse(serviceEndPoint + "products", "application/xml");
	Assert.assertNotNull(result, "Response null");
	Assert.assertTrue(result.getData().contains("<productCode>S24_3816</productCode><productName>1940 Ford Delivery " +
			                          "Sedan</productName><productLine>Vintage Cars</productLine>" +
			                          "<quantityInStock>6621</quantityInStock><buyPrice>48.64</buyPrice>" +
			                          "</Product>"), "Expected result not found");
	log.info("data service returns correct response when \"application-xml\" content-type is specified in" +
	         " GET-method");
}
 
Example #18
Source File: ValidateJSONSchemaTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = "wso2.esb", description = "Validating the request payload against the JSON Schema" +
                                         " stored in local-entry")
public void inValidRequestTest1() throws Exception {
    String payload = "{\"msg\":{" +
                     "  \"getQuote\": {" +
                     "    \"request\": { \"symbol1\": \"WSO2\" }" +
                     "  }" +
                     "}" +
                     "}";
    HttpResponse response = doPost(new URL(getProxyServiceURLHttp("validateMediatorJsonTestProxy"))
            , payload, httpHeaders);
    Assert.assertEquals(response.getResponseCode(), 500, "Response Code mismatched");
    Assert.assertTrue((!response.getData().equals("") && response.getData().contains("Invalid Request"))
            , "Validation must be failed. Response: " + response.getData());
}
 
Example #19
Source File: ESBJAVA4781EscapeAutoPrimitiveTestCase.java    From product-ei with Apache License 2.0 5 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("JSON field value auto primitive has not not been escaped from formatter" +
          " when if field value starting region is matched with replace regex.", expected.equals(response.getData()));

}
 
Example #20
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 and missing equal sign return expected response for given
 * resource template
 *
 * 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 #21
Source File: PartialInputStreamReadError.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = "wso2.esb", description = "Testing with a inSequence with Log Mediator")
public void testPartialReadErrorWithLogMediator() throws Exception {
    URL endpoint = new URL(getProxyServiceURLHttp("ProcessPO2"));
    Map<String, String> header = new HashMap<>();
    header.put("Content-Type", "application/xml");
    HttpResponse httpResponse = doPost(endpoint, input, header);
    assertTrue(EXPECTED_ERROR.equals(httpResponse.getData()), "Expected error message not received");
}
 
Example #22
Source File: LastQueryParamEmptyTestCase.java    From micro-integrator 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
 * <p>
 * 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 #23
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 #24
Source File: ESBJAVA3751UriTemplateReservedCharacterEncodingTest.java    From micro-integrator with Apache License 2.0 5 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 {
    carbonLogReader.clearLogs();
    boolean isPercentEncoded = false;
    HttpResponse response = HttpRequestUtil.sendGetRequest(
            getApiInvocationURL("services/client/special_case/http://localhost:8480/services/test_2/special_case"),
            null);
    isPercentEncoded = carbonLogReader.checkForLog("To: /services/test_2/special_case", DEFAULT_TIMEOUT);
    Assert.assertTrue(isPercentEncoded,
            "The Special case of of Full URL expansion should be identified and should not percent encode full URL");
}
 
Example #25
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 #26
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 #27
Source File: ESBJAVA3751UriTemplateReservedCharacterEncodingTest.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Sending http request with a path param consist of reserved "
        + "character : with percent encoding escaped at uri-template expansion")
public void testURITemplateExpandWithEscapedPercentEncodingPathParam() throws Exception {
    carbonLogReader.clearLogs();
    boolean isPercentEncoded = false;
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getApiInvocationURL("services/client/escapeUrlEncoded/ESB:WSO2"), null);
    isPercentEncoded = carbonLogReader.checkForLog("To: /services/test_2/ESB%3AWSO2", DEFAULT_TIMEOUT);
    Assert.assertFalse(isPercentEncoded,
            "Reserved character should not be percent encoded while uri-template expansion as escape enabled");

}
 
Example #28
Source File: ESBJAVA3751UriTemplateReservedCharacterEncodingTest.java    From micro-integrator 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 : with percent encoding escaped at uri-template expansion")
public void testURITemplateExpandWithEscapedPercentEncoding() throws Exception {
    boolean isPercentEncoded = false;
    carbonLogReader.clearLogs();
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getApiInvocationURL("services/client/escapeUrlEncoded?queryParam=ESB:WSO2"), null);
    isPercentEncoded = carbonLogReader.checkForLog("ESB%3AWSO2", DEFAULT_TIMEOUT);
    Assert.assertFalse(isPercentEncoded,
            "Reserved character should not be percent encoded while uri-template expansion as escape enabled");

}
 
Example #29
Source File: ESBJAVA3751UriTemplateReservedCharacterEncodingTest.java    From micro-integrator 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 testURITemplateExpandWithPercentEncoding() throws Exception {
    carbonLogReader.clearLogs();
    boolean isPercentEncoded = false;
    HttpResponse response = HttpRequestUtil
            .sendGetRequest(getApiInvocationURL("services/client/urlEncoded?queryParam=ESB:WSO2"), null);
    isPercentEncoded = carbonLogReader.checkForLog("ESB%3AWSO2", DEFAULT_TIMEOUT);
    Assert.assertTrue(isPercentEncoded,
            "Reserved character should be percent encoded while uri-template expansion");

}
 
Example #30
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 - /pattern2*
 *
 * @throws Exception
 */
@Test(groups = { "wso2.esb" })
public void testResourcePattern2WithLastParameterEmpty() 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</m:longitude><m:floor/></m:checkQueryParam>");
}