ExcludeValuesAction extends AbstractSurvivorshipAction { @Override public boolean canHandle(ActionParameter actionParameter) { if (actionParameter.getExpression() == null) { return true; } ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("javascript"); try { if (actionParameter.getInputData() != null) { engine.put("inputData", actionParameter.getInputData()); Object eval = engine.eval("inputData.match(\"" + actionParameter.getExpression() + "\")"); return eval == null; } } catch (ScriptException e) { LOGGER.error(e.getMessage(), e); } return false; }  @Override boolean canHandle(ActionParameter actionParameter); static boolean checkUnexpectedValue(String valuesToExclude, Object inputData);  }
@Test public void testCheckCanHandle() { DataSet dataset = null; Object inputData = "Tony"; int rowNum = 0; String column = "firstName"; String ruleName = "rule1"; String expression = "Tony|Green"; boolean ignoreBlanks = false; ActionParameter actionParameter = new ActionParameter(dataset, inputData, rowNum, column, ruleName, expression, ignoreBlanks); ExcludeValuesAction exclusivenessAction = new ExcludeValuesAction(); boolean checkCanHandle = exclusivenessAction.canHandle(actionParameter); Assert.assertFalse("Tony is a constant value so that result should be false", checkCanHandle); actionParameter = new ActionParameter(dataset, inputData, rowNum, column, ruleName, expression, ignoreBlanks); inputData = "Tony1"; checkCanHandle = exclusivenessAction.canHandle(actionParameter); Assert.assertFalse("Tony1 is not a constant value so that result should be true", checkCanHandle); }