Search in sources :

Example 1 with LengthConstraint

use of org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint in project alien4cloud by alien4cloud.

the class ToscaSerializerTest method getConstraintList.

private List<PropertyConstraint> getConstraintList() {
    List<PropertyConstraint> result = new ArrayList<PropertyConstraint>();
    ValidValuesConstraint c1 = new ValidValuesConstraint();
    c1.setValidValues(Lists.newArrayList("one", "two", "tree"));
    result.add(c1);
    GreaterOrEqualConstraint c2 = new GreaterOrEqualConstraint();
    c2.setGreaterOrEqual("2");
    result.add(c2);
    GreaterThanConstraint c3 = new GreaterThanConstraint();
    c3.setGreaterThan("3");
    result.add(c3);
    LessOrEqualConstraint c4 = new LessOrEqualConstraint();
    c4.setLessOrEqual("4");
    result.add(c4);
    LessThanConstraint c5 = new LessThanConstraint();
    c5.setLessThan("5");
    result.add(c5);
    LengthConstraint c6 = new LengthConstraint();
    c6.setLength(6);
    result.add(c6);
    MaxLengthConstraint c7 = new MaxLengthConstraint();
    c7.setMaxLength(7);
    result.add(c7);
    MinLengthConstraint c8 = new MinLengthConstraint();
    c8.setMinLength(8);
    result.add(c8);
    PatternConstraint c9 = new PatternConstraint();
    c9.setPattern("9+");
    result.add(c9);
    EqualConstraint c10 = new EqualConstraint();
    c10.setEqual("10");
    result.add(c10);
    InRangeConstraint c11 = new InRangeConstraint();
    c11.setInRange(Lists.newArrayList("11", "12"));
    result.add(c11);
    return result;
}
Also used : MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) LengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) GreaterOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.GreaterOrEqualConstraint) ArrayList(java.util.ArrayList) LessThanConstraint(org.alien4cloud.tosca.model.definitions.constraints.LessThanConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) LessOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.LessOrEqualConstraint) ValidValuesConstraint(org.alien4cloud.tosca.model.definitions.constraints.ValidValuesConstraint) GreaterThanConstraint(org.alien4cloud.tosca.model.definitions.constraints.GreaterThanConstraint) PatternConstraint(org.alien4cloud.tosca.model.definitions.constraints.PatternConstraint) InRangeConstraint(org.alien4cloud.tosca.model.definitions.constraints.InRangeConstraint) LessOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.LessOrEqualConstraint) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint) GreaterOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.GreaterOrEqualConstraint)

Example 2 with LengthConstraint

use of org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint in project alien4cloud by alien4cloud.

the class ConstraintPropertyServiceTest method testValidListProperty.

@Test
public void testValidListProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.LIST);
    PropertyDefinition entrySchema = new PropertyDefinition();
    entrySchema.setType(ToscaTypes.STRING);
    propertyDefinition.setEntrySchema(entrySchema);
    Object propertyValue = ImmutableList.builder().add("aa", "bb").build();
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
    // test length constraint
    LengthConstraint lengthConstraint = new LengthConstraint();
    lengthConstraint.setLength(2);
    List<PropertyConstraint> constraints = Lists.newArrayList();
    constraints.add(lengthConstraint);
    propertyDefinition.setConstraints(constraints);
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
    // test min_length constraint
    MinLengthConstraint minLengthConstraint = new MinLengthConstraint();
    minLengthConstraint.setMinLength(1);
    constraints.add(minLengthConstraint);
    propertyDefinition.setConstraints(constraints);
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
    // test max_length constraint
    MaxLengthConstraint maxLengthConstraint = new MaxLengthConstraint();
    maxLengthConstraint.setMaxLength(3);
    constraints.add(maxLengthConstraint);
    propertyDefinition.setConstraints(constraints);
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
}
Also used : LengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) Test(org.junit.Test)

Example 3 with LengthConstraint

use of org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint in project alien4cloud by alien4cloud.

the class ConstraintPropertyServiceTest method testInvalidFloatPropertyWithConstraint.

@Test(expected = ConstraintValueDoNotMatchPropertyTypeException.class)
public void testInvalidFloatPropertyWithConstraint() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setConstraints(new ArrayList<PropertyConstraint>());
    LengthConstraint lengthConstraint = new LengthConstraint();
    lengthConstraint.setLength(3);
    propertyDefinition.getConstraints().add(lengthConstraint);
    propertyDefinition.setType(ToscaTypes.FLOAT);
    ConstraintPropertyService.checkPropertyConstraint("test", "aaa", propertyDefinition);
}
Also used : LengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 4 with LengthConstraint

use of org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint in project alien4cloud by alien4cloud.

the class ConstraintPropertyServiceTest method testInvalidMapLengthConstraintProperty.

@Test(expected = ConstraintViolationException.class)
public void testInvalidMapLengthConstraintProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.MAP);
    PropertyDefinition entrySchema = new PropertyDefinition();
    entrySchema.setType(ToscaTypes.STRING);
    propertyDefinition.setEntrySchema(entrySchema);
    Object propertyValue = ImmutableMap.builder().put("aa", "bb").build();
    // invalid length constraint
    LengthConstraint lengthConstraint = new LengthConstraint();
    lengthConstraint.setLength(4);
    List<PropertyConstraint> constraints = Lists.newArrayList();
    constraints.add(lengthConstraint);
    propertyDefinition.setConstraints(constraints);
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
}
Also used : LengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 5 with LengthConstraint

use of org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint in project alien4cloud by alien4cloud.

the class ConstraintPropertyServiceTest method testInvalidStringConstraintProperty.

@Test(expected = ConstraintViolationException.class)
public void testInvalidStringConstraintProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.STRING);
    propertyDefinition.setConstraints(new ArrayList<PropertyConstraint>());
    LengthConstraint lengthConstraint = new LengthConstraint();
    lengthConstraint.setLength(3);
    propertyDefinition.getConstraints().add(lengthConstraint);
    ConstraintPropertyService.checkPropertyConstraint("test", "value", propertyDefinition);
}
Also used : LengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Aggregations

LengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint)10 MaxLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint)10 MinLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)10 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)8 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)7 Test (org.junit.Test)7 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)3 GreaterOrEqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.GreaterOrEqualConstraint)3 GreaterThanConstraint (org.alien4cloud.tosca.model.definitions.constraints.GreaterThanConstraint)3 InRangeConstraint (org.alien4cloud.tosca.model.definitions.constraints.InRangeConstraint)3 LessOrEqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.LessOrEqualConstraint)3 LessThanConstraint (org.alien4cloud.tosca.model.definitions.constraints.LessThanConstraint)3 PatternConstraint (org.alien4cloud.tosca.model.definitions.constraints.PatternConstraint)3 ValidValuesConstraint (org.alien4cloud.tosca.model.definitions.constraints.ValidValuesConstraint)3 FormPropertyDefinition (alien4cloud.ui.form.annotation.FormPropertyDefinition)1 FormDescriptorGenerationException (alien4cloud.ui.form.exception.FormDescriptorGenerationException)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)1 AbstractPropertyConstraint (org.alien4cloud.tosca.model.definitions.constraints.AbstractPropertyConstraint)1