use of alien4cloud.tosca.model.ArchiveRoot 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 alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method parseTopologyTemplateWithGetInputErrors.
@Test
public void parseTopologyTemplateWithGetInputErrors() throws ParsingException, IOException {
// parse the node define with node_filter
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-badinputs.yml"));
// there are 2 MISSING INPUT errors
Assert.assertEquals(2, countErrorByLevelAndCode(parsingResult, ParsingErrorLevel.ERROR, ErrorCode.MISSING_TOPOLOGY_INPUT));
// check 2 errors content
List<ParsingError> errors = parsingResult.getContext().getParsingErrors();
for (Iterator iterator = errors.iterator(); iterator.hasNext(); ) {
ParsingError parsingError = (ParsingError) iterator.next();
if (parsingError.getErrorLevel().equals(ParsingErrorLevel.ERROR) && parsingError.getErrorCode().equals(ErrorCode.MISSING_TOPOLOGY_INPUT)) {
if (parsingError.getProblem().equals("toto")) {
Assert.assertEquals("os_distribution", parsingError.getNote());
}
if (parsingError.getProblem().equals("greatsize")) {
Assert.assertEquals("size", parsingError.getNote());
}
}
}
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testImportDependency.
@Test
public void testImportDependency() throws FileNotFoundException, ParsingException {
Csar csar = new Csar("tosca-normative-types", "1.0.0-SNAPSHOT-wd03");
Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-import-dependency.yml"));
Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
assertNotNull(archiveRoot.getArchive().getDependencies());
Assert.assertEquals(1, archiveRoot.getArchive().getDependencies().size());
Assert.assertEquals(new CSARDependency(csar.getName(), csar.getVersion()), archiveRoot.getArchive().getDependencies().iterator().next());
}
use of alien4cloud.tosca.model.ArchiveRoot 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 alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testArtifactType.
@SuppressWarnings("unchecked")
@Test
public void testArtifactType() throws FileNotFoundException, ParsingException {
ArtifactType mockedResult = Mockito.mock(ArtifactType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(ArtifactType.class), Mockito.eq("tosca.artifact.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
List<String> derivedFromSet = Lists.newArrayList();
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(derivedFromSet);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-artifact-type.yml"));
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(1, archiveRoot.getArtifactTypes().size());
Entry<String, ArtifactType> entry = archiveRoot.getArtifactTypes().entrySet().iterator().next();
Assert.assertEquals("my_artifact_type", entry.getKey());
ArtifactType artifact = entry.getValue();
Assert.assertEquals(Lists.newArrayList("tosca.artifact.Root"), artifact.getDerivedFrom());
Assert.assertEquals("Java Archive artifact type", artifact.getDescription());
Assert.assertEquals("application/java-archive", artifact.getMimeType());
Assert.assertEquals(Lists.newArrayList("jar"), artifact.getFileExt());
}
Aggregations