Search in sources :

Example 81 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class InputPropertiesStepDefinitions method getPropertyDefinition.

private PropertyDefinition getPropertyDefinition(String nodeName, String propertyName) throws Throwable {
    PropertyDefinition propDef = null;
    String url = String.format("/rest/v1/topologies/%s", Context.getInstance().getTopologyId());
    String response = Context.getRestClientInstance().get(url);
    TopologyDTO topologyDTO = JsonUtil.read(response, TopologyDTO.class, Context.getJsonMapper()).getData();
    NodeTemplate template = MapUtils.getObject(topologyDTO.getTopology().getNodeTemplates(), nodeName);
    if (template != null) {
        NodeType nodeType = MapUtils.getObject(topologyDTO.getNodeTypes(), template.getType());
        if (nodeType != null) {
            propDef = MapUtils.getObject(nodeType.getProperties(), propertyName);
        }
    }
    if (propDef == null) {
        throw new NullPointerException("The property definition is required for node " + nodeName + " and property " + propertyName + ", please check your cucumber scenario.");
    }
    return propDef;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) NodeType(org.alien4cloud.tosca.model.types.NodeType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 82 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class InputPropertiesStepDefinitions method i_define_the_capability_property_of_the_node_of_typeId_as_input_property.

@Given("^I define the capability \"(.*?)\" property \"(.*?)\" of the node \"(.*?)\" as input property$")
public void i_define_the_capability_property_of_the_node_of_typeId_as_input_property(String capabilityName, String propertyName, String nodeName) throws Throwable {
    String url = String.format("/rest/v1/topologies/%s", Context.getInstance().getTopologyId());
    String response = Context.getRestClientInstance().get(url);
    TopologyDTO topologyDTO = JsonUtil.read(response, TopologyDTO.class, Context.getJsonMapper()).getData();
    NodeTemplate template = MapUtils.getObject(topologyDTO.getTopology().getNodeTemplates(), nodeName);
    Capability capability = template.getCapabilities().get(capabilityName);
    CapabilityType capabilityType = topologyDTO.getCapabilityTypes().get(capability.getType());
    PropertyDefinition propertyDefinition = capabilityType.getProperties().get(propertyName);
    String fullUrl = String.format("/rest/v1/topologies/%s/inputs/%s", Context.getInstance().getTopologyId(), propertyName);
    String json = JsonUtil.toString(propertyDefinition);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(fullUrl, json));
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) Capability(org.alien4cloud.tosca.model.templates.Capability) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Given(cucumber.api.java.en.Given)

Example 83 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TopologyCompareStepsDefinitions method quickCompareTopologies.

@Then("^Topologies \"([^\"]*)\" and \"([^\"]*)\" have the same number of node templates with identical types.$")
public void quickCompareTopologies(String topologyId1, String topologyId2) throws Throwable {
    // created topology
    Context.getInstance().registerRestResponse(getRestClientInstance().get("/rest/v1/topologies/" + topologyId1));
    TopologyDTO topology1 = JsonUtil.read(Context.getInstance().getRestResponse(), TopologyDTO.class, Context.getJsonMapper()).getData();
    Context.getInstance().registerRestResponse(getRestClientInstance().get("/rest/v1/topologies/" + topologyId2));
    TopologyDTO topology2 = JsonUtil.read(Context.getInstance().getRestResponse(), TopologyDTO.class, Context.getJsonMapper()).getData();
    // node templates count test
    assertNotNull(topology2);
    assertNotNull(topology1);
    int topo2nodeCount = topology2.getTopology() == null || topology2.getTopology().getNodeTemplates() == null ? 0 : topology2.getTopology().getNodeTemplates().size();
    int topo1nodeCount = topology1.getTopology() == null || topology1.getTopology().getNodeTemplates() == null ? 0 : topology1.getTopology().getNodeTemplates().size();
    assertEquals(topo2nodeCount, topo1nodeCount);
    if (topo2nodeCount == 0) {
        return;
    }
    // node templates name / type test
    for (Map.Entry<String, NodeTemplate> entry : topology1.getTopology().getNodeTemplates().entrySet()) {
        assertTrue(topology2.getTopology().getNodeTemplates().containsKey(entry.getKey()));
        assertTrue(topology2.getTopology().getNodeTemplates().get(entry.getKey()).getType().equals(entry.getValue().getType()));
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) TopologyDTO(alien4cloud.topology.TopologyDTO) Map(java.util.Map) Then(cucumber.api.java.en.Then)

Example 84 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TopologyStepDefinitions method The_topology_should_contain_a_nodetemplate_named_with_an_artifact_with_the_specified_UID.

@Then("^The topology should contain a nodetemplate named \"([^\"]*)\" with an artifact \"([^\"]*)\" with the specified UID and name \"([^\"]*)\"$")
public void The_topology_should_contain_a_nodetemplate_named_with_an_artifact_with_the_specified_UID(String nodeTemplateName, String artifactId, String artifactName) throws Throwable {
    The_topology_should_contain_a_nodetemplate_named(nodeTemplateName);
    String topologyResponseText = Context.getInstance().getRestResponse();
    NodeTemplate nodeTemp = JsonUtil.read(topologyResponseText, TopologyDTO.class, Context.getJsonMapper()).getData().getTopology().getNodeTemplates().get(nodeTemplateName);
    Assert.assertNotNull(nodeTemp.getArtifacts());
    Assert.assertFalse(nodeTemp.getArtifacts().isEmpty());
    DeploymentArtifact deploymentArtifact = nodeTemp.getArtifacts().get(artifactId);
    Assert.assertNotNull(deploymentArtifact);
    Assert.assertNotNull(deploymentArtifact.getArtifactType());
    Assert.assertEquals(artifactName, deploymentArtifact.getArtifactName());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) Then(cucumber.api.java.en.Then)

Example 85 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TopologyStepDefinitions method The_topology_should_contain_a_nodetemplate_named_with_property_set_to.

@Then("^The topology should contain a nodetemplate named \"([^\"]*)\" with property \"([^\"]*)\" set to \"([^\"]*)\"$")
public void The_topology_should_contain_a_nodetemplate_named_with_property_set_to(String nodeTemplateName, String propertyName, String propertyValue) throws Throwable {
    The_topology_should_contain_a_nodetemplate_named(nodeTemplateName);
    String topologyResponseText = Context.getInstance().getRestResponse();
    NodeTemplate nodeTemp = JsonUtil.read(topologyResponseText, TopologyDTO.class, Context.getJsonMapper()).getData().getTopology().getNodeTemplates().get(nodeTemplateName);
    assertNotNull(nodeTemp.getProperties());
    if (propertyValue != null) {
        assertNotNull(nodeTemp.getProperties().get(propertyName));
    }
    assertEquals(propertyValue, PropertyUtil.getScalarValue(nodeTemp.getProperties().get(propertyName)));
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Then(cucumber.api.java.en.Then)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10