Commit dec39138 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added tests

parent 9b8e422c
......@@ -313,19 +313,19 @@ public class ToscaHelper {
}
private NODE_STATES getNodeState(NodeTemplateMap node, String stateName) {
if (node.getNodeTemplate().getArtifacts() != null) {
return NODE_STATES.valueOf((String) node.getNodeTemplate().getArtifacts().get(stateName));
if (node.getNodeTemplate().getAttributes() != null) {
return NODE_STATES.valueOf((String) node.getNodeTemplate().getAttributes().get(stateName));
}
return null;
}
private NodeTemplateMap setNodeState(NodeTemplateMap node, String stateName, NODE_STATES nodeState) {
Map<String, Object> artifacts = node.getNodeTemplate().getArtifacts();
if (artifacts == null) {
artifacts = new HashMap<>();
Map<String, Object> attributes = node.getNodeTemplate().getAttributes();
if (attributes == null) {
attributes = new HashMap<>();
}
artifacts.put(stateName, nodeState.toString());
node.getNodeTemplate().setArtifacts(artifacts);
attributes.put(stateName, nodeState.toString());
node.getNodeTemplate().attributes(attributes);
return node;
}
......
......@@ -110,6 +110,8 @@ public class DRIPService {
public String provision(String id) throws MissingCredentialsException, ApiException, TypeExeption, IOException, JsonProcessingException, TimeoutException, InterruptedException, NotFoundException, MissingVMTopologyException {
ToscaTemplate toscaTemplate = initExecution(id);
toscaTemplate = addCredentials(toscaTemplate);
//Update ToscaTemplate so we can include the credentials
helper.uploadToscaTemplate(toscaTemplate);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
if (vmTopologies == null || vmTopologies.isEmpty()) {
throw new MissingVMTopologyException("ToscaTemplate: " + toscaTemplate + " has no VM Topologies");
......
......@@ -33,6 +33,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -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.MissingVMTopologyException;
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.ToscaTemplate;
import nl.uva.sne.drip.sure.tosca.client.ApiException;
......@@ -96,6 +99,9 @@ public class ServiceTests {
@Autowired
CredentialService credentialService;
@Autowired
ToscaHelper helper;
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
......@@ -416,6 +422,32 @@ public class ServiceTests {
ToscaTemplate toscaTemplate = dripService.initExecution(id);
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