Search in sources :

Example 46 with AbstractPropertyValue

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

the class FunctionEvaluatorTest method getEvaluationContext.

/**
 * Generate the topology below (no need type validations) and inputs to be used for next tests.
 *
 * @return A function evaluator context for the test topology.
 */
private FunctionEvaluatorContext getEvaluationContext() {
    NodeTemplate myNode = new NodeTemplate();
    myNode.setProperties(Maps.newHashMap());
    setPropertiesValues(myNode.getProperties(), "");
    Capability capability = new Capability();
    myNode.setCapabilities(Maps.newHashMap());
    myNode.getCapabilities().put("my_capability", capability);
    capability.setProperties(Maps.newHashMap());
    setPropertiesValues(capability.getProperties(), "capa ");
    Topology topology = new Topology();
    topology.setNodeTemplates(Maps.newHashMap());
    topology.getNodeTemplates().put("my_node", myNode);
    Map<String, AbstractPropertyValue> inputs = Maps.newHashMap();
    inputs.put("scalar_input", new ScalarPropertyValue("scalar input value"));
    return new FunctionEvaluatorContext(topology, inputs);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) Topology(org.alien4cloud.tosca.model.templates.Topology) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 47 with AbstractPropertyValue

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

the class ToscaSerializerUtilsTest method testHasCapabilitiesContainingNotNullProperties.

@Test
public void testHasCapabilitiesContainingNotNullProperties() {
    NodeTemplate nt = new NodeTemplate();
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    Map<String, Capability> capabilities = Maps.newHashMap();
    nt.setCapabilities(capabilities);
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    Capability capability1 = new Capability();
    capabilities.put("capa1", capability1);
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    Capability capability2 = new Capability();
    Map<String, AbstractPropertyValue> properties = new HashMap<String, AbstractPropertyValue>();
    capability2.setProperties(properties);
    capabilities.put("capa2", capability2);
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    properties.put("prop1", null);
    Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
    properties.put("prop2", new ScalarPropertyValue("value"));
    Assert.assertTrue(utils.hasCapabilitiesContainingNotNullProperties(nt));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) HashMap(java.util.HashMap) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Test(org.junit.Test)

Example 48 with AbstractPropertyValue

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

the class DeploymentTopologyStepDefinitions method assertNodePropertyValueEquals.

private void assertNodePropertyValueEquals(NodeTemplate node, String propertyName, String expectedPropertyValue) {
    assertNotNull(node);
    AbstractPropertyValue abstractProperty = MapUtils.getObject(node.getProperties(), propertyName);
    assertEquals(expectedPropertyValue, PropertyUtil.getScalarValue(abstractProperty));
}
Also used : AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 49 with AbstractPropertyValue

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

the class PropertyValueDeserializer method getNullValue.

@Override
public AbstractPropertyValue getNullValue(DeserializationContext ctxt) throws JsonMappingException {
    if (ctxt.getAttribute(ConditionalAttributes.REST) != null && RestMapper.PATCH.equals(RestMapper.REQUEST_OPERATION.get())) {
        try {
            AbstractPropertyValue instance = (AbstractPropertyValue) RestMapper.NULL_INSTANCES.get(ScalarPropertyValue.class);
            if (instance == null) {
                instance = ScalarPropertyValue.class.getConstructor().newInstance();
            }
            RestMapper.NULL_INSTANCES.put(ScalarPropertyValue.class, instance);
            return instance;
        } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
        }
    }
    return super.getNullValue(ctxt);
}
Also used : ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 50 with AbstractPropertyValue

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

AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)57 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)23 Map (java.util.Map)18 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)17 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)17 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)14 Capability (org.alien4cloud.tosca.model.templates.Capability)14 NotFoundException (alien4cloud.exception.NotFoundException)10 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)9 Test (org.junit.Test)8 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)7 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)7 NodeType (org.alien4cloud.tosca.model.types.NodeType)7 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)5 List (java.util.List)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)4 ListPropertyValue (org.alien4cloud.tosca.model.definitions.ListPropertyValue)4 HashMap (java.util.HashMap)3