Search in sources :

Example 26 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.

the class ServiceTest method testGetFormParamsWithUnsupportedMediaType.

@Test(description = "Test GetFormParams with unsupported media type")
public void testGetFormParamsWithUnsupportedMediaType() {
    String path = "/echo/getFormParams";
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage(path, "POST", "firstName=WSO2&company=BalDance");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg, "responseMsg message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(responseMsg).getInputStream());
    Assert.assertNotNull(bJson);
    Assert.assertEquals(bJson.value().get("Name").asText(), "WSO2", "Name variable not set properly.");
    Assert.assertNull(bJson.value().get("Team").stringValue());
}
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 27 with Variable

use of org.wso2.siddhi.query.api.expression.Variable 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 28 with Variable

use of org.wso2.siddhi.query.api.expression.Variable 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)

Example 29 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.

the class DataBindingTest method testDataBindingWhenPathParamExist.

@Test(description = "Test data binding when path param exists")
public void testDataBindingWhenPathParamExist() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/body2/hello", "POST", "WSO2");
    requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), TEXT_PLAIN);
    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(), "hello", "Key variable not set properly.");
    Assert.assertEquals(bJson.value().get("Person").asText(), "WSO2", "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 30 with Variable

use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.

the class LSCustomErrorStrategy method setContextException.

@Override
protected void setContextException(Parser parser) {
    // Here the type of the exception is not important.
    InputMismatchException e = new InputMismatchException(parser);
    ParserRuleContext context = parser.getContext();
    // the run time
    if (context instanceof BallerinaParser.CallableUnitBodyContext) {
        context.exception = null;
        return;
    }
    context.exception = e;
    // We need to set the error for the variable definition as well.
    if (context.getParent() instanceof BallerinaParser.VariableDefinitionStatementContext) {
        context.getParent().exception = e;
        return;
    }
    if (context instanceof BallerinaParser.NameReferenceContext) {
        setContextIfConnectorInit(context, e);
    } else if (context instanceof BallerinaParser.ExpressionContext) {
        setContextIfConditionalStatement(context, e);
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) InputMismatchException(org.antlr.v4.runtime.InputMismatchException) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser)

Aggregations

RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)37 ArrayList (java.util.ArrayList)31 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)31 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)30 Test (org.testng.annotations.Test)28 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)26 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)26 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)26 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)23 BJSON (org.ballerinalang.model.values.BJSON)22 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)18 IOException (java.io.IOException)17 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)17 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)17 Variable (org.wso2.siddhi.query.api.expression.Variable)17 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)16 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)15 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)15 Response (javax.ws.rs.core.Response)14 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)13