Search in sources :

Example 21 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition 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 22 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition 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 23 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class ConstraintPropertyServiceTest method testValidIntegerProperty.

@Test
public void testValidIntegerProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.INTEGER);
    ConstraintPropertyService.checkPropertyConstraint("test", "128", propertyDefinition);
}
Also used : PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 24 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class ConstraintPropertyServiceTest method testValidVersionProperty.

@Test
public void testValidVersionProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.VERSION);
    ConstraintPropertyService.checkPropertyConstraint("test", "2.0", propertyDefinition);
    ConstraintPropertyService.checkPropertyConstraint("test", "1.0.0-SNAPSHOT", propertyDefinition);
}
Also used : PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 25 with PropertyDefinition

use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.

the class ConstraintPropertyServiceTest method testInvalidIntegerProperty.

// invalid value tests
@Test(expected = ConstraintValueDoNotMatchPropertyTypeException.class)
public void testInvalidIntegerProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.INTEGER);
    ConstraintPropertyService.checkPropertyConstraint("test", "aaaa128", propertyDefinition);
}
Also used : PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Aggregations

PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)101 Test (org.junit.Test)42 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)23 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)20 Map (java.util.Map)19 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeType (org.alien4cloud.tosca.model.types.NodeType)15 NotFoundException (alien4cloud.exception.NotFoundException)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)11 MinLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint)11 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)10 MaxLengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint)10 Capability (org.alien4cloud.tosca.model.templates.Capability)10 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)10 DataType (org.alien4cloud.tosca.model.types.DataType)9 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)8 Set (java.util.Set)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)8 LengthConstraint (org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint)8