Search in sources :

Example 26 with HttpMessageDataStreamer

use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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)

Example 27 with HttpMessageDataStreamer

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

the class ServiceEndpointTest method testGetProtocolConnectionStruct.

@Test(description = "Test the protocol value of ServiceEndpoint struct within a service")
public void testGetProtocolConnectionStruct() {
    String protocolValue = "http";
    String path = "/hello/protocol";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200);
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("protocol").asText(), protocolValue);
}
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 28 with HttpMessageDataStreamer

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

the class RequestNativeFunctionSuccessTest method testGetRequestURL.

@Test
public void testGetRequestURL() {
    String path = "/hello/12";
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), path);
}
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) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 29 with HttpMessageDataStreamer

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

the class RequestNativeFunctionSuccessTest method testServiceGetHeader.

@Test(description = "Test GetHeader function within a service")
public void testServiceGetHeader() {
    String path = "/hello/getHeader";
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    inRequestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_FORM);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("value").asText(), APPLICATION_FORM);
}
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) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 30 with HttpMessageDataStreamer

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

the class RequestNativeFunctionSuccessTest method testServiceSetXmlPayload.

@Test(description = "Test SetXmlPayload function within a service")
public void testServiceSetXmlPayload() {
    String value = "Ballerina";
    String path = "/hello/SetXmlPayload/";
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("lang").asText(), value);
}
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) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Aggregations

HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)176 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)172 Test (org.testng.annotations.Test)172 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)172 BJSON (org.ballerinalang.model.values.BJSON)104 BString (org.ballerinalang.model.values.BString)21 ArrayList (java.util.ArrayList)5 Header (org.wso2.carbon.messaging.Header)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 ExecutorService (java.util.concurrent.ExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BStruct (org.ballerinalang.model.values.BStruct)2 StringDataSource (org.ballerinalang.runtime.message.StringDataSource)2 MIMEPart (org.jvnet.mimepull.MIMEPart)2 EncoderException (io.netty.handler.codec.EncoderException)1 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1