Search in sources :

Example 81 with HTTPTestRequest

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

the class HTTPCorsTest method testSimpleReqInvalidOrigin.

@Test(description = "Test simple request for invalid origins")
public void testSimpleReqInvalidOrigin() {
    String path = "/hello1/test1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "www.wso2.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(), "resCors");
    Assert.assertEquals(null, response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()));
    Assert.assertNull(null, response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS.toString()));
}
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 82 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqwithUnavailableMethod.

@Test(description = "Test preflight with unavailable HTTP methods")
public void testPreFlightReqwithUnavailableMethod() {
    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_PUT);
    cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_HEADERS.toString(), "X-PINGOTHER");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    assertEqualsCorsResponse(response, 200, null, null, null, null, null);
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 83 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqwithHeadMethod.

@Test(description = "Test for preflight with Head as request method to a GET method annotated resource")
public void testPreFlightReqwithHeadMethod() {
    String path = "/hello1/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.m3.com");
    cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_HEAD);
    cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_HEADERS.toString(), "CORELATION_ID");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    assertEqualsCorsResponse(response, 200, "http://www.m3.com", "true", "CORELATION_ID", HttpConstants.HTTP_METHOD_HEAD, "1");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 84 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqwithNoMethod.

@Test(description = "Test preflight without Request Method header")
public void testPreFlightReqwithNoMethod() {
    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_HEADERS.toString(), "X-PINGOTHER");
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    assertEqualsCorsResponse(response, 200, null, null, null, null, null);
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 85 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqwithCaseInsensitiveOrigin.

@Test(description = "Test for case insensitive origin")
public void testPreFlightReqwithCaseInsensitiveOrigin() {
    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);
    HTTPCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg);
    Assert.assertNotNull(response);
    assertEqualsCorsResponse(response, 200, null, null, null, null, null);
}
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