Search in sources :

Example 56 with HttpMessageDataStreamer

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

the class ServiceTest method testConstantValueAsAnnAttributeVal.

@Test(description = "Test using constant as annotation attribute value")
public void testConstantValueAsAnnAttributeVal() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/constantPath", "GET");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg);
    String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
    StringDataSource stringDataSource = new StringDataSource(responseMsgPayload);
    Assert.assertNotNull(stringDataSource);
    Assert.assertEquals(stringDataSource.getValue(), "constant path test");
}
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) StringDataSource(org.ballerinalang.runtime.message.StringDataSource) Test(org.testng.annotations.Test)

Example 57 with HttpMessageDataStreamer

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

the class ServiceTest method testGetString.

@Test(dependsOnMethods = "testSetString")
public void testGetString() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/getString", "GET");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg);
    String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertNotNull(responseMsgPayload);
    Assert.assertEquals(responseMsgPayload, "hello");
}
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 58 with HttpMessageDataStreamer

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

the class ServiceTest method testGetFormParamsNativeFunction.

@Test(description = "Test GetFormParams Native Function")
public void testGetFormParamsNativeFunction() {
    String path = "/echo/getFormParams";
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage(path, "POST", "firstName=WSO2&team=BalDance");
    requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_FORM);
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg, "responseMsg message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertEquals(bJson.value().get("Name").asText(), "WSO2", "Name variable not set properly.");
    Assert.assertEquals(bJson.value().get("Team").asText(), "BalDance", "Team 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 59 with HttpMessageDataStreamer

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

the class ServiceTest method testGetServiceLevelString.

@Test(description = "Test accessing service level variable in resource")
public void testGetServiceLevelString() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/getServiceLevelString", "GET");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg);
    String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
    StringDataSource stringDataSource = new StringDataSource(responseMsgPayload);
    Assert.assertNotNull(stringDataSource);
    Assert.assertEquals(stringDataSource.getValue(), "sample 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) StringDataSource(org.ballerinalang.runtime.message.StringDataSource) Test(org.testng.annotations.Test)

Example 60 with HttpMessageDataStreamer

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

the class ServiceTest method testGetFormParamsWithUnsupportedMediaType.

@Test(description = "Test GetFormParams with unsupported media type")
public void testGetFormParamsWithUnsupportedMediaType() {
    String path = "/echo/getFormParams";
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage(path, "POST", "firstName=WSO2&company=BalDance");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg, "responseMsg message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertNotNull(bJson);
    Assert.assertEquals(bJson.value().get("Name").asText(), "WSO2", "Name variable not set properly.");
    Assert.assertNull(bJson.value().get("Team").stringValue());
}
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