use of org.alien4cloud.tosca.model.definitions.PropertyConstraint in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidConstraintProperty.
@Test(expected = ConstraintValueDoNotMatchPropertyTypeException.class)
public void testInvalidConstraintProperty() 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
LessOrEqualConstraint lengthConstraint = new LessOrEqualConstraint();
lengthConstraint.setLessOrEqual("aa");
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 testValidStringConstraintProperty.
// constraint test
@Test
public void testValidStringConstraintProperty() 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", "val", propertyDefinition);
}
use of org.alien4cloud.tosca.model.definitions.PropertyConstraint in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidMapMinLengthConstraintProperty.
@Test(expected = ConstraintViolationException.class)
public void testInvalidMapMinLengthConstraintProperty() 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
MinLengthConstraint lengthConstraint = new MinLengthConstraint();
lengthConstraint.setMinLength(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 PropertyDefinitionConstraintsTest method testCheckIfCompatibleOrFailConstraintNotSatisfiedSetOfScamblePropertyConstraintWithDifferentType.
@Test(expected = IncompatiblePropertyDefinitionException.class)
public void testCheckIfCompatibleOrFailConstraintNotSatisfiedSetOfScamblePropertyConstraintWithDifferentType() throws ConstraintViolationException, IncompatiblePropertyDefinitionException {
PropertyDefinition propDef1 = new PropertyDefinition();
PropertyDefinition propDef2 = new PropertyDefinition();
List<PropertyConstraint> constraintsProp1 = Lists.newArrayList();
List<PropertyConstraint> constraintsProp2 = Lists.newArrayList();
propDef1.setType(ToscaTypes.STRING);
propDef2.setType(ToscaTypes.INTEGER);
EqualConstraint constraint1 = new EqualConstraint();
constraint1.setEqual("test");
InRangeConstraint constraint1Bis = new InRangeConstraint();
constraint1Bis.setRangeMaxValue("4");
LessThanConstraint constraint2 = new LessThanConstraint();
constraint2.setLessThan("5");
constraintsProp1.add(constraint1);
constraintsProp1.add(constraint2);
constraintsProp2.add(constraint2);
constraintsProp2.add(constraint1Bis);
propDef1.setConstraints(constraintsProp1);
propDef2.setConstraints(constraintsProp2);
propDef1.checkIfCompatibleOrFail(propDef2);
}
use of org.alien4cloud.tosca.model.definitions.PropertyConstraint in project alien4cloud by alien4cloud.
the class PropertyDefinitionConstraintsTest method testCheckIfCompatibleOrFailConstraintNotSatisfiedNull.
@Test(expected = IncompatiblePropertyDefinitionException.class)
public void testCheckIfCompatibleOrFailConstraintNotSatisfiedNull() throws ConstraintViolationException, IncompatiblePropertyDefinitionException {
PropertyDefinition propDef1 = new PropertyDefinition();
PropertyDefinition propDef2 = new PropertyDefinition();
propDef1.setType(ToscaTypes.STRING);
propDef2.setType(ToscaTypes.STRING);
List<PropertyConstraint> constraints = Lists.newArrayList();
constraints.add(new EqualConstraint());
propDef1.setConstraints(constraints);
EqualConstraint constraint = new EqualConstraint();
constraint.setEqual("test");
constraints.add(constraint);
propDef1.setConstraints(constraints);
propDef1.checkIfCompatibleOrFail(propDef2);
}
Aggregations