use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testValidUrlTemplate5Dispatching.
@Test(description = "Test accessing the variables parsed with URL. /products5/{productId}/reg")
public void testValidUrlTemplate5Dispatching() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/ecommerceservice/products5/PID125/reg?regID=RID125¶1=value1", "GET");
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
// Expected Json message : {"Template":"T5","ProductID":"PID125","RegID":"RID125"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("Template").asText(), "T5", "Resource dispatched to wrong template");
Assert.assertEquals(bJson.value().get("ProductID").asText(), "PID125", "ProductID variable not set properly.");
Assert.assertEquals(bJson.value().get("RegID").asText(), "RID125", "RegID variable not set properly.");
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class UriTemplateDispatcherTest method testValidUrlTemplateDispatching.
@Test(description = "Test accessing the variables parsed with URL. /products/{productId}/{regId}", dataProvider = "validUrl")
public void testValidUrlTemplateDispatching(String path) {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
final String xOrderIdHeadeName = "X-ORDER-ID";
final String xOrderIdHeadeValue = "ORD12345";
cMsg.setHeader(xOrderIdHeadeName, xOrderIdHeadeValue);
HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
Assert.assertNotNull(response, "Response message not found");
// Expected Json message : {"X-ORDER-ID":"ORD12345","ProductID":"PID123","RegID":"RID123"}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get(xOrderIdHeadeName).asText(), xOrderIdHeadeValue, "Header value mismatched");
Assert.assertEquals(bJson.value().get("ProductID").asText(), "PID123", "ProductID variable not set properly.");
Assert.assertEquals(bJson.value().get("RegID").asText(), "RID123", "RegID variable not set properly.");
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class ServiceTest method testGetFormParamsForUndefinedKey.
@Test(description = "Test GetFormParams with undefined key")
public void testGetFormParamsForUndefinedKey() {
String path = "/echo/getFormParams";
HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage(path, "POST", "firstName=WSO2&company=BalDance");
requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_FORM);
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.assertTrue(bJson.value().get("Team").isNull(), "Team variable not set properly.");
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class ServiceTest method testGetFormParamsNativeFunction.
@Test(description = "Test GetFormParams Native Function")
public void testGetFormParamsNativeFunction() {
String path = "/echo/getFormParams";
HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage(path, "POST", "firstName=WSO2&team=BalDance");
requestMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), APPLICATION_FORM);
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.assertEquals(bJson.value().get("Name").asText(), "WSO2", "Name variable not set properly.");
Assert.assertEquals(bJson.value().get("Team").asText(), "BalDance", "Team variable not set properly.");
}
use of org.wso2.siddhi.query.api.expression.Variable in project ballerina by ballerina-lang.
the class ServiceTest method testGetServiceLevelString.
@Test(description = "Test accessing service level variable in resource")
public void testGetServiceLevelString() {
HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/getServiceLevelString", "GET");
HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
Assert.assertNotNull(responseMsg);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
StringDataSource stringDataSource = new StringDataSource(responseMsgPayload);
Assert.assertNotNull(stringDataSource);
Assert.assertEquals(stringDataSource.getValue(), "sample value");
}
Aggregations