Search in sources :

Example 96 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testBogusConsumesAnnotation.

@Test(description = "Test bogus Consumes annotation with URL. /echo66/test1 ")
public void testBogusConsumesAnnotation() {
    String path = "/echo66/test1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
    cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), ",:vhjv");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    int trueResponse = (int) response.getProperty(HttpConstants.HTTP_STATUS_CODE);
    Assert.assertEquals(trueResponse, 415, "Unsupported media type");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 97 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest 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)

Example 98 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testProducesConsumeAnnotation.

@Test(description = "Test Produces and Consumes with URL. /echo66/test3 ")
public void testProducesConsumeAnnotation() {
    String path = "/echo66/test3";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
    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("msg").asText(), "wso222", "media types 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 99 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testProducesAnnotationWithWildCard.

@Test(description = "Test Produces with wildcard header with URL. /echo66/test2 ")
public void testProducesAnnotationWithWildCard() {
    String path = "/echo66/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "*/*, 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)

Example 100 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testIncorrectProducesConsumeAnnotation.

@Test(description = "Test Incorrect Produces and Consumes with URL. /echo66/test3 ")
public void testIncorrectProducesConsumeAnnotation() {
    String path = "/echo66/test3";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
    cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "text/plain ; charset=ISO-8859-4");
    cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "compileResult/xml, text/html");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    int trueResponse = (int) response.getProperty(HttpConstants.HTTP_STATUS_CODE);
    Assert.assertEquals(trueResponse, 406, "Not acceptable");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Aggregations

HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)243 Test (org.testng.annotations.Test)241 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)233 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)172 BJSON (org.ballerinalang.model.values.BJSON)108 BString (org.ballerinalang.model.values.BString)32 ArrayList (java.util.ArrayList)26 BStruct (org.ballerinalang.model.values.BStruct)16 Header (org.wso2.carbon.messaging.Header)15 InputStream (java.io.InputStream)4 ExecutorService (java.util.concurrent.ExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BValue (org.ballerinalang.model.values.BValue)2 BXMLItem (org.ballerinalang.model.values.BXMLItem)2 RequestCacheControlStruct (org.ballerinalang.net.http.caching.RequestCacheControlStruct)2 StringDataSource (org.ballerinalang.runtime.message.StringDataSource)2