Search in sources :

Example 6 with PropertyConstraint

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);
}
Also used : LessOrEqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.LessOrEqualConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 7 with PropertyConstraint

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);
}
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 8 with PropertyConstraint

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);
}
Also used : PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 9 with PropertyConstraint

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);
}
Also used : PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 10 with PropertyConstraint

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);
}
Also used : PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Aggregations

PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)30 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)18 Test (org.junit.Test)15 MinLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)11 MaxLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint)10 LengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint)8 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)5 ConstraintViolationException (org.alien4cloud.tosca.exceptions.ConstraintViolationException)4 GreaterThanConstraint (org.alien4cloud.tosca.model.definitions.constraints.GreaterThanConstraint)4 LessThanConstraint (org.alien4cloud.tosca.model.definitions.constraints.LessThanConstraint)4 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)3 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)3 GreaterOrEqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.GreaterOrEqualConstraint)3 LessOrEqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.LessOrEqualConstraint)3 PatternConstraint (org.alien4cloud.tosca.model.definitions.constraints.PatternConstraint)3 ValidValuesConstraint (org.alien4cloud.tosca.model.definitions.constraints.ValidValuesConstraint)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 NodeType (org.alien4cloud.tosca.model.types.NodeType)3 ConstraintInformation (alien4cloud.tosca.properties.constraints.ConstraintUtil.ConstraintInformation)2 IntrospectionException (java.beans.IntrospectionException)2