DefaultTopologyContext(Topology topology, Csar csar) { super(); this.topology = topology; this.dslVersion = csar.getToscaDefinitionsVersion(); }
/** * Get the yaml string out of a cloud service archive and topology. * * @param csar The csar that contains archive meta-data. * @param topology The topology template within the archive. * @param generateWorkflow if true, all wf will be generate, if false, only the custom wf will be generate * @return The TOSCA yaml file that describe the topology. */ public String getYaml(Csar csar, Topology topology, boolean generateWorkflow) { return getYaml(csar, topology, generateWorkflow, csar.getToscaDefinitionsVersion()); }
@Override public String getDSLVersion() { return archiveRoot.getArchive().getToscaDefinitionsVersion(); }
DefaultTopologyContext(Topology topology) { super(); this.topology = topology; Csar topologyCsar = csarRepoSearchService.getArchive(topology.getArchiveName(), topology.getArchiveVersion()); if (topologyCsar == null) { throw new NotFoundException("Topology's csar " + topology.getArchiveName() + ":" + topology.getArchiveVersion() + " cannot be found"); } this.dslVersion = topologyCsar.getToscaDefinitionsVersion(); }
@Test public void testServiceRelationshipSubstitution() throws FileNotFoundException, ParsingException { Mockito.reset(csarRepositorySearchService); Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class)); NodeType mockRoot = Mockito.mock(NodeType.class); Mockito.when(mockRoot.isAbstract()).thenReturn(true); Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))) .thenReturn(mockRoot); Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Root"), Mockito.any(Set.class))).thenReturn(Mockito.mock(CapabilityType.class)); Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.Root"), Mockito.any(Set.class))).thenReturn(Mockito.mock(RelationshipType.class)); ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "substitution_mapping_service_relationship.yml")); Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size()); ArchiveRoot archiveRoot = parsingResult.getResult(); Assert.assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); Assert.assertEquals("org.alien4cloud.relationships.test.MyRelationship", archiveRoot.getTopology().getSubstitutionMapping().getCapabilities().get("subst_capa").getServiceRelationshipType()); }
@SuppressWarnings("unchecked") @Test public void testCapabilityType() throws FileNotFoundException, ParsingException { CapabilityType mockedResult = Mockito.mock(CapabilityType.class); Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Feature"), 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-capability-type.yml")); assertNoBlocker(parsingResult); ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); Assert.assertEquals(1, archiveRoot.getCapabilityTypes().size()); Entry<String, CapabilityType> entry = archiveRoot.getCapabilityTypes().entrySet().iterator().next(); Assert.assertEquals("mycompany.mytypes.myapplication.MyFeature", entry.getKey()); CapabilityType capability = entry.getValue(); Assert.assertEquals(Lists.newArrayList("tosca.capabilities.Feature", "tosca.capabilities.Root"), capability.getDerivedFrom()); Assert.assertEquals("a custom feature of my company’s application", capability.getDescription()); }
@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()); }
ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); Assert.assertEquals(1, archiveRoot.getNodeTypes().size());
ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
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();
@Test public void testDefinitionVersionValid() throws FileNotFoundException, ParsingException { ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-definition-version.yml")); Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size()); ArchiveRoot archiveRoot = parsingResult.getResult(); Assert.assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); }
assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); assertEquals(1, archiveRoot.getPolicyTypes().size());
@Test public void testDescriptionSingleLine() throws FileNotFoundException, ParsingException { ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "description-single-line.yml")); Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size()); ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); assertNotNull(archiveRoot.getArchive().getDescription()); Assert.assertEquals("This is an example of a single line description (no folding).", archiveRoot.getArchive().getDescription()); }
@Test public void testDescriptionMultiLine() throws FileNotFoundException, ParsingException { ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "description-multi-line.yml")); Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size()); ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); assertNotNull(archiveRoot.getArchive().getDescription()); Assert.assertEquals( "This is an example of a multi-line description using YAML. It permits for line breaks for easier readability...\nif needed. However, (multiple) line breaks are folded into a single space character when processed into a single string value.", archiveRoot.getArchive().getDescription()); }
ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); Assert.assertEquals(1, archiveRoot.getRepositories().size()); Assert.assertEquals(2, archiveRoot.getArtifactTypes().size());
csar.setToscaDefinitionsVersion(csarService.getOrFail(new Csar(oldArchiveName, oldArchiveVersion).getId()).getToscaDefinitionsVersion()); } else { csar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL);
final String definitionVersion = parsingResult.getResult().getArchive().getToscaDefinitionsVersion();
@Test public void testRootCategories() throws FileNotFoundException, ParsingException { ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-root-categories.yml")); assertNoBlocker(parsingResult); ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); Assert.assertEquals("Tosca default namespace value", archiveRoot.getArchive().getToscaDefaultNamespace()); Assert.assertEquals("Template name value", archiveRoot.getArchive().getName()); Assert.assertEquals("Temlate author value", archiveRoot.getArchive().getTemplateAuthor()); Assert.assertEquals("1.0.0-SNAPSHOT", archiveRoot.getArchive().getVersion()); Assert.assertEquals("This is an example of a single line description (no folding).", archiveRoot.getArchive().getDescription()); }
ArchiveRoot archiveRoot = parsingResult.getResult(); assertNotNull(archiveRoot.getArchive()); Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion()); Assert.assertEquals(2, archiveRoot.getArtifactTypes().size()); Assert.assertEquals(4, archiveRoot.getNodeTypes().size());