use of org.ow2.proactive.scheduler.common.exception.UserException 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.exception.UserException in project scheduling by ow2-proactive.
the class SpelValidatorTest method createTask.
private Task createTask() throws UserException {
Task task = new JavaTask();
task.setVariables(ImmutableMap.of("var1", new TaskVariable("var1", "value1"), "var2", new TaskVariable("var2", "value2"), "var3", new TaskVariable("var3", ""), "var4", new TaskVariable("var4", null)));
task.setName("task1");
return task;
}
use of org.ow2.proactive.scheduler.common.exception.UserException in project scheduling by ow2-proactive.
the class SpelValidatorTest method createJob.
private TaskFlowJob createJob() throws UserException {
TaskFlowJob job = new TaskFlowJob();
job.setVariables(ImmutableMap.of("var1", new JobVariable("var1", "value1"), "var2", new JobVariable("var2", "value2"), "var3", new JobVariable("var3", ""), "var4", new JobVariable("var4", null)));
return job;
}
use of org.ow2.proactive.scheduler.common.exception.UserException 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.exception.UserException 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