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