Search in sources :

Example 16 with PropertyDefinition

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

the class ToscaSerializerTest method simpleTest.

@Ignore
@Test
public void simpleTest() throws IOException, URISyntaxException {
    Topology topology = new Topology();
    topology.setDependencies(new HashSet<CSARDependency>());
    topology.getDependencies().add(new CSARDependency("name1", "1.0"));
    topology.getDependencies().add(new CSARDependency("name2", "2.0"));
    topology.setInputs(new HashMap<String, PropertyDefinition>());
    PropertyDefinition pd1 = new PropertyDefinition();
    pd1.setType("string");
    pd1.setConstraints(getConstraintList());
    pd1.setDescription("A description");
    topology.getInputs().put("input1", pd1);
    PropertyDefinition pd2 = new PropertyDefinition();
    pd2.setType("integer");
    pd2.setRequired(false);
    pd2.setDefault(new ScalarPropertyValue("10"));
    topology.getInputs().put("input2", pd2);
    PropertyDefinition pd3 = new PropertyDefinition();
    pd3.setType("map");
    pd3.setRequired(false);
    PropertyDefinition entrySchema = new PropertyDefinition();
    entrySchema.setType("integer");
    pd3.setEntrySchema(entrySchema);
    topology.getInputs().put("input3", pd3);
    topology.setNodeTemplates(new HashMap<String, NodeTemplate>());
    topology.getNodeTemplates().put("node1", new NodeTemplate());
    topology.getNodeTemplates().get("node1").setType("the.node.Type");
    topology.getNodeTemplates().get("node1").setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").setRelationships(new HashMap<String, RelationshipTemplate>());
    topology.getNodeTemplates().get("node1").getRelationships().put("hostedOn", new RelationshipTemplate());
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setTarget("compute2");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setRequirementType("capabilities.Capa");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setRequirementName("host");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setType("relationship.Rel");
    topology.getNodeTemplates().get("node1").getRelationships().get("hostedOn").setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").setCapabilities(new HashMap<String, Capability>());
    Capability capability = new Capability();
    capability.setProperties(buildSamplePropertyValueMap());
    topology.getNodeTemplates().get("node1").getCapabilities().put("capa1", capability);
    // this capability should not appear
    topology.getNodeTemplates().get("node1").getCapabilities().put("capa2", new Capability());
    topology.getNodeTemplates().get("node1").setArtifacts(new HashMap<String, DeploymentArtifact>());
    DeploymentArtifact da = new DeploymentArtifact();
    da.setArtifactName("artifact.war");
    da.setArtifactRef("010203904872876723");
    da.setArtifactType("artifacttypes.Artifact");
    topology.getNodeTemplates().get("node1").getArtifacts().put("artifact1", da);
    topology.setOutputProperties(new HashMap<String, Set<String>>());
    topology.getOutputProperties().put("node1", Sets.newHashSet("prop1", "prop2"));
    topology.setOutputAttributes(new HashMap<String, Set<String>>());
    topology.getOutputAttributes().put("node1", Sets.newHashSet("att1", "att2"));
    Map<String, Object> velocityCtx = new HashMap<String, Object>();
    velocityCtx.put("topology", topology);
    velocityCtx.put("template_name", "template-id");
    velocityCtx.put("template_version", "1.0.0-SNAPSHOT");
    velocityCtx.put("template_author", "Foo Bar");
    velocityCtx.put("application_description", "Here is a \nmultiline description");
    StringWriter writer = new StringWriter();
    VelocityUtil.generate("org/alien4cloud/tosca/exporter/topology-alien_dsl_1_4_0.yml.vm", writer, velocityCtx);
    System.out.println(writer.toString());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) HashMap(java.util.HashMap) Topology(org.alien4cloud.tosca.model.templates.Topology) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) StringWriter(java.io.StringWriter) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with PropertyDefinition

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

the class ConstraintPropertyServiceTest method testValidStringProperty.

// valid value tests
@Test
public void testValidStringProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.STRING);
    ConstraintPropertyService.checkPropertyConstraint("test", "value", propertyDefinition);
}
Also used : PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 18 with PropertyDefinition

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

the class ConstraintPropertyServiceTest method testValidListProperty.

@Test
public void testValidListProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.LIST);
    PropertyDefinition entrySchema = new PropertyDefinition();
    entrySchema.setType(ToscaTypes.STRING);
    propertyDefinition.setEntrySchema(entrySchema);
    Object propertyValue = ImmutableList.builder().add("aa", "bb").build();
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
    // test length constraint
    LengthConstraint lengthConstraint = new LengthConstraint();
    lengthConstraint.setLength(2);
    List<PropertyConstraint> constraints = Lists.newArrayList();
    constraints.add(lengthConstraint);
    propertyDefinition.setConstraints(constraints);
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
    // test min_length constraint
    MinLengthConstraint minLengthConstraint = new MinLengthConstraint();
    minLengthConstraint.setMinLength(1);
    constraints.add(minLengthConstraint);
    propertyDefinition.setConstraints(constraints);
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
    // test max_length constraint
    MaxLengthConstraint maxLengthConstraint = new MaxLengthConstraint();
    maxLengthConstraint.setMaxLength(3);
    constraints.add(maxLengthConstraint);
    propertyDefinition.setConstraints(constraints);
    ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
}
Also used : LengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.LengthConstraint) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) MinLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MinLengthConstraint) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) MaxLengthConstraint(org.alien4cloud.tosca.model.definitions.constraints.MaxLengthConstraint) Test(org.junit.Test)

Example 19 with PropertyDefinition

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

the class ConstraintPropertyServiceTest method testValidBooleanProperty.

@Test
public void testValidBooleanProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.BOOLEAN);
    ConstraintPropertyService.checkPropertyConstraint("test", "true", propertyDefinition);
    ConstraintPropertyService.checkPropertyConstraint("test", "false", propertyDefinition);
    ConstraintPropertyService.checkPropertyConstraint("test", "1", propertyDefinition);
    ConstraintPropertyService.checkPropertyConstraint("test", "0", propertyDefinition);
    ConstraintPropertyService.checkPropertyConstraint("test", "TRUE", propertyDefinition);
    ConstraintPropertyService.checkPropertyConstraint("test", "FALSE", propertyDefinition);
    // in fact anything can be used for boolean
    ConstraintPropertyService.checkPropertyConstraint("test", "anything", propertyDefinition);
}
Also used : PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 20 with PropertyDefinition

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

the class ConstraintPropertyServiceTest method testValidTimestampProperty.

@Test
public void testValidTimestampProperty() throws Exception {
    PropertyDefinition propertyDefinition = new PropertyDefinition();
    propertyDefinition.setType(ToscaTypes.TIMESTAMP);
    ConstraintPropertyService.checkPropertyConstraint("test", "2001-12-15T02:59:43.1Z", propertyDefinition);
}
Also used : PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) 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