use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqwithRestrictedMethodsResourceLevel.
@Test(description = "Test preflight with method restriction at resource level")
public void testPreFlightReqwithRestrictedMethodsResourceLevel() {
String path = "/hello2/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.bbc.com");
cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_DELETE);
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 testSimpleReqMultipleOrigins.
@Test(description = "Test simple request with multiple origins")
public void testSimpleReqMultipleOrigins() {
String path = "/hello1/test3";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Hello there");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.wso2.com http://www.amazon.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(), "moreOrigins");
Assert.assertEquals("http://www.wso2.com http://www.amazon.com", response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()));
Assert.assertEquals("true", 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 testSimpleReqwithExtraWS.
@Test(description = "Test for values with extra white spaces")
public void testSimpleReqwithExtraWS() {
String path = "/hello2/test1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "hello");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.facebook.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(), "resOnlyCors");
Assert.assertEquals("http://www.facebook.com", response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()));
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqwithMissingHeadersAtResourceLevel.
@Test(description = "Test preflight with missing headers at resource level")
public void testPreFlightReqwithMissingHeadersAtResourceLevel() {
String path = "/hello2/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.bbc.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, "http://www.bbc.com", null, "X-PINGOTHER", "PUT", "-1");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPCorsTest method testPreFlightReqServiceResourceCorsOverride.
@Test(description = "Test for CORS override at two levels with preflight")
public void testPreFlightReqServiceResourceCorsOverride() {
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");
}
Aggregations