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);
}
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));
}
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));
}
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);
}
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"));
}
Aggregations