Java Code Examples for org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil#doPost()
The following examples show how to use
org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil#doPost() .
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: ESBJAVA3290TestXWWWFormURLEncodedFormatter.java From micro-integrator with Apache License 2.0 | 6 votes |
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) @Test(groups = "wso2.esb", description = "POST request against REST endpoint where " + "body parameter name starts with digit") public void testPostRequest() throws Exception { URL endpoint = new URL(getProxyServiceURLHttp("RestProxy")); try { Map<String, String> header = new HashMap<String, String>(); header.put("Content-Type", "application/x-www-form-urlencoded"); HttpRequestUtil.doPost(endpoint, "paramName=abc&2paramName=def&$paramName=ghi", header); } catch (Exception e) { //ignore } String response = wireServer.getCapturedMessage(); Assert.assertNotNull(response); Assert.assertTrue(response.contains("2paramName"), "POST request does not contain the " + "body " + "parameter name starts with digit " + "specified"); Assert.assertTrue(response.contains("$paramName"), "POST request does not contain the " + "body " + "parameter name starts with $ character " + "specified"); }
Example 2
Source File: JSONTransformJSONSchemaTestCases.java From product-ei with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Changing XML payload to JSON payload with simple Schema " + "stored in Local Entry") public void testSimpleXMLToJsonWithSchemaLocalEntry() 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("transformMediatorSimpleXMLtoJSONWithSchemaLocalEntry")), payload, httpHeaders); assertEqualJsonObjects(response.getData(), expectedOutput, "Simple XML to JSON transformation with a simple schema did not happen properly"); }
Example 3
Source File: XMLToJsonTestCase.java From product-ei with Apache License 2.0 | 6 votes |
@Test(groups = {"wso2.esb"}, description = "Test XML to JSON Array conversion") public void testXmlToJsonArray() throws Exception { String xmlPayload = "<coordinates>\n" + " <location>\n" + " <name>Bermuda Triangle</name>\n" + " <n>25.0000</n>\n" + " <w>71.0000</w>\n" + " </location>\n" + " <location>\n" + " <name>Eiffel Tower</name>\n" + " <n>48.8582</n>\n" + " <e>2.2945</e>\n" + " </location>\n" + " </coordinates>"; Map<String, String> requestHeader = new HashMap<>(); requestHeader.put("Content-Type", "text/xml"); HttpResponse response = HttpRequestUtil. doPost(new URL(getProxyServiceURLHttp("xmlToJsonTestProxy")), xmlPayload, requestHeader); Assert.assertTrue(response.getData().contains("{\"coordinates\":{\"location\":[{"), "Invalid XML to JSON array conversion . " + response.getData()); }
Example 4
Source File: LocationHeaderWithRelativeURLPathTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Test to check whether location header value persists in the http response") public void testForLocationHeaderInResponse() throws Exception { String proxyServiceUrl = getProxyServiceURLHttp("LocationHeaderTestProxy"); String requestPayload = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + " <testBody>\n" + " <foo/>\n" + " </testBody>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>\n"; Map<String, String> headers = new HashMap<>(); headers.put("SOAPAction", "urn:getQuote"); HttpResponse response = HttpRequestUtil.doPost(new URL(proxyServiceUrl), requestPayload, headers); Map<String, String> responseHeaders = response.getHeaders(); assertNotNull(responseHeaders, "Error in retrieving the response headers!"); String locationHeaderValue = responseHeaders.get(LOCATION_HEADER_NAME); assertNotNull(locationHeaderValue, "Location header not set!"); assertEquals(locationHeaderValue, EXPECTED_LOCATION_HEADER, "Incorrect location header!"); }
Example 5
Source File: LocationHeaderWithRelativeURLPathTestCase.java From product-ei with Apache License 2.0 | 6 votes |
@Test(groups = "wso2.esb", description = "Test to check whether location header value persists in the http response") public void testForLocationHeaderInResponse() throws Exception { String proxyServiceUrl = getProxyServiceURLHttp("LocationHeaderTestProxy"); String requestPayload = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + " <testBody>\n" + " <foo/>\n" + " </testBody>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>\n"; Map<String, String> headers = new HashMap<>(); headers.put("SOAPAction", "urn:getQuote"); HttpResponse response = HttpRequestUtil.doPost(new URL(proxyServiceUrl), requestPayload, headers); Map<String, String> responseHeaders = response.getHeaders(); assertNotNull(responseHeaders, "Error in retrieving the response headers!"); String locationHeaderValue = responseHeaders.get(LOCATION_HEADER_NAME); assertNotNull(locationHeaderValue, "Location header not set!"); assertEquals(locationHeaderValue, EXPECTED_LOCATION_HEADER, "Incorrect location header!"); }
Example 6
Source File: VFSTransportTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) @Test(groups = { "wso2.esb" }, description = "Writing to a file the content of a xml with content in text element") public void testVFSProxyPlainXMLWriter() throws Exception { File outfile = new File(proxyVFSRoots.get("salesforce_DAMAS_writeFile") + File.separator + "out" + File.separator + "out_reply.xml"); String request = " <ns:text xmlns:ns=\"http://ws.apache.org/commons/ns/payload\"><test>request_value</test></ns:text>"; Map<String, String> headers = new HashMap<>(); headers.put("Content-type", "text/xml;charset=UTF-8"); headers.put("Accept-Charset", "UTF-8"); HttpRequestUtil.doPost(new URL(getProxyServiceURLHttp("salesforce_DAMAS_writeFile")), request, headers); Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(isFileExist(outfile)); Assert.assertTrue(outfile.exists()); Assert.assertTrue(doesFileContain(outfile, "request_value"), "Sent request body not found"); }
Example 7
Source File: TransactionMediatorTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Test for use-existing-or-new action for using an existing transaction * * @throws Exception */ @Test(groups = "wso2.esb", description = "Test use-existing-or-new action for using an existing transaction") public void useExistingTransactionTest() throws Exception { String expectedOutputForNick = "<response><table1>4</table1><table2>4</table2></response>"; String expectedOutputForJohn = "<response><table1>5</table1><table2>5</table2></response>"; HttpRequestUtil.doPost(new URL(API_URL + USE_EXISTING_NEW_CONTEXT + "?testEntry=John&entryId=5"), ""); HttpResponse httpResponseForNick = HttpRequestUtil .doPost(new URL(API_URL + TEST_CONTEXT + "?testEntry=Nick"), ""); HttpResponse httpResponseForJohn = HttpRequestUtil .doPost(new URL(API_URL + TEST_CONTEXT + "?testEntry=John"), ""); boolean satisfyEntryNick = httpResponseForNick.getData().equals(expectedOutputForNick); boolean satisfyEntryJohn = httpResponseForJohn.getData().equals(expectedOutputForJohn); Assert.assertTrue(satisfyEntryJohn & satisfyEntryNick, "Use-existing-or-new action fails for using an existing transaction in transaction mediator"); }
Example 8
Source File: XMLToJsonTransformationPropertiesTestCase.java From product-ei with Apache License 2.0 | 6 votes |
/** * Test the property synapse.commons.json.output.jsonoutAutoArray=false * @throws Exception */ @Test(groups = {"wso2.esb"}, description = "Test XML to JSON Array conversion") public void testXmlToJsonArray() throws Exception { String xmlPayload = "<stocks>" + " <stock>\n" + " <name>WSO2</name>\n" + " <price>10</price>\n" + " </stock>\n" + " <stock>\n" + " <name>IBM</name>\n" + " <price>15</price>\n" + " </stock>" + " </stocks>"; Map<String, String> requestHeader = new HashMap<>(); requestHeader.put("Content-Type", "text/xml"); HttpResponse response = HttpRequestUtil. doPost(new URL(getProxyServiceURLHttp("xmlToJsonTestProxy")), xmlPayload, requestHeader); Assert.assertEquals(response.getData(), "{\"stocks\":{\"stock\":{\"name\":\"WSO2\",\"price\":\"10\"},\"stock\":{\"name\":\"IBM\",\"price\":\"15\"}}}", "Invalid XML to JSON array conversion. " + response.getData()); }
Example 9
Source File: TransactionMediatorTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Test for creating a new transaction with new and commit actions * * @throws Exception */ @Test(groups = "wso2.esb", description = "Test commit transaction") public void commitTransactionTest() throws Exception { String expectedOutput = "<response><table1/><table2>2</table2></response>"; HttpRequestUtil.doPost(new URL(API_URL + COMMIT_CONTEXT), ""); HttpResponse httpResponse = HttpRequestUtil.doPost(new URL(API_URL + TEST_CONTEXT + "?testEntry=Alice"), ""); Assert.assertEquals(httpResponse.getData(), expectedOutput, "Commit transaction fails in transaction mediator"); }
Example 10
Source File: XMLToJsonTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
@Test(groups = { "wso2.esb" }, description = "Test XML to JSON conversion") public void testXmlToJson() throws Exception { String xmlPayload = "<location>\n" + " <name>Bermuda Triangle</name>\n" + " <n>25.0000</n>\n" + " <w>71.0000</w>\n" + " </location>"; Map<String, String> requestHeader = new HashMap<>(); requestHeader.put("Content-Type", "text/xml"); HttpResponse response = HttpRequestUtil. doPost(new URL(getProxyServiceURLHttp("xmlToJsonTestProxy")), xmlPayload, requestHeader); Assert.assertEquals(response.getData(), "{\"location\":{\"name\":\"Bermuda Triangle\",\"n\":25.0000,\"w\":71.0000}}", "Invalid XML to JSON conversion. " + response.getData()); }
Example 11
Source File: MediationLibraryServiceTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Test for invoking connector service. * * @throws Exception */ @Test(groups = "wso2.esb", description = "Test connector upload and invoke.") public void invokeConnectorTest() throws Exception { String apiURI = "http://localhost:8480/library-service/get-message"; String expectedOutput = "<message>Bob</message>"; HttpResponse httpResponse = HttpRequestUtil.doPost(new URL(apiURI), ""); Assert.assertEquals(httpResponse.getData(), expectedOutput, "Invoking hello connector fails."); }
Example 12
Source File: SOAP11ToJSONConversion.java From micro-integrator with Apache License 2.0 | 5 votes |
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) @Test(groups = "wso2.esb", description = "JSon to SOAP11 Conversion") public void testJsonToSOAP11() throws Exception { URL endpoint = new URL(getProxyServiceURLHttp("jsonToSoap11")); Map<String, String> header = new HashMap<String, String>(); header.put("Content-Type", "application/json"); String inputPayload = "{\"Hello\":\"World\"}"; HttpResponse response = HttpRequestUtil.doPost(endpoint, inputPayload, header); Assert.assertEquals(inputPayload, response.getData(), "Expected payload not received."); }
Example 13
Source File: SOAP11ToJSONConversion.java From micro-integrator with Apache License 2.0 | 5 votes |
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE }) @Test(groups = "wso2.esb", description = "SOAP11 to JSON Conversion") public void testSOAP11ToJson() throws Exception { URL endpoint = new URL(getProxyServiceURLHttp("soapToJson")); Map<String, String> header = new HashMap<String, String>(); header.put("Content-Type", "text/xml"); HttpResponse response = HttpRequestUtil.doPost(endpoint, "<test>123</test>", header); String expectedPayload = "<jsonObject><Hello>World</Hello></jsonObject>"; Assert.assertEquals(expectedPayload, response.getData(), "Expected payload not received."); }
Example 14
Source File: TransactionMediatorTestCase.java From product-ei with Apache License 2.0 | 5 votes |
/** * Test for identifying no transaction with fault-if-no-tx action * * @throws Exception */ @Test(groups = "wso2.esb", description = "Test fault-if-no-tx transaction") public void faultIfNoTxTransactionTest() throws Exception { String expectedOutput = "<response><message>No Transactions</message></response>"; HttpResponse httpResponse = HttpRequestUtil.doPost(new URL(API_URL + FAULT_NOTX_CONTEXT), ""); Assert.assertEquals(httpResponse.getData(), expectedOutput, "Fault-if-no-tx transaction fails in transaction mediator"); }
Example 15
Source File: AggregateEmptyJsonPayloadTestCase.java From product-ei with Apache License 2.0 | 5 votes |
/** * At the proxy service, requests will be sent iteratively for the no content response backend, and recieved * responses will be aggregated * * @throws Exception */ @Test(groups = "wso2.esb", description = "Test CorrelateOn in Aggregate mediator ") public void testAggregateEmptyJsonPayload() throws Exception { String inputPayload = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + "<soapenv:Header/>\n" + "<soapenv:Body>\n" + "<m0:getQuote xmlns:m0=\"http://services.samples\">\n" + " <m0:request>IBM\n" + " </m0:request>\n" + " <m0:request>WSO2\n" + " </m0:request>\n" + "</m0:getQuote>\n" + "</soapenv:Body>\n" + "</soapenv:Envelope>"; String expectedOutput = "<OverallResponse " + "xmlns=\"http://ws.apache.org/ns/synapse\"><jsonObject xmlns=\"\"/><jsonObject " + "xmlns=\"\"/></OverallResponse>"; Map<String, String> requestHeader = new HashMap<>(); requestHeader.put("Content-type", "text/xml"); requestHeader.put("SOAPAction", "urn:mediate"); requestHeader.put("Accept", "application/json"); HttpRequestUtil.doPost(new URL(getProxyServiceURLHttp(PROXY_NAME)), inputPayload, requestHeader); Assert.assertTrue(assertIfSystemLogContains(logViewerClient, expectedOutput), "No content 204 responses are not properly aggregated at the aggregate mediator."); }
Example 16
Source File: TransactionMediatorTestCase.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Test for transaction rollback * * @throws Exception */ @Test(groups = "wso2.esb", description = "Test rollback transaction") public void rollbackTransactionTest() throws Exception { String expectedOutput = "<response><table1>2</table1><table2>1</table2></response>"; HttpRequestUtil.doPost(new URL(API_URL + ROLLBACK_CONTEXT), ""); HttpResponse httpResponse = HttpRequestUtil.doPost(new URL(API_URL + TEST_CONTEXT + "?testEntry=Bob"), ""); Assert.assertEquals(httpResponse.getData(), expectedOutput, "Rollback transaction fails in transaction mediator"); }
Example 17
Source File: DBMediatorUseTransaction.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Initialize database by creating necessary tables and entries for following tests * * @throws Exception */ @BeforeClass(alwaysRun = true) public void setEnvironment() throws Exception { super.init(); HttpRequestUtil.doPost(new URL(getApiInvocationURL(API_URL + INIT_CONTEXT_1)), ""); HttpRequestUtil.doPost(new URL(getApiInvocationURL(API_URL + INIT_CONTEXT_2)), ""); }
Example 18
Source File: TransactionMediatorTestCase.java From product-ei with Apache License 2.0 | 5 votes |
/** * Test for suspend action of a transaction (suspend action has not been implemented though it is mentioned in WSO2 * docs. https://docs.wso2.com/display/EI630/Transaction+Mediator) * * @throws Exception */ @Test(enabled = false, groups = "wso2.esb", description = "Test suspend action without commit transaction") public void suspendActionTest() throws Exception { String expectedOutput = "<response><table1/><table2/></response>"; HttpRequestUtil.doPost(new URL(API_URL + SUSPEND_CONTEXT), ""); HttpResponse httpResponse = HttpRequestUtil.doPost(new URL(API_URL + TEST_CONTEXT + "?testEntry=Mike"), ""); Assert.assertEquals(httpResponse.getData(), expectedOutput, "Suspend action fails in transaction mediator"); }
Example 19
Source File: DBMediatorUseTransaction.java From product-ei with Apache License 2.0 | 4 votes |
private String getDatabaseResultsForDB1FailCase() throws MalformedURLException, AutomationFrameworkException { HttpResponse httpResponse = HttpRequestUtil.doPost(new URL(getApiInvocationURL(API_URL + TEST_CONTEXT_1 + "?testEntry=SUN")), ""); return httpResponse.getData(); }
Example 20
Source File: DBMediatorUseTransaction.java From micro-integrator with Apache License 2.0 | 4 votes |
private String getDatabaseResultsForDB1() throws MalformedURLException, AutomationFrameworkException { HttpResponse httpResponse = HttpRequestUtil .doPost(new URL(getApiInvocationURL(API_URL + TEST_CONTEXT_1 + "?testEntry=IBM")), ""); return httpResponse.getData(); }