Search in sources :

Example 6 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class ToscaParserSimpleProfileAlien120Test method testRelationshipType.

@SuppressWarnings("unchecked")
@Test
public void testRelationshipType() throws FileNotFoundException, ParsingException {
    RelationshipType mockedResult = Mockito.mock(RelationshipType.class);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.Relationship"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.capabilities.Root"));
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-relationship-type.yml"));
    ParserTestUtil.displayErrors(parsingResult);
    assertNoBlocker(parsingResult);
    ArchiveRoot archiveRoot = parsingResult.getResult();
    Assert.assertNotNull(archiveRoot.getArchive());
    Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
    Assert.assertEquals(1, archiveRoot.getRelationshipTypes().size());
    Entry<String, RelationshipType> entry = archiveRoot.getRelationshipTypes().entrySet().iterator().next();
    Assert.assertEquals("mycompany.mytypes.myapplication.MyRelationship", entry.getKey());
    RelationshipType relationship = entry.getValue();
    Assert.assertEquals(Lists.newArrayList("tosca.relationships.Relationship", "tosca.capabilities.Root"), relationship.getDerivedFrom());
    Assert.assertEquals("a custom relationship", relationship.getDescription());
    // properties
    Assert.assertEquals(2, relationship.getProperties().size());
    Assert.assertTrue(relationship.getProperties().containsKey("my_feature_setting"));
    PropertyDefinition pd = relationship.getProperties().get("my_feature_setting");
    Assert.assertEquals("string", pd.getType());
    Assert.assertTrue(relationship.getProperties().containsKey("my_feature_value"));
    pd = relationship.getProperties().get("my_feature_value");
    Assert.assertEquals("integer", pd.getType());
    // valid targets
    Assert.assertEquals(2, relationship.getValidTargets().length);
    Assert.assertEquals("tosca.capabilities.Feature1", relationship.getValidTargets()[0]);
    Assert.assertEquals("tosca.capabilities.Feature2", relationship.getValidTargets()[1]);
}
Also used : Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Test(org.junit.Test)

Example 7 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class ToscaParserSimpleProfileAlien120Test method testCapabilities.

@Test
public void testCapabilities() throws ParsingException {
    NodeType mockedResult = Mockito.mock(NodeType.class);
    Mockito.when(repositorySearchService.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(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
    CapabilityType mockedCapabilityResult = Mockito.mock(CapabilityType.class);
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Endpoint"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
    Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
    RelationshipType connectsTo = new RelationshipType();
    Mockito.when(repositorySearchService.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());
                    Assert.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 8 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType in project alien4cloud by alien4cloud.

the class ToscaParserSimpleProfileAlien120Test method testBadOccurrence.

@SuppressWarnings("unchecked")
@Test
public void testBadOccurrence() throws FileNotFoundException, 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);
    RelationshipType hostedOn = new RelationshipType();
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
    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);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-node-type-invalid-occurrence.yml"));
    Assert.assertEquals(2, countErrorByLevelAndCode(parsingResult, ParsingErrorLevel.ERROR, ErrorCode.SYNTAX_ERROR));
}
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 9 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType 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 10 with RelationshipType

use of org.alien4cloud.tosca.model.types.RelationshipType 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)

Aggregations

RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)41 NodeType (org.alien4cloud.tosca.model.types.NodeType)22 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)15 Set (java.util.Set)14 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)14 Test (org.junit.Test)14 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)9 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)9 Csar (org.alien4cloud.tosca.model.Csar)8 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)8 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)5 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)5 Interface (org.alien4cloud.tosca.model.definitions.Interface)5 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)4 NotFoundException (alien4cloud.exception.NotFoundException)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)3 Capability (org.alien4cloud.tosca.model.templates.Capability)3 DataType (org.alien4cloud.tosca.model.types.DataType)3 ParsingError (alien4cloud.tosca.parser.ParsingError)2