use of org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext 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"));
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext in project scheduling by ow2-proactive.
the class SpelValidatorTest method testSpelOK.
@Test
public void testSpelOK() throws ValidationException {
SpelValidator validator = new SpelValidator("#value == 'MyString'");
String value = "MyString";
Assert.assertEquals(value, validator.validate(value, new ModelValidatorContext(new StandardEvaluationContext())));
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext in project scheduling by ow2-proactive.
the class SpelValidatorTest method testSpelOKUpdateJobVariable.
@Test
public void testSpelOKUpdateJobVariable() throws ValidationException, UserException {
SpelValidator validator = new SpelValidator("#value == 'MyString'?(variables['var1'] = 'toto1') instanceof T(String):false");
String value = "MyString";
ModelValidatorContext context = new ModelValidatorContext(createJob());
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.ModelValidatorContext in project scheduling by ow2-proactive.
the class SpelValidatorTest method testSpelKOUpdateTaskVariable.
@Test
public void testSpelKOUpdateTaskVariable() throws ValidationException, UserException {
SpelValidator validator = new SpelValidator("#value == 'MyString'?(variables['var1'] = 'toto1') instanceof T(String) : false");
String value = "MyString123";
ModelValidatorContext context = new ModelValidatorContext(createTask());
try {
validator.validate(value, context);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e instanceof ValidationException);
}
Assert.assertEquals("value1", context.getSpELVariables().getVariables().get("var1"));
}
use of org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext in project scheduling by ow2-proactive.
the class SpelValidatorTest method testSpelKOUpdateJobVariable.
@Test
public void testSpelKOUpdateJobVariable() throws ValidationException, UserException {
SpelValidator validator = new SpelValidator("#value == 'MyString'?(variables['var1'] = 'toto1') instanceof T(String):false");
String value = "MyString123";
ModelValidatorContext context = new ModelValidatorContext(createJob());
try {
validator.validate(value, context);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e instanceof ValidationException);
}
Assert.assertEquals("value1", context.getSpELVariables().getVariables().get("var1"));
}
Aggregations