@Override public void start() throws InitialisationException { ValidationResult result = this.expressionManager.validate(expression); if (!result.isSuccess()) { throw new InvalidExpressionException(expression, result.errorMessage().orElse("Invalid exception")); } latch = new CountDownLatch(count); addAssertion(getRootContainerLocation().toString(), this); }
@Before public void initialise() { when(mockEvent.getMessage()).thenReturn(muleMessage); expressionManager = mock(ExtendedExpressionManager.class); when(expressionManager.isValid(anyString())).thenReturn(true); when(expressionManager.validate(anyString())).thenReturn(success()); when(expressionManager.evaluateBoolean(eq(TRUE_EXPRESSION), any(CoreEvent.class), any(ComponentLocation.class), anyBoolean(), anyBoolean())) .thenReturn(true); when(expressionManager.evaluateBoolean(eq(FALSE_EXPRESSION), any(CoreEvent.class), any(ComponentLocation.class), anyBoolean(), anyBoolean())) .thenReturn(false); when(muleContext.getExpressionManager()).thenReturn(expressionManager); flowConstruct = mock(FlowConstruct.class); when(flowConstruct.getMuleContext()).thenReturn(muleContext); when(flowConstruct.getName()).thenReturn("MockedFlowConstruct"); }
if (valid.get()) { ValidationResult result = expressionLanguage.validate(token); if (!result.isSuccess()) { valid.compareAndSet(true, false); message.append(token).append(" is invalid\n"); message.append(result.errorMessage().orElse("")); return failure(e.getMessage(), expression); return failure(message.toString()); return success();
@Test public void testValidate() { assertThat(validate("2*2").isSuccess(), is(true)); }
@Override public ValidationResult validate(String expression) { if (expression.startsWith(DEFAULT_EXPRESSION_PREFIX)) { if (!expression.endsWith(DEFAULT_EXPRESSION_POSTFIX)) { return failure("Expression string is not an expression", expression); } expression = expression.substring(2, expression.length() - 1); } try { expressionExecutor.validate(expression); } catch (CompileException e) { return failure(e.getMessage(), expression); } return success(); }
@Test public void testValidateInvalid() { assertThat(validate("2*'2").isSuccess(), is(false)); }
@Override public void start() throws InitialisationException { super.start(); ValidationResult result = this.expressionManager.validate(responseExpression); if (!result.isSuccess()) { throw new InvalidExpressionException(expression, result.errorMessage().orElse("Invalid expression")); } responseLatch = new CountDownLatch(responseCount); addAssertion(getLocation().getRootContainerName(), this); }
@Override public boolean isValid(String expression) { return validate(expression).isSuccess(); }
@Before public void initialise() { when(mockEvent.getMessage()).thenReturn(muleMessage); expressionManager = mock(ExtendedExpressionManager.class); when(expressionManager.isValid(anyString())).thenReturn(true); when(expressionManager.validate(anyString())).thenReturn(success()); when(expressionManager.evaluateBoolean(eq(TRUE_EXPRESSION), any(CoreEvent.class), any(ComponentLocation.class), anyBoolean(), anyBoolean())) .thenReturn(true); when(expressionManager.evaluateBoolean(eq(FALSE_EXPRESSION), any(CoreEvent.class), any(ComponentLocation.class), anyBoolean(), anyBoolean())) .thenReturn(false); when(muleContext.getExpressionManager()).thenReturn(expressionManager); flowConstruct = mock(FlowConstruct.class); when(flowConstruct.getMuleContext()).thenReturn(muleContext); when(flowConstruct.getName()).thenReturn("MockedFlowConstruct"); }
public void validate(Object expression) { // TODO shouldn't this be private if (expression instanceof String) { ValidationResult validationResult = expressionManager.validate((String) expression); if (!validationResult.isSuccess()) { throw new MunitError( "Expression parsing failed. The expression: '" + expression + "' is invalid - " + validationResult .errorMessage()); } } else { throw new MunitError("Expression parsing failed. The expression: '" + expression + "' is invalid (not a string)"); } }
@Test public void testValidate() { assertThat(validate("2*2").isSuccess(), is(true)); }
@Test public void testValidateInvalid() { assertThat(validate("2*'2").isSuccess(), is(false)); }