Search in sources :

Example 86 with PropertyDefinition

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

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

Example 88 with 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());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 89 with PropertyDefinition

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

Example 90 with PropertyDefinition

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"));
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) 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