Search in sources :

Example 76 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqwithRestrictedMethodsResourceLevel.

@Test(description = "Test preflight with method restriction at resource level")
public void testPreFlightReqwithRestrictedMethodsResourceLevel() {
    String path = "/hello2/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.bbc.com");
    cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_DELETE);
    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 77 with HTTPTestRequest

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

the class HTTPCorsTest method testSimpleReqMultipleOrigins.

@Test(description = "Test simple request with multiple origins")
public void testSimpleReqMultipleOrigins() {
    String path = "/hello1/test3";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.wso2.com http://www.amazon.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(), "moreOrigins");
    Assert.assertEquals("http://www.wso2.com http://www.amazon.com", response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.toString()));
    Assert.assertEquals("true", 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 78 with HTTPTestRequest

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

the class HTTPCorsTest method testSimpleReqwithExtraWS.

@Test(description = "Test for values with extra white spaces")
public void testSimpleReqwithExtraWS() {
    String path = "/hello2/test1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "hello");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.facebook.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(), "resOnlyCors");
    Assert.assertEquals("http://www.facebook.com", response.getHeader(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN.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 79 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqwithMissingHeadersAtResourceLevel.

@Test(description = "Test preflight with missing headers at resource level")
public void testPreFlightReqwithMissingHeadersAtResourceLevel() {
    String path = "/hello2/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there");
    cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.bbc.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, "http://www.bbc.com", null, "X-PINGOTHER", "PUT", "-1");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 80 with HTTPTestRequest

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

the class HTTPCorsTest method testPreFlightReqServiceResourceCorsOverride.

@Test(description = "Test for CORS override at two levels with preflight")
public void testPreFlightReqServiceResourceCorsOverride() {
    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)

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