Search in sources :

Example 16 with UserException

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"));
}
Also used : ModelValidatorContext(org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext) Test(org.junit.Test)

Example 17 with UserException

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;
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 18 with UserException

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;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 19 with UserException

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"));
}
Also used : ValidationException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException) ModelValidatorContext(org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext) UserException(org.ow2.proactive.scheduler.common.exception.UserException) ValidationException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException) PatternSyntaxException(java.util.regex.PatternSyntaxException) Test(org.junit.Test)

Example 20 with UserException

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"));
}
Also used : ValidationException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException) ModelValidatorContext(org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext) UserException(org.ow2.proactive.scheduler.common.exception.UserException) ValidationException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException) PatternSyntaxException(java.util.regex.PatternSyntaxException) Test(org.junit.Test)

Aggregations

TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)16 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)7 Test (org.junit.Test)6 ModelValidatorContext (org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext)6 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)6 SimpleScript (org.ow2.proactive.scripting.SimpleScript)6 TaskScript (org.ow2.proactive.scripting.TaskScript)5 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)4 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 UserException (org.ow2.proactive.scheduler.common.exception.UserException)2 ValidationException (org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException)2 Task (org.ow2.proactive.scheduler.common.task.Task)2 TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)2 SelectionScript (org.ow2.proactive.scripting.SelectionScript)2 PropagateVariablesExec (functionaltests.executables.PropagateVariablesExec)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)1 EmptyTask (org.ow2.proactive.scheduler.examples.EmptyTask)1