use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testParseTopologyReferenceToNormative.
@Test
public void testParseTopologyReferenceToNormative() throws FileNotFoundException, ParsingException {
Csar csar = new Csar("tosca-normative-types", "1.0.0.wd03-SNAPSHOT");
NodeType mockedCompute = getMockedCompute();
NodeType mockedSoftware = getMockedSoftwareComponent();
CapabilityType mockedContainer = Mockito.mock(CapabilityType.class);
Mockito.when(mockedContainer.getElementId()).thenReturn("tosca.capabilities.Container");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedSoftware);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedContainer);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedCompute);
RelationshipType hostedOn = new RelationshipType();
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-node-from-derived-type-from-import.yml"));
Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
assertNoBlocker(parsingResult);
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testCapabilities.
@Test
public void testCapabilities() throws ParsingException {
NodeType mockedResult = Mockito.mock(NodeType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
CapabilityType mockedCapabilityResult = Mockito.mock(CapabilityType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Endpoint"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
RelationshipType connectsTo = new RelationshipType();
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.ConnectsTo"), Mockito.any(Set.class))).thenReturn(connectsTo);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "requirement_capabilities.yaml"));
ParserTestUtil.displayErrors(parsingResult);
parsingResult.getResult().getNodeTypes().values().forEach(nodeType -> {
nodeType.getRequirements().forEach(requirementDefinition -> {
switch(requirementDefinition.getId()) {
case "host":
Assert.assertEquals("tosca.capabilities.Container", requirementDefinition.getType());
break;
case "endpoint":
case "another_endpoint":
Assert.assertEquals("tosca.capabilities.Endpoint", requirementDefinition.getType());
Assert.assertEquals(0, requirementDefinition.getLowerBound());
Assert.assertEquals(Integer.MAX_VALUE, requirementDefinition.getUpperBound());
Assert.assertEquals("tosca.relationships.ConnectsTo", requirementDefinition.getRelationshipType());
break;
}
});
nodeType.getCapabilities().forEach(capabilityDefinition -> {
switch(capabilityDefinition.getId()) {
case "host":
Assert.assertEquals("tosca.capabilities.Container", capabilityDefinition.getType());
break;
case "endpoint":
case "another_endpoint":
Assert.assertEquals("tosca.capabilities.Endpoint", capabilityDefinition.getType());
assertNotNull(capabilityDefinition.getDescription());
}
});
});
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method getMockedSoftwareComponent.
private NodeType getMockedSoftwareComponent() {
NodeType mockedSoftware = new NodeType();
mockedSoftware.setArchiveName("tosca-normative-types");
mockedSoftware.setArchiveVersion("1.0.0.wd03-SNAPSHOT");
RequirementDefinition hostRequirement = new RequirementDefinition("host", "tosca.capabilities.Container", null, "", "tosca.relationships.HostedOn", "host", 1, Integer.MAX_VALUE, null);
mockedSoftware.setRequirements(Lists.<RequirementDefinition>newArrayList(hostRequirement));
mockedSoftware.setElementId("tosca.nodes.SoftwareComponent");
return mockedSoftware;
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testParseTopologyWithWorkflows.
@Test
public void testParseTopologyWithWorkflows() throws FileNotFoundException, ParsingException {
Csar csar = new Csar("tosca-normative-types", "1.0.0.wd03-SNAPSHOT");
NodeType mockedCompute = getMockedCompute();
NodeType mockedSoftware = getMockedSoftwareComponent();
CapabilityType mockedContainer = Mockito.mock(CapabilityType.class);
Mockito.when(mockedContainer.getElementId()).thenReturn("tosca.capabilities.Container");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedSoftware);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedContainer);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedCompute);
RelationshipType hostedOn = Mockito.mock(RelationshipType.class);
Mockito.when(hostedOn.getElementId()).thenReturn("tosca.relationships.HostedOn");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflows.yml"));
Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
assertNoBlocker(parsingResult);
Assert.assertEquals(3, parsingResult.getContext().getParsingErrors().size());
assertNotNull(parsingResult.getResult().getTopology());
Assert.assertEquals(5, parsingResult.getResult().getTopology().getWorkflows().size());
// check invalid names were renamed
assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalidName_"));
assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalid_Name"));
assertTrue(parsingResult.getResult().getTopology().getWorkflows().containsKey("invalid_Name_1"));
}
use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testAttributesConcatValid.
@SuppressWarnings("unchecked")
@Test
public void testAttributesConcatValid() throws Throwable {
Csar csar = new Csar("tosca-normative-types", "1.0.0-SNAPSHOT-wd03");
// Mockito.when(csarRepositorySearchService.getArchive(csar.getId())).thenReturn(csar);
NodeType mockedResult = Mockito.mock(NodeType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getId()).thenReturn("tosca.nodes.Compute:1.0.0-SNAPSHOT-wd03");
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-node-type-inputs.yml"));
Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
// check nodetype elements
Entry<String, NodeType> entry = archiveRoot.getNodeTypes().entrySet().iterator().next();
Assert.assertEquals("alien.test.TestComputeConcat", entry.getKey());
NodeType nodeType = entry.getValue();
nodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
Map<String, IValue> attributes = nodeType.getAttributes();
IValue simpleDefinition = attributes.get("simple_definition");
IValue ipAddressDefinition = attributes.get("ip_address");
IValue simpleConcat = attributes.get("simple_concat");
IValue complexConcat = attributes.get("complex_concat");
// check attributes types
assertTrue(simpleDefinition.getClass().equals(AttributeDefinition.class));
assertTrue(ipAddressDefinition.getClass().equals(AttributeDefinition.class));
assertTrue(simpleConcat.getClass().equals(ConcatPropertyValue.class));
assertTrue(complexConcat.getClass().equals(ConcatPropertyValue.class));
// Test nodeType serialization
String nodeTypeJson = JsonUtil.toString(nodeType);
// recover node from serialized string
NodeType nodeTypeDeserialized = JsonUtil.readObject(nodeTypeJson, NodeType.class);
assertNotNull(nodeTypeDeserialized);
attributes = nodeTypeDeserialized.getAttributes();
simpleDefinition = attributes.get("simple_definition");
ipAddressDefinition = attributes.get("ip_address");
simpleConcat = attributes.get("simple_concat");
complexConcat = attributes.get("complex_concat");
// check attributes types after deserialization
assertTrue(simpleDefinition.getClass().equals(AttributeDefinition.class));
assertTrue(ipAddressDefinition.getClass().equals(AttributeDefinition.class));
assertTrue(simpleConcat.getClass().equals(ConcatPropertyValue.class));
assertTrue(complexConcat.getClass().equals(ConcatPropertyValue.class));
}
Aggregations