Search in sources :

Example 61 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.

the class RequestNativeFunctionSuccessTest method testServiceGetStringPayload.

@Test(description = "Test GetStringPayload function within a service")
public void testServiceGetStringPayload() {
    String value = "ballerina";
    String path = "/hello/GetStringPayload";
    List<Header> headers = new ArrayList<>();
    headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), TEXT_PLAIN));
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_POST, headers, value);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(ResponseReader.getReturnValue(response), value);
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Header(org.wso2.carbon.messaging.Header) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 62 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.

the class RequestNativeFunctionSuccessTest method testServiceAddHeader.

@Test(description = "Test addHeader function within a service")
public void testServiceAddHeader() {
    String key = "lang";
    String value = "ballerina";
    String path = "/hello/addheader/" + key + "/" + value;
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(ResponseReader.getReturnValue(response));
    Assert.assertEquals(bJson.value().get(key).asText(), value);
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 63 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.

the class RequestNativeFunctionSuccessTest method testServiceGetHeader.

@Test(description = "Test GetHeader function within a service")
public void testServiceGetHeader() {
    String path = "/hello/getHeader";
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    inRequestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_FORM);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("value").asText(), APPLICATION_FORM);
}
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) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 64 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.

the class RequestNativeFunctionSuccessTest method testServiceGetJsonPayload.

@Test(description = "Test GetJsonPayload function within a service")
public void testServiceGetJsonPayload() {
    String key = "lang";
    String value = "ballerina";
    String path = "/hello/getJsonPayload";
    String jsonString = "{\"" + key + "\":\"" + value + "\"}";
    List<Header> headers = new ArrayList<>();
    headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_JSON));
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_POST, headers, jsonString);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    Assert.assertEquals(new BJSON(ResponseReader.getReturnValue(response)).value().stringValue(), value);
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) Header(org.wso2.carbon.messaging.Header) ArrayList(java.util.ArrayList) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 65 with Within

use of org.wso2.siddhi.query.api.aggregation.Within in project ballerina by ballerina-lang.

the class RequestNativeFunctionSuccessTest method testServiceSetXmlPayload.

@Test(description = "Test SetXmlPayload function within a service")
public void testServiceSetXmlPayload() {
    String value = "Ballerina";
    String path = "/hello/SetXmlPayload/";
    HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_GET);
    HTTPCarbonMessage response = Services.invokeNew(serviceResult, MOCK_ENDPOINT_NAME, inRequestMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("lang").asText(), value);
}
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) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)135 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)101 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)100 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)90 TestUtil (org.wso2.siddhi.core.TestUtil)60 Event (org.wso2.siddhi.core.event.Event)37 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)28 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)27 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)23 BString (org.ballerinalang.model.values.BString)22 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)19 BJSON (org.ballerinalang.model.values.BJSON)18 ArrayList (java.util.ArrayList)8 ExecutorService (java.util.concurrent.ExecutorService)6 Expression (org.wso2.siddhi.query.api.expression.Expression)6 Map (java.util.Map)4 Semaphore (java.util.concurrent.Semaphore)4 Header (org.wso2.carbon.messaging.Header)4 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)4 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4