use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException in project scheduling by ow2-proactive.
the class SpelValidator method validate.
@Override
public String validate(String parameterValue, ModelValidatorContext context) throws ValidationException {
try {
context.getSpELContext().setVariable("value", parameterValue);
Object untypedResult = spelExpression.getValue(context.getSpELContext());
if (!(untypedResult instanceof Boolean)) {
throw new ValidationException("SPEL expression did not return a boolean value.");
}
boolean evaluationResult = (Boolean) untypedResult;
if (!evaluationResult) {
throw new ValidationException("SPEL expression returned false, received " + parameterValue);
}
} catch (EvaluationException e) {
throw new ValidationException("SPEL expression raised an error: " + e.getMessage(), e);
}
return parameterValue;
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException in project scheduling by ow2-proactive.
the class SpelValidatorTest method testSpelOKUpdateTaskVariable.
@Test
public void testSpelOKUpdateTaskVariable() throws ValidationException, UserException {
SpelValidator validator = new SpelValidator("#value == 'MyString'?(variables['var1'] = 'toto1') instanceof T(String) : false");
String value = "MyString";
ModelValidatorContext context = new ModelValidatorContext(createTask());
Assert.assertEquals(value, validator.validate(value, context));
Assert.assertEquals("toto1", context.getSpELVariables().getVariables().get("var1"));
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException in project scheduling by ow2-proactive.
the class SpelValidatorTest method testSpelKO.
@Test(expected = ValidationException.class)
public void testSpelKO() throws ValidationException {
SpelValidator validator = new SpelValidator("#value == 'MyString'");
String value = "MyString123";
validator.validate(value, new ModelValidatorContext(new StandardEvaluationContext()));
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException in project scheduling by ow2-proactive.
the class SpelValidatorTest method testSpelOKUpdateJobVariableWhenEmptyOK.
@Test
public void testSpelOKUpdateJobVariableWhenEmptyOK() throws ValidationException, UserException {
SpelValidator validator = new SpelValidator("#value == 'MyString' ? (variables['var4'] == null ? (variables['var4'] = 'toto1') instanceof T(String) : true) : false");
String value = "MyString";
ModelValidatorContext context = new ModelValidatorContext(createJob());
Assert.assertEquals(value, validator.validate(value, context));
Assert.assertEquals("toto1", context.getSpELVariables().getVariables().get("var4"));
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException in project scheduling by ow2-proactive.
the class SpelValidatorTest method testSpelOKUpdateJobVariableWhenEmptyKO.
@Test
public void testSpelOKUpdateJobVariableWhenEmptyKO() throws ValidationException, UserException {
SpelValidator validator = new SpelValidator("#value == 'MyString' ? (variables['var2'] == null ? (variables['var2'] = 'toto1') instanceof T(String) : true) : false");
String value = "MyString";
ModelValidatorContext context = new ModelValidatorContext(createJob());
Assert.assertEquals(value, validator.validate(value, context));
Assert.assertEquals("value2", context.getSpELVariables().getVariables().get("var2"));
}
Aggregations