Services.get().destroy();
super.tearDown();
}
public void testFunctions() throws Exception {
XConfiguration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, "appPath");
conf.set(OozieClient.USER_NAME, "user");
conf.set("a", "A");
LiteWorkflowApp def =
new LiteWorkflowApp("name", "<workflow-app/>", new StartNodeDef("end")).addNode(new EndNodeDef("end"));
LiteWorkflowInstance job = new LiteWorkflowInstance(def, conf, "wfId");
WorkflowJobBean wf = new WorkflowJobBean();
wf.setId(job.getId());
wf.setAppName("name");
wf.setAppPath("appPath");
wf.setUser("user");
wf.setGroup("group");
wf.setWorkflowInstance(job);
wf.setRun(2);
wf.setProtoActionConf(conf.toXmlString());
WorkflowActionBean action = new WorkflowActionBean();
action.setId("actionId");
action.setName("actionName");
action.setErrorInfo("ec", "em");
action.setData("b=B");
action.setExternalId("ext");
action.setTrackerUri("tracker");
action.setExternalStatus("externalStatus");
ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
DagELFunctions.configureEvaluator(eval, wf, action);
assertEquals("wfId", eval.evaluate("${wf:id()}", String.class));
assertEquals("name", eval.evaluate("${wf:name()}", String.class));
assertEquals("appPath", eval.evaluate("${wf:appPath()}", String.class));
assertEquals("A", eval.evaluate("${wf:conf('a')}", String.class));
assertEquals("A", eval.evaluate("${a}", String.class));
assertEquals("user", eval.evaluate("${wf:user()}", String.class));
assertEquals("group", eval.evaluate("${wf:group()}", String.class));
assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("id=actionId"));
assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("status=XX"));
assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("status=XX"));
assertEquals(2, (int) eval.evaluate("${wf:run()}", Integer.class));
action.setStatus(WorkflowAction.Status.ERROR);
System.out.println("WorkflowInstance " + wf.getWorkflowInstance().getStatus().toString());
WorkflowInstance wfInstance = wf.getWorkflowInstance();
DagELFunctions.setActionInfo(wfInstance, action);
wf.setWorkflowInstance(wfInstance);
assertEquals("actionName", eval.evaluate("${wf:lastErrorNode()}", String.class));
assertEquals("ec", eval.evaluate("${wf:errorCode('actionName')}", String.class));
assertEquals("em", eval.evaluate("${wf:errorMessage('actionName')}", String.class));
assertEquals("B", eval.evaluate("${wf:actionData('actionName')['b']}", String.class));
String expected = XmlUtils.escapeCharsForXML("{\"b\":\"B\"}");
assertEquals(expected, eval.evaluate("${toJsonStr(wf:actionData('actionName'))}", String.class));
expected = XmlUtils.escapeCharsForXML("b=B");
assertTrue(eval.evaluate("${toPropertiesStr(wf:actionData('actionName'))}", String.class).contains(expected));
conf = new XConfiguration();
conf.set("b", "B");
expected = XmlUtils.escapeCharsForXML(XmlUtils.prettyPrint(conf).toString());
assertTrue(eval.evaluate("${toConfigurationStr(wf:actionData('actionName'))}", String.class).contains(expected));
assertEquals("ext", eval.evaluate("${wf:actionExternalId('actionName')}", String.class));
assertEquals("tracker", eval.evaluate("${wf:actionTrackerUri('actionName')}", String.class));