Search in sources :

Example 6 with SpelValidator

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator 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 7 with SpelValidator

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator 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 8 with SpelValidator

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator 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 9 with SpelValidator

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator 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 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 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)2 ModelSyntaxException (org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException)1 SpelValidator (org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator)1 ParseException (org.springframework.expression.ParseException)1