Commit dec39138 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added tests

parent 9b8e422c
...@@ -313,19 +313,19 @@ public class ToscaHelper { ...@@ -313,19 +313,19 @@ public class ToscaHelper {
} }
private NODE_STATES getNodeState(NodeTemplateMap node, String stateName) { private NODE_STATES getNodeState(NodeTemplateMap node, String stateName) {
if (node.getNodeTemplate().getArtifacts() != null) { if (node.getNodeTemplate().getAttributes() != null) {
return NODE_STATES.valueOf((String) node.getNodeTemplate().getArtifacts().get(stateName)); return NODE_STATES.valueOf((String) node.getNodeTemplate().getAttributes().get(stateName));
} }
return null; return null;
} }
private NodeTemplateMap setNodeState(NodeTemplateMap node, String stateName, NODE_STATES nodeState) { private NodeTemplateMap setNodeState(NodeTemplateMap node, String stateName, NODE_STATES nodeState) {
Map<String, Object> artifacts = node.getNodeTemplate().getArtifacts(); Map<String, Object> attributes = node.getNodeTemplate().getAttributes();
if (artifacts == null) { if (attributes == null) {
artifacts = new HashMap<>(); attributes = new HashMap<>();
} }
artifacts.put(stateName, nodeState.toString()); attributes.put(stateName, nodeState.toString());
node.getNodeTemplate().setArtifacts(artifacts); node.getNodeTemplate().attributes(attributes);
return node; return node;
} }
......
...@@ -110,6 +110,8 @@ public class DRIPService { ...@@ -110,6 +110,8 @@ public class DRIPService {
public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException, MissingVMTopologyException { public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException, MissingVMTopologyException {
ToscaTemplate toscaTemplate = initExecution(id); ToscaTemplate toscaTemplate = initExecution(id);
toscaTemplate = addCredentials(toscaTemplate); toscaTemplate = addCredentials(toscaTemplate);
//Update ToscaTemplate so we can include the credentials
helper.uploadToscaTemplate(toscaTemplate);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates(); List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies == null || vmTopologies.isEmpty()) { if (vmTopologies == null || vmTopologies.isEmpty()) {
throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM Topologies"); throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM Topologies");
......
...@@ -33,6 +33,7 @@ import java.util.HashMap; ...@@ -33,6 +33,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -44,6 +45,8 @@ import nl.uva.sne.drip.configuration.MongoConfig; ...@@ -44,6 +45,8 @@ import nl.uva.sne.drip.configuration.MongoConfig;
import nl.uva.sne.drip.model.Exceptions.MissingCredentialsException; import nl.uva.sne.drip.model.Exceptions.MissingCredentialsException;
import nl.uva.sne.drip.model.Exceptions.MissingVMTopologyException; import nl.uva.sne.drip.model.Exceptions.MissingVMTopologyException;
import nl.uva.sne.drip.model.Exceptions.TypeExeption; import nl.uva.sne.drip.model.Exceptions.TypeExeption;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.NodeTemplateMap;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import nl.uva.sne.drip.model.tosca.ToscaTemplate; import nl.uva.sne.drip.model.tosca.ToscaTemplate;
import nl.uva.sne.drip.sure.tosca.client.ApiException; import nl.uva.sne.drip.sure.tosca.client.ApiException;
...@@ -96,6 +99,9 @@ public class ServiceTests { ...@@ -96,6 +99,9 @@ public class ServiceTests {
@Autowired @Autowired
CredentialService credentialService; CredentialService credentialService;
@Autowired
ToscaHelper helper;
@Autowired @Autowired
private WebApplicationContext wac; private WebApplicationContext wac;
private MockMvc mockMvc; private MockMvc mockMvc;
...@@ -416,6 +422,32 @@ public class ServiceTests { ...@@ -416,6 +422,32 @@ public class ServiceTests {
ToscaTemplate toscaTemplate = dripService.initExecution(id); ToscaTemplate toscaTemplate = dripService.initExecution(id);
toscaTemplate = dripService.addCredentials(toscaTemplate); toscaTemplate = dripService.addCredentials(toscaTemplate);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies == null || vmTopologies.isEmpty()) {
throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM Topologies");
}
for (NodeTemplateMap vmTopology : vmTopologies) {
Map<String, Object> attributes = vmTopology.getNodeTemplate().getAttributes();
assertNotNull(attributes);
Assert.assertTrue(attributes.containsKey("credential"));
assertNotNull(attributes.get("credential"));
}
toscaTemplate = dripService.setDesieredSate(toscaTemplate, vmTopologies, ToscaHelper.NODE_STATES.PROVISION);
Map<String, NodeTemplate> nodes = toscaTemplate.getTopologyTemplate().getNodeTemplates();
Set<String> names = nodes.keySet();
for (String name : names) {
NodeTemplate node = nodes.get(name);
if (node.getType().equals("tosca.nodes.ARTICONF.VM.topology")) {
Map<String, Object> attributes = node.getAttributes();
assertNotNull(attributes);
Assert.assertTrue(attributes.containsKey("credential"));
assertNotNull(attributes.get("credential"));
Assert.assertTrue(attributes.containsKey("desired_state"));
assertNotNull(attributes.get("desired_state"));
}
}
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment