Search in sources :

Example 11 with PropertyDefinition

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

the class ToscaTypeConverterTest method convert_complex_data_type_to_property_value.

@Test
public void convert_complex_data_type_to_property_value() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType("alien.nodes.test.ComplexDataType");
    PropertyValue propertyValue = converter.toPropertyValue(ImmutableMap.of("nested", "nested value", "nested_array", Arrays.asList("item1", "item2", "item3"), "nested_map", ImmutableMap.of("key1", "value1", "key2", "value2")), propertyDefinition);
    assertThat(propertyValue).isInstanceOf(ComplexPropertyValue.class);
    ComplexPropertyValue complexPropertyValue = (ComplexPropertyValue) propertyValue;
    assertThat(complexPropertyValue.getValue().get("nested_map")).isEqualTo(ImmutableMap.of("key1", "value1", "key2", "value2"));
    assertThat(complexPropertyValue.getValue().get("nested_array")).isEqualTo(Arrays.asList("item1", "item2", "item3"));
    assertThat(complexPropertyValue.getValue().get("nested")).isEqualTo("nested value");
}
Also used : ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) ComplexPropertyValue(org.alien4cloud.tosca.model.definitions.ComplexPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 12 with PropertyDefinition

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

the class ToscaTypeConverterTest method findDataType.

@SneakyThrows
private static DataType findDataType(Class<? extends DataType> concreteType, String id) {
    switch(id) {
        case "alien.nodes.test.ComplexDataType":
            DataType dataType = new DataType();
            Map<String, PropertyDefinition> propertyDefinitionMap = Maps.newHashMap();
            new PropertyDefinition();
            propertyDefinitionMap.put("nested", buildPropDef("string"));
            propertyDefinitionMap.put("nested_array", buildPropDef("list", "string"));
            propertyDefinitionMap.put("nested_map", buildPropDef("map", "string"));
            dataType.setProperties(propertyDefinitionMap);
            dataType.setElementId("alien.nodes.test.ComplexDataType");
            return dataType;
        default:
            return null;
    }
}
Also used : DataType(org.alien4cloud.tosca.model.types.DataType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) SneakyThrows(lombok.SneakyThrows)

Example 13 with PropertyDefinition

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

the class ToscaPropertyDefaultValueConstraintsValidatorTest method createDefinitions.

private PropertyDefinition createDefinitions(String propertyType, PropertyConstraint constraint, String defaultValue) {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(propertyType);
    propertyDefinition.setDefault(new ScalarPropertyValue(defaultValue));
    propertyDefinition.setConstraints(Lists.newArrayList(constraint));
    return propertyDefinition;
}
Also used : ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 14 with PropertyDefinition

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

the class ToscaPropertyDefaultValueTypeValidatorTest method createDefinitions.

private PropertyDefinition createDefinitions(String propertyType, String defaultValue) {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(propertyType);
    propertyDefinition.setDefault(new ScalarPropertyValue(defaultValue));
    return propertyDefinition;
}
Also used : ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 15 with PropertyDefinition

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

the class ToscaPropertyTypeValidatorTest method createDefinitions.

private PropertyDefinition createDefinitions() {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.STRING.toString());
    return propertyDefinition;
}
Also used : PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

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