Search in sources :

Example 6 with ModelValidatorContext

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

Example 7 with ModelValidatorContext

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

Example 8 with ModelValidatorContext

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

Example 9 with ModelValidatorContext

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"));
}
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 10 with ModelValidatorContext

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"));
}
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

Test (org.junit.Test)8 ModelValidatorContext (org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext)8 ValidationException (org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 UserException (org.ow2.proactive.scheduler.common.exception.UserException)2 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)2 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)1 Task (org.ow2.proactive.scheduler.common.task.Task)1 TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)1 EvaluationException (org.springframework.expression.EvaluationException)1