Search in sources :

Example 71 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class UriTemplateDispatcherTest method testEmptyStringResourcepath.

@Test(description = "Test empty string resource path")
public void testEmptyStringResourcepath() {
    String path = "/ecommerceservice/echo1";
    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("echo11").asText(), "echo11", "Resource dispatched to wrong template");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 72 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class UriTemplateDispatcherTest method testSpecialCharacterEscapedURI.

@Test(description = "Test dispatching with OPTIONS request with wildcard")
public void testSpecialCharacterEscapedURI() {
    String path = "/ech%5Bo14/ech%5Bo14/b%5Bar14";
    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("echo114").asText(), "b[ar14", "Resource dispatched to wrong template");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 73 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class UriTemplateDispatcherTest method testOPTIONSAtWrongRootPath.

@Test(description = "Test dispatching with OPTIONS request wrong Root")
public void testOPTIONSAtWrongRootPath() {
    String path = "/optionss";
    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 service found for path : /optionss");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 74 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class UriTemplateDispatcherTest method testValidUrlTemplateDispatching.

@Test(description = "Test accessing the variables parsed with URL. /products/{productId}/{regId}", dataProvider = "validUrl")
public void testValidUrlTemplateDispatching(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.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(xOrderIdHeadeName).asText(), xOrderIdHeadeValue, "Header value mismatched");
    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.");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 75 with HttpCarbonMessage

use of org.wso2.transport.http.netty.message.HttpCarbonMessage in project ballerina by ballerina-lang.

the class UriTemplateDispatcherTest method testOPTIONSWithMultiResources.

@Test(description = "Test dispatching with OPTIONS request multiple resources")
public void testOPTIONSWithMultiResources() {
    String path = "/options/test";
    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, "POST, UPDATE, GET, PUT, HEAD, OPTIONS");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Aggregations

HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)308 Test (org.testng.annotations.Test)247 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)233 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)179 BJSON (org.ballerinalang.model.values.BJSON)108 BString (org.ballerinalang.model.values.BString)45 BStruct (org.ballerinalang.model.values.BStruct)43 Request (org.wso2.msf4j.Request)34 ArrayList (java.util.ArrayList)25 BValue (org.ballerinalang.model.values.BValue)19 Header (org.wso2.carbon.messaging.Header)14 Tracer (org.ballerinalang.util.tracer.Tracer)11 HttpCarbonMessage (org.wso2.transport.http.netty.message.HttpCarbonMessage)10 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)9 IOException (java.io.IOException)8 ResponseCacheControlStruct (org.ballerinalang.net.http.caching.ResponseCacheControlStruct)7 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)5 Semaphore (java.util.concurrent.Semaphore)5 APIMgtSecurityException (org.wso2.carbon.apimgt.rest.api.common.exception.APIMgtSecurityException)5 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)4