Search in sources :

Example 96 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class DASpecificationTest method getNodesWithSuitableConcreteDAAndTheDirectlyConnectedNode.

@Test
public void getNodesWithSuitableConcreteDAAndTheDirectlyConnectedNode() throws Exception {
    setRevisionTo("5f63267261584a513dd8a9b7960687cc3dda910a");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
    TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
    assertNotNull(topologyTemplate);
    TNodeTemplate nodeTemplateWithAbstractDA = topologyTemplate.getNodeTemplate("shetland_pony");
    assertNotNull(nodeTemplateWithAbstractDA);
    assertNotNull(nodeTemplateWithAbstractDA.getDeploymentArtifacts());
    TDeploymentArtifact deploymentArtifact = nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0);
    TNodeTemplate nodeTemplateConcreteDA1 = topologyTemplate.getNodeTemplate("dressageequipment");
    TRelationshipTemplate relationshipTemplate1 = topologyTemplate.getRelationshipTemplate("con_42");
    TNodeTemplate nodeTemplateConcreteDA2 = topologyTemplate.getNodeTemplate("westernequipment");
    TRelationshipTemplate relationshipTemplate2 = topologyTemplate.getRelationshipTemplate("con_54");
    Set<Pair<TRelationshipTemplate, TNodeTemplate>> concreteDAsAndConnectedNodes = new HashSet<>();
    concreteDAsAndConnectedNodes.add(Pair.of(relationshipTemplate1, nodeTemplateConcreteDA1));
    concreteDAsAndConnectedNodes.add(Pair.of(relationshipTemplate2, nodeTemplateConcreteDA2));
    Set<Pair<TRelationshipTemplate, TNodeTemplate>> actualNodeWithConcreteDA = DASpecification.getNodesWithSuitableConcreteDAAndTheDirectlyConnectedNode(nodeTemplateWithAbstractDA, deploymentArtifact, topologyTemplate);
    assertEquals(concreteDAsAndConnectedNodes, actualNodeWithConcreteDA);
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Pair(org.apache.commons.lang3.tuple.Pair) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 97 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class DASpecificationTest method getNodesWithSuitableConcreteDAs.

@Test
public void getNodesWithSuitableConcreteDAs() throws Exception {
    setRevisionTo("5f63267261584a513dd8a9b7960687cc3dda910a");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
    TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
    assertNotNull(topologyTemplate);
    TNodeTemplate nodeTemplate = topologyTemplate.getNodeTemplate("ponycompetition");
    TNodeTemplate nodeTemplateWithAbstractDA = topologyTemplate.getNodeTemplate("shetland_pony");
    assertNotNull(nodeTemplateWithAbstractDA);
    assertNotNull(nodeTemplateWithAbstractDA.getDeploymentArtifacts());
    TDeploymentArtifact deploymentArtifact = nodeTemplateWithAbstractDA.getDeploymentArtifacts().get(0);
    TNodeTemplate expectedNodeTemplate = topologyTemplate.getNodeTemplate("dressageequipment");
    TNodeTemplate actualNodeWithConcreteDA = DASpecification.getNodesWithSuitableConcreteDAs(nodeTemplate, deploymentArtifact, topologyTemplate);
    assertEquals(expectedNodeTemplate, actualNodeWithConcreteDA);
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 98 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class DASpecificationTest method getArtifactTypeHierarchy.

@Test
public void getArtifactTypeHierarchy() throws Exception {
    setRevisionTo("af529e513388dc9358a8f700757d8dc59aba3a55");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
    TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
    assertNotNull(topologyTemplate);
    TNodeTemplate nodeTemplate = topologyTemplate.getNodeTemplate("westernequipment");
    assertNotNull(nodeTemplate);
    assertNotNull(nodeTemplate.getDeploymentArtifacts());
    List<TArtifactType> artifactTypes = DASpecification.getArtifactTypeHierarchy(DASpecification.getArtifactTypeOfDA(nodeTemplate.getDeploymentArtifacts().get(0)));
    List<String> artifactTypeNames = new ArrayList<>();
    artifactTypes.forEach(at -> artifactTypeNames.add(at.getName()));
    assertEquals(2, artifactTypes.size());
    assertTrue(artifactTypeNames.contains("WesternEquipment_Pony"));
    assertTrue(artifactTypeNames.contains("PonyEquipment"));
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 99 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class DASpecificationTest method getNodeTemplatesWithAbstractDAs.

@Test
public void getNodeTemplatesWithAbstractDAs() throws Exception {
    setRevisionTo("af529e513388dc9358a8f700757d8dc59aba3a55");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
    TTopologyTemplate topologyTemplate = this.repository.getElement(id).getTopologyTemplate();
    assertNotNull(topologyTemplate);
    List<TNodeTemplate> nodeTemplateWithAbstractDA = new ArrayList<>();
    nodeTemplateWithAbstractDA.add(topologyTemplate.getNodeTemplate("shetland_pony"));
    List<TNodeTemplate> nodesWithAbstractDA = DASpecification.getNodeTemplatesWithAbstractDAs(topologyTemplate);
    assertEquals(nodeTemplateWithAbstractDA, nodesWithAbstractDA);
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 100 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class CsarExporterTest method testHashesForEachFile.

@Test
public void testHashesForEachFile() throws Exception {
    Map<String, Object> exportConfiguration = new HashMap<>();
    exportConfiguration.put(INCLUDE_HASHES.name(), null);
    try (InputStream inputStream = this.createOutputAndInputStream(// quick fix - should work if eclipse/winery#305 is merged
    "7c8d8c7057403a07fde90dec1f44f0190ae65ae2", new ServiceTemplateId("http://plain.winery.opentosca.org/servicetemplates", "ServiceTemplateWithAllReqCapVariants", false), exportConfiguration);
        ZipInputStream zis = new ZipInputStream(inputStream)) {
        ZipEntry entry;
        List<CsarContentProperties> elementsList = new ArrayList<>();
        ManifestContents manifestContents = null;
        while ((entry = zis.getNextEntry()) != null) {
            CsarContentProperties fileProperties = new CsarContentProperties(entry.getName());
            elementsList.add(fileProperties);
            byte[] array = IOUtils.toByteArray(zis);
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(array);
            fileProperties.setFileHash(HashingUtil.getChecksum(byteArrayInputStream, TOSCAMetaFileAttributes.HASH));
            if ("TOSCA-Metadata/TOSCA.meta".equals(fileProperties.getPathInsideCsar())) {
                String s = new String(array, StandardCharsets.UTF_8);
                manifestContents = new RecoveringManifestParser().parse(s);
            }
        }
        assertNotNull(manifestContents);
        for (CsarContentProperties fileProperties : elementsList) {
            Map<String, String> attributes = manifestContents.getAttributesForSection(fileProperties.getPathInsideCsar());
            if (!"TOSCA-Metadata/TOSCA.meta".equals(fileProperties.getPathInsideCsar())) {
                // ensure each file has a hash
                assertTrue(attributes.containsKey(TOSCAMetaFileAttributes.HASH));
                // ensure that the hashes match
                assertEquals(fileProperties.getFileHash(), attributes.get(TOSCAMetaFileAttributes.HASH));
            }
        }
        // ensures that every file in the archive has a hash in the manifest
        assertEquals(elementsList.size() - 1, manifestContents.getSectionNames().size());
    }
}
Also used : RecoveringManifestParser(org.eclipse.virgo.util.parser.manifest.RecoveringManifestParser) HashMap(java.util.HashMap) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ManifestContents(org.eclipse.virgo.util.parser.manifest.ManifestContents) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13