use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testSpecialCharacterURI.
@Test(description = "Test dispatching with OPTIONS request with wildcard")
public void testSpecialCharacterURI() {
String path = "/ech%5Bo/ech%5Bo/b%5Bar";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET", null);
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("echo113").asText(), "b[ar", "Resource dispatched to wrong template");
}
use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testOPTIONSMethods.
@Test(description = "Test dispatching with OPTIONS method")
public void testOPTIONSMethods() {
String path = "/options/hi";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "hi");
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("echo").asText(), "wso2", "Resource dispatched to wrong template");
}
use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testValidUrlTemplate5Dispatching.
@Test(description = "Test accessing the variables parsed with URL. /products5/{productId}/reg")
public void testValidUrlTemplate5Dispatching() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/ecommerceservice/products5/PID125/reg?regID=RID125¶1=value1", "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
// Expected Json message : {"Template":"T5","ProductID":"PID125","RegID":"RID125"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("Template").asText(), "T5", "Resource dispatched to wrong template");
Assert.assertEquals(bJson.value().get("ProductID").asText(), "PID125", "ProductID variable not set properly.");
Assert.assertEquals(bJson.value().get("RegID").asText(), "RID125", "RegID variable not set properly.");
}
use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testInValidUrlTemplateDispatching.
@Test(description = "Test resource dispatchers with invalid URL. /products/{productId}/{regId}", dataProvider = "inValidUrl")
public void testInValidUrlTemplateDispatching(String path) {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
final String xOrderIdHeadeName = "X-ORDER-ID";
final String xOrderIdHeadeValue = "ORD12345";
cMsg.setHeader(xOrderIdHeadeName, xOrderIdHeadeValue);
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
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.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testOPTIONSWithPOSTMethods.
@Test(description = "Test dispatching with OPTIONS request with POST method")
public void testOPTIONSWithPOSTMethods() {
String path = "/options/post";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
Assert.assertEquals(StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), "");
Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200, "Response code mismatch");
String allowHeader = cMsg.getHeader(HttpHeaderNames.ALLOW.toString());
Assert.assertEquals(allowHeader, "POST, OPTIONS");
}
Aggregations