use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testUrlTemplateWithMultipleQueryParamWithURIEncodeCharacterDispatching.
@Test(description = "Test dispatching with URL. /products?productId={productId}®ID={regID} " + "Ex: products?productID=PID%20123®ID=RID%201123")
public void testUrlTemplateWithMultipleQueryParamWithURIEncodeCharacterDispatching() {
String path = "/ecommerceservice/products?prodID=PID%20123®ID=RID%20123";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
// Expected Json message : {"X-ORDER-ID":"ORD12345","ProductID":"PID123","RegID":"RID123"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("Template").asText(), "T6", "Resource dispatched to wrong template");
Assert.assertEquals(bJson.value().get("ProductID").asText(), "PID 123", "ProductID variable not set properly.");
Assert.assertEquals(bJson.value().get("RegID").asText(), "RID 123", "RegID variable not set properly.");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testOPTIONSWhenNoResourcesAvailable.
@Test(description = "Test dispatching with OPTIONS request when no resources available")
public void testOPTIONSWhenNoResourcesAvailable() {
String path = "/noResource";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS");
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");
Assert.assertEquals(StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), "no matching resource found for path : /noResource , method : OPTIONS");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testValidUrlTemplateWithQueryParamDispatching.
@Test(description = "Test accessing the variables parsed with URL. /products/{productId}", dataProvider = "validUrlWithQueryParam")
public void testValidUrlTemplateWithQueryParamDispatching(String path) {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
// Expected Json message : {"X-ORDER-ID":"ORD12345","ProductID":"PID123","RegID":"RID123"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("Template").asText(), "T4", "Resource dispatched to wrong template");
Assert.assertEquals(bJson.value().get("ProductID").asText(), "PID123", "ProductID variable not set properly.");
Assert.assertEquals(bJson.value().get("RegID").asText(), "RID123", "RegID variable not set properly.");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testOPTIONSWithPUTMethods.
@Test(description = "Test dispatching with OPTIONS request with PUT method")
public void testOPTIONSWithPUTMethods() {
String path = "/options/put";
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 = response.getHeader(HttpHeaderNames.ALLOW.toString());
Assert.assertEquals(allowHeader, "PUT, OPTIONS");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testOPTIONSWithGETMethods.
@Test(description = "Test dispatching with OPTIONS request with GET method")
public void testOPTIONSWithGETMethods() {
String path = "/options/getme";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "hi");
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, "GET, HEAD, OPTIONS");
}
Aggregations