use of org.alien4cloud.tosca.model.definitions.PropertyConstraint 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;
}
use of org.alien4cloud.tosca.model.definitions.PropertyConstraint 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);
}
use of org.alien4cloud.tosca.model.definitions.PropertyConstraint 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);
}
use of org.alien4cloud.tosca.model.definitions.PropertyConstraint 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);
}
use of org.alien4cloud.tosca.model.definitions.PropertyConstraint 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);
}
Aggregations