use of org.wso2.carbon.registry.core.Resource 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.wso2.carbon.registry.core.Resource 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.wso2.carbon.registry.core.Resource 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.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.
the class UriMatrixParametersMatchTest method testNonEncodedUrlDispatching.
@Test
public void testNonEncodedUrlDispatching() {
// encoded URI
String path = "/hello/t2/john;age=2;color=white/foo;a=5;b=10";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 404, "Response code mismatch");
// checking the exception message
String errorMessage = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(errorMessage, "Message body null");
Assert.assertTrue(errorMessage.contains("no matching resource found for path"), "Expected error not found.");
}
use of org.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.
the class UriTemplateBestMatchTest method testStringQueryParam.
@Test(description = "Test suitable method with URL. /echo125?foo=hello ")
public void testStringQueryParam() {
String path = "/hello/echo125?foo=hello";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("echo125").asText(), "hello", "Resource dispatched to wrong template");
path = "/hello/echo125?foo=";
cMsg = MessageUtils.generateHTTPMessage(path, "GET");
response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("echo125").asText(), "", "Resource dispatched to wrong template");
}
Aggregations