use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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()));
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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()));
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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()));
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer 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.");
}
Aggregations