Search in sources :

Example 86 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqwithCaseInsensitiveHeader.

@Test(description = "Test for case insensitive header")
public void testPreFlightReqwithCaseInsensitiveHeader() {
    String path = "/hello1/test1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.wso2.com");
    cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_POST);
    cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_HEADERS.toString(), "X-PINGOTHER");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    assertEqualsCorsResponse(response, 200, "http://www.wso2.com", "true", "X-PINGOTHER", "POST", "-1");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 87 with HTTPTestRequest

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

the class HTTPCorsTest method testSimpleReqServiceCors.

@Test(description = "Test for simple request service CORS")
public void testSimpleReqServiceCors() {
    String path = "/hello1/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.hello.com");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo").asText(), "serCors");
    Assert.assertEquals(response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()), "http://www.hello.com");
    Assert.assertEquals(response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString()), "true");
}
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 88 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqNoCorsResource.

@Test(description = "Test preflight without CORS headers")
public void testPreFlightReqNoCorsResource() {
    String path = "/echo4/info1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.wso2.com");
    cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_POST);
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    assertEqualsCorsResponse(response, 200, null, null, null, null, null);
    Assert.assertEquals(response.getHeader(HttpHeaderNames.ALLOW.toString()), "POST, OPTIONS");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 89 with HTTPTestRequest

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

the class DataBindingTest method testDataBindingWithoutPayload.

@Test(description = "Test data binding without a payload")
public void testDataBindingWithoutPayload() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body1", "GET");
    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("Person").asText(), "", "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 90 with HTTPTestRequest

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

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