use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqwithCaseInsensitiveHeader.
@Test(description = "Test for case insensitive header")
public void testPreFlightReqwithCaseInsensitiveHeader() {
String path = "/hello1/test1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.wso2.com");
cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_POST);
cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_HEADERS.toString(), "X-PINGOTHER");
HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
Assert.assertNotNull(response);
assertEqualsCorsResponse(response, 200, "http://www.wso2.com", "true", "X-PINGOTHER", "POST", "-1");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testSimpleReqServiceCors.
@Test(description = "Test for simple request service CORS")
public void testSimpleReqServiceCors() {
String path = "/hello1/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.hello.com");
HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
Assert.assertNotNull(response);
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("echo").asText(), "serCors");
Assert.assertEquals(response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()), "http://www.hello.com");
Assert.assertEquals(response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString()), "true");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqNoCorsResource.
@Test(description = "Test preflight without CORS headers")
public void testPreFlightReqNoCorsResource() {
String path = "/echo4/info1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.wso2.com");
cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_POST);
HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
Assert.assertNotNull(response);
assertEqualsCorsResponse(response, 200, null, null, null, null, null);
Assert.assertEquals(response.getHeader(HttpHeaderNames.ALLOW.toString()), "POST, OPTIONS");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class DataBindingTest method testDataBindingWithoutPayload.
@Test(description = "Test data binding without a payload")
public void testDataBindingWithoutPayload() {
HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body1", "GET");
HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_EP, requestMsg);
Assert.assertNotNull(responseMsg, "responseMsg message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
Assert.assertEquals(bJson.value().get("Person").asText(), "", "Person variable not set properly.");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class DataBindingTest method testDataBindingWithGlobalStruct.
@Test(description = "Test data binding with global custom struct")
public void testDataBindingWithGlobalStruct() {
HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body6", "POST", "{'name':'wso2','age':12}");
requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_JSON);
HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_EP, requestMsg);
Assert.assertNotNull(responseMsg, "responseMsg message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
Assert.assertEquals(bJson.value().get("Key").asText(), "wso2", "Key variable not set properly.");
Assert.assertEquals(bJson.value().get("Age").asText(), "12", "Age variable not set properly.");
}
Aggregations