Search in sources :

Example 16 with ArchiveRoot

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);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Test(org.junit.Test)

Example 17 with ArchiveRoot

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());
            }
        }
    }
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 18 with ArchiveRoot

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());
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 19 with ArchiveRoot

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());
            }
        });
    });
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Test(org.junit.Test)

Example 20 with ArchiveRoot

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());
}
Also used : Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ArtifactType(org.alien4cloud.tosca.model.types.ArtifactType) Test(org.junit.Test)

Aggregations

ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)78 Test (org.junit.Test)45 Csar (org.alien4cloud.tosca.model.Csar)27 Set (java.util.Set)26 NodeType (org.alien4cloud.tosca.model.types.NodeType)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)16 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)14 ParsingError (alien4cloud.tosca.parser.ParsingError)13 Path (java.nio.file.Path)11 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)8 Node (org.yaml.snakeyaml.nodes.Node)8 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)6 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)6 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)6 ParsingException (alien4cloud.tosca.parser.ParsingException)5 Map (java.util.Map)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)4 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4