use of org.alien4cloud.tosca.model.definitions.PropertyDefinition 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);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition 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.PropertyDefinition 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.PropertyDefinition 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.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidMapPropertyInComplex.
@Test(expected = ConstraintValueDoNotMatchPropertyTypeException.class)
public void testInvalidMapPropertyInComplex() throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
// given
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType("alien.test.ComplexStruct");
PropertyDefinition subPropertyDefinition = new PropertyDefinition();
subPropertyDefinition.setType(ToscaTypes.MAP);
PropertyDefinition entrySchema = new PropertyDefinition();
entrySchema.setType(ToscaTypes.STRING);
subPropertyDefinition.setEntrySchema(entrySchema);
DataType dataType = new DataType();
dataType.setProperties(Maps.newHashMap());
dataType.getProperties().put("myMap", subPropertyDefinition);
dataType.setElementId("alien.test.ComplexStruct");
ICSARRepositorySearchService originalCsarRepositorySearchService = ToscaContext.getCsarRepositorySearchService();
ToscaContext.init(new HashSet<>());
ICSARRepositorySearchService mockSearchService = Mockito.mock(ICSARRepositorySearchService.class);
Mockito.when(mockSearchService.getRequiredElementInDependencies(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(dataType);
Mockito.when(mockSearchService.getElementInDependencies(Mockito.any(), Mockito.any(), Mockito.anySet())).thenReturn(dataType);
try {
ToscaContext.setCsarRepositorySearchService(mockSearchService);
// when
Object propertyValue = ImmutableMap.builder().put("myMap", "aa").build();
// then -> ConstraintViolationException
ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
} finally {
ToscaContext.setCsarRepositorySearchService(originalCsarRepositorySearchService);
ToscaContext.destroy();
}
}
Aggregations