use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testSimpleReqInvalidOrigin.
@Test(description = "Test simple request for invalid origins")
public void testSimpleReqInvalidOrigin() {
String path = "/hello1/test1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Hello there");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "www.wso2.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(), "resCors");
Assert.assertEquals(null, response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()));
Assert.assertNull(null, response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString()));
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqwithUnavailableMethod.
@Test(description = "Test preflight with unavailable HTTP methods")
public void testPreFlightReqwithUnavailableMethod() {
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_PUT);
cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_HEADERS.toString(), "X-PINGOTHER");
HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
Assert.assertNotNull(response);
assertEqualsCorsResponse(response, 200, null, null, null, null, null);
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqwithHeadMethod.
@Test(description = "Test for preflight with Head as request method to a GET method annotated resource")
public void testPreFlightReqwithHeadMethod() {
String path = "/hello1/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.m3.com");
cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_HEAD);
cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_HEADERS.toString(), "CORELATION_ID");
HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
Assert.assertNotNull(response);
assertEqualsCorsResponse(response, 200, "http://www.m3.com", "true", "CORELATION_ID", HttpConstants.HTTP_METHOD_HEAD, "1");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqwithNoMethod.
@Test(description = "Test preflight without Request Method header")
public void testPreFlightReqwithNoMethod() {
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_HEADERS.toString(), "X-PINGOTHER");
HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
Assert.assertNotNull(response);
assertEqualsCorsResponse(response, 200, null, null, null, null, null);
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqwithCaseInsensitiveOrigin.
@Test(description = "Test for case insensitive origin")
public void testPreFlightReqwithCaseInsensitiveOrigin() {
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);
HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
Assert.assertNotNull(response);
assertEqualsCorsResponse(response, 200, null, null, null, null, null);
}
Aggregations