use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidMapProperty.
@Test(expected = ConstraintValueDoNotMatchPropertyTypeException.class)
public void testInvalidMapProperty() throws Exception {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(ToscaTypes.MAP);
PropertyDefinition entrySchema = new PropertyDefinition();
entrySchema.setType(ToscaTypes.STRING);
propertyDefinition.setEntrySchema(entrySchema);
Object propertyValue = ImmutableList.builder().add("aa", "bb").build();
ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidFloatProperty.
@Test(expected = ConstraintValueDoNotMatchPropertyTypeException.class)
public void testInvalidFloatProperty() throws Exception {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(ToscaTypes.FLOAT);
ConstraintPropertyService.checkPropertyConstraint("test", "aaaa128", propertyDefinition);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ToscaPropertyTypeValidatorTest method invalidPropertyTypeShouldCreateViolations.
@Test
public void invalidPropertyTypeShouldCreateViolations() {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType("unknwon type");
Set<ConstraintViolation<PropertyDefinition>> violations = validator.validate(propertyDefinition);
Assert.assertEquals(1, violations.size());
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class MockOrchestratorFactory method getDeploymentPropertyDefinitions.
@Override
public Map<String, PropertyDefinition> getDeploymentPropertyDefinitions() {
// Field 1 : managerUrl as string
PropertyDefinition managerUrl = new PropertyDefinition();
managerUrl.setType(ToscaTypes.STRING.toString());
managerUrl.setRequired(true);
managerUrl.setDescription("PaaS manager URL");
managerUrl.setConstraints(null);
PatternConstraint manageUrlConstraint = new PatternConstraint();
manageUrlConstraint.setPattern("http://.+");
managerUrl.setConstraints(Arrays.asList((PropertyConstraint) manageUrlConstraint));
// Field 2 : number backup with constraint
PropertyDefinition numberBackup = new PropertyDefinition();
numberBackup.setType(ToscaTypes.INTEGER.toString());
numberBackup.setRequired(true);
numberBackup.setDescription("Number of backup");
numberBackup.setConstraints(null);
GreaterOrEqualConstraint greaterOrEqualConstraint = new GreaterOrEqualConstraint();
greaterOrEqualConstraint.setGreaterOrEqual(String.valueOf("1"));
numberBackup.setConstraints(Lists.newArrayList((PropertyConstraint) greaterOrEqualConstraint));
// Field 3 : email manager
PropertyDefinition managerEmail = new PropertyDefinition();
managerEmail.setType(ToscaTypes.STRING.toString());
managerEmail.setRequired(true);
managerEmail.setDescription("PaaS manager email");
managerEmail.setConstraints(null);
PatternConstraint managerEmailConstraint = new PatternConstraint();
managerEmailConstraint.setPattern(".+@.+");
managerEmail.setConstraints(Arrays.asList((PropertyConstraint) managerEmailConstraint));
deploymentProperties.put("managementUrl", managerUrl);
deploymentProperties.put("numberBackup", numberBackup);
deploymentProperties.put("managerEmail", managerEmail);
return deploymentProperties;
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien120Test method testDataTypesComplexWithDefault.
@Test
public void testDataTypesComplexWithDefault() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-data-types-complex-default.yml"));
ParserTestUtil.displayErrors(parsingResult);
Assert.assertEquals(2, parsingResult.getResult().getDataTypes().size());
Assert.assertEquals(2, parsingResult.getResult().getNodeTypes().size());
Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size());
NodeType commandType = parsingResult.getResult().getNodeTypes().get("alien.test.Command");
Assert.assertNotNull(commandType);
PropertyDefinition pd = commandType.getProperties().get("customer");
Assert.assertNotNull(pd);
// check the default value
Object defaultValue = pd.getDefault();
Assert.assertNotNull(defaultValue);
Assert.assertTrue(defaultValue instanceof ComplexPropertyValue);
ComplexPropertyValue cpv = (ComplexPropertyValue) defaultValue;
Map<String, Object> valueAsMap = cpv.getValue();
Assert.assertNotNull(valueAsMap);
Assert.assertTrue(valueAsMap.containsKey("first_name"));
Assert.assertEquals("Foo", valueAsMap.get("first_name"));
Assert.assertTrue(valueAsMap.containsKey("last_name"));
Assert.assertEquals("Bar", valueAsMap.get("last_name"));
Assert.assertEquals(1, parsingResult.getResult().getTopology().getNodeTemplates().size());
NodeTemplate nodeTemplate = parsingResult.getResult().getTopology().getNodeTemplates().values().iterator().next();
// on the node, the default value should be set
Assert.assertNotNull(nodeTemplate.getProperties());
Assert.assertTrue(nodeTemplate.getProperties().containsKey("customer"));
AbstractPropertyValue apv = nodeTemplate.getProperties().get("customer");
Assert.assertNotNull(apv);
Assert.assertTrue(apv instanceof ComplexPropertyValue);
cpv = (ComplexPropertyValue) apv;
valueAsMap = cpv.getValue();
Assert.assertNotNull(valueAsMap);
Assert.assertTrue(valueAsMap.containsKey("first_name"));
Assert.assertEquals("Foo", valueAsMap.get("first_name"));
Assert.assertTrue(valueAsMap.containsKey("last_name"));
Assert.assertEquals("Bar", valueAsMap.get("last_name"));
}
Aggregations