Search in sources :

Example 6 with ScalarPropertyValue

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

the class ToscaTypeConverterTest method convert_version.

@Test
public void convert_version() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.VERSION);
    Object value = converter.toPropertyValue("3.4-SNAPSHOT", propertyDefinition);
    assertThat(value).isInstanceOf(ScalarPropertyValue.class);
    assertThat(value).isEqualTo(new ScalarPropertyValue("3.4-SNAPSHOT"));
}
Also used : ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 7 with ScalarPropertyValue

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

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

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

the class ToscaSerializerUtilsTest method testMapIsNotEmptyAndContainsNotnullValues.

@Test
public void testMapIsNotEmptyAndContainsNotnullValues() {
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(null));
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(Maps.newHashMap()));
    Map<String, Object> map = Maps.newHashMap();
    map.put("key1", null);
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(map));
    map.put("key2", "something");
    Assert.assertTrue(utils.mapIsNotEmptyAndContainsNotnullValues(map));
    // inner collection
    Map<String, Set<String>> mapOfSet = Maps.newHashMap();
    Set<String> set = Sets.newHashSet();
    mapOfSet.put("key1", set);
    // the set is empty
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfSet));
    Set<String> filledSet = Sets.newHashSet("something");
    mapOfSet.put("key2", filledSet);
    // the second set contains something
    Assert.assertTrue(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfSet));
    // inner map
    Map<String, Map<String, Set<String>>> mapOfmap = Maps.newHashMap();
    Map<String, Set<String>> innerMap = Maps.newHashMap();
    mapOfmap.put("key1", innerMap);
    // the inner map is empty
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfmap));
    Map<String, Set<String>> innerMap2 = Maps.newHashMap();
    Set<String> emptySet = Sets.newHashSet();
    innerMap2.put("key21", emptySet);
    mapOfmap.put("key2", innerMap2);
    // the inner set is empty
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfmap));
    filledSet = Sets.newHashSet("something");
    innerMap2.put("key22", filledSet);
    Assert.assertTrue(utils.mapIsNotEmptyAndContainsNotnullValues(mapOfmap));
    // ScalarPropertyValue
    ScalarPropertyValue spv = new ScalarPropertyValue();
    Map<String, AbstractPropertyValue> apvMap = new HashMap<String, AbstractPropertyValue>();
    apvMap.put("key1", spv);
    Assert.assertFalse(utils.mapIsNotEmptyAndContainsNotnullValues(apvMap));
    spv.setValue("value");
    Assert.assertTrue(utils.mapIsNotEmptyAndContainsNotnullValues(apvMap));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) HashMap(java.util.HashMap) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Test(org.junit.Test)

Example 10 with ScalarPropertyValue

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

the class ToscaSerializerTest method buildSamplePropertyValueMap.

private Map<String, AbstractPropertyValue> buildSamplePropertyValueMap() {
    Map<String, AbstractPropertyValue> result = new HashMap<String, AbstractPropertyValue>();
    result.put("prop1", new ScalarPropertyValue("value1"));
    FunctionPropertyValue fpv1 = new FunctionPropertyValue();
    fpv1.setFunction("get_property");
    fpv1.setParameters(Lists.newArrayList("p1", "p2"));
    result.put("prop2", fpv1);
    FunctionPropertyValue fpv2 = new FunctionPropertyValue();
    fpv2.setFunction("get_input");
    fpv2.setParameters(Lists.newArrayList("p1"));
    result.put("prop3", fpv2);
    result.put("prop4", null);
    result.put("prop5", new ScalarPropertyValue("a value containing a ["));
    result.put("prop6", new ScalarPropertyValue("a value containing a ]"));
    result.put("prop7", new ScalarPropertyValue("a value containing a {"));
    result.put("prop8", new ScalarPropertyValue("a value containing a }"));
    result.put("prop9", new ScalarPropertyValue("a value containing a :"));
    result.put("prop9", new ScalarPropertyValue("a value containing a \""));
    result.put("prop9", new ScalarPropertyValue("a value containing a : and a \""));
    result.put("prop10", new ScalarPropertyValue(" a value starting with a space"));
    result.put("prop11", new ScalarPropertyValue("a value ending with a space "));
    return result;
}
Also used : HashMap(java.util.HashMap) FunctionPropertyValue(org.alien4cloud.tosca.model.definitions.FunctionPropertyValue) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)37 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)14 Test (org.junit.Test)13 Map (java.util.Map)10 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)8 ListPropertyValue (org.alien4cloud.tosca.model.definitions.ListPropertyValue)8 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)7 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)7 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)7 HashMap (java.util.HashMap)5 List (java.util.List)5 Set (java.util.Set)5 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)4 ConstraintViolationException (org.alien4cloud.tosca.exceptions.ConstraintViolationException)4 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)4 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)4 Capability (org.alien4cloud.tosca.model.templates.Capability)4