Search in sources :

Example 66 with HttpMessageDataStreamer

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

the class DataBindingTest method testDataBindingWithGlobalStruct.

@Test(description = "Test data binding with global custom struct")
public void testDataBindingWithGlobalStruct() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body6", "POST", "{'name':'wso2','age':12}");
    requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_JSON);
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_EP, requestMsg);
    Assert.assertNotNull(responseMsg, "responseMsg message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertEquals(bJson.value().get("Key").asText(), "wso2", "Key variable not set properly.");
    Assert.assertEquals(bJson.value().get("Age").asText(), "12", "Age 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 67 with HttpMessageDataStreamer

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

the class DataBindingTest method testDataBindingWhenPathParamExist.

@Test(description = "Test data binding when path param exists")
public void testDataBindingWhenPathParamExist() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body2/hello", "POST", "WSO2");
    requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), TEXT_PLAIN);
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_EP, requestMsg);
    Assert.assertNotNull(responseMsg, "responseMsg message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertEquals(bJson.value().get("Key").asText(), "hello", "Key variable not set properly.");
    Assert.assertEquals(bJson.value().get("Person").asText(), "WSO2", "Person 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 68 with HttpMessageDataStreamer

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

the class ProducesConsumesAnnotationTest method testWithoutProducesConsumeAnnotation.

@Test(description = "Test without Pro-Con annotation with URL. /echo67/echo1 ")
public void testWithoutProducesConsumeAnnotation() {
    String path = "/echo67/echo1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "text/plain; charset=ISO-8859-4");
    cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/*;q=0.3, text/html;Level=1;q=0.7");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo33").asText(), "echo1", "No media types");
}
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 69 with HttpMessageDataStreamer

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

the class ProducesConsumesAnnotationTest method testProducesAnnotation.

@Test(description = "Test Produces annotation with URL. /echo66/test2 ")
public void testProducesAnnotation() {
    String path = "/echo66/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/xml;q=0.3, multipart/*;Level=1;q=0.7");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("msg").asText(), "wso22", "media type matched");
}
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 70 with HttpMessageDataStreamer

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

the class ProducesConsumesAnnotationTest method testProducesAnnotationWithSubTypeWildCard.

@Test(description = "Test Produces with sub type wildcard header with URL. /echo66/test2 ")
public void testProducesAnnotationWithSubTypeWildCard() {
    String path = "/echo66/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/*;q=0.3, text/html;Level=1;q=0.7");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("msg").asText(), "wso22", "media type matched");
}
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)

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