Search in sources :

Example 1 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 testSpelOKUpdateTaskVariable.

@Test
public void testSpelOKUpdateTaskVariable() throws ValidationException, UserException {
    SpelValidator validator = new SpelValidator("#value == 'MyString'?(variables['var1'] = 'toto1') instanceof T(String) : false");
    String value = "MyString";
    ModelValidatorContext context = new ModelValidatorContext(createTask());
    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 2 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 testSpelKO.

@Test(expected = ValidationException.class)
public void testSpelKO() throws ValidationException {
    SpelValidator validator = new SpelValidator("#value == 'MyString'");
    String value = "MyString123";
    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 3 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 testSpelOKUpdateJobVariableWhenEmptyOK.

@Test
public void testSpelOKUpdateJobVariableWhenEmptyOK() throws ValidationException, UserException {
    SpelValidator validator = new SpelValidator("#value == 'MyString' ? (variables['var4'] == null ? (variables['var4'] = 'toto1') instanceof T(String) : true) : false");
    String value = "MyString";
    ModelValidatorContext context = new ModelValidatorContext(createJob());
    Assert.assertEquals(value, validator.validate(value, context));
    Assert.assertEquals("toto1", context.getSpELVariables().getVariables().get("var4"));
}
Also used : ModelValidatorContext(org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext) Test(org.junit.Test)

Example 4 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 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 5 with SpelValidator

use of org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator in project scheduling by ow2-proactive.

the class SPELParserValidator method createValidator.

@Override
protected Validator<String> createValidator(String model, Converter<String> converter) throws ModelSyntaxException {
    String spelRegexp = "^" + SPEL_TYPE_REGEXP + LEFT_DELIMITER_REGEXP + "(.+)" + RIGHT_DELIMITER_REGEXP + "$";
    String spelString = parseAndGetOneGroup(model, spelRegexp);
    try {
        return new SpelValidator(spelString);
    } catch (ParseException e) {
        throw new ModelSyntaxException(e.getMessage(), e);
    }
}
Also used : ModelSyntaxException(org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException) SpelValidator(org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.SpelValidator) ParseException(org.springframework.expression.ParseException)

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