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());
}
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.");
}
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.");
}
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.");
}
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);
}
}
Aggregations