Commit 4053fc74 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added tests for utils

updated model
parent 779bc2e5
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.commons.utils;
import java.util.Map;
import nl.uva.sne.drip.model.NodeTemplate;
/**
*
* @author S. Koulouzis
*/
class NodeTemplateFactory {
static NodeTemplate create(Map.Entry node) {
NodeTemplate nodeTemplate = new NodeTemplate();
Map<String, Object> nodeMap = (Map<String, Object>) node.getValue();
nodeTemplate.setArtifacts((Map<String, Object>) nodeMap.get("artifacts"));
return null;
}
}
...@@ -18,13 +18,12 @@ package nl.uva.sne.drip.commons.utils; ...@@ -18,13 +18,12 @@ package nl.uva.sne.drip.commons.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.TopologyTemplate; import nl.uva.sne.drip.model.TopologyTemplate;
import nl.uva.sne.drip.model.ToscaTemplate; import nl.uva.sne.drip.model.ToscaTemplate;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
/** /**
* *
...@@ -32,7 +31,7 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException; ...@@ -32,7 +31,7 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
*/ */
public class TOSCAUtils { public class TOSCAUtils {
public static List<Map.Entry> getNodes(ToscaTemplate toscaTemplate, String filterType, String filterValue) { public static List<Map<String, NodeTemplate>> getNodes(ToscaTemplate toscaTemplate, String filterType, String filterValue) {
boolean byType = false; boolean byType = false;
boolean byName = false; boolean byName = false;
switch (filterType) { switch (filterType) {
...@@ -44,29 +43,29 @@ public class TOSCAUtils { ...@@ -44,29 +43,29 @@ public class TOSCAUtils {
break; break;
} }
TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate(); TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
Map<String, Object> nodeTemplates = topologyTemplate.getNodeTemplates(); Map<String, NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
List<Map.Entry> nodeList = new ArrayList<>(); List<Map<String, NodeTemplate>> nodeList = new ArrayList<>();
Set<String> keys = nodeTemplates.keySet();
Iterator it = nodeTemplates.entrySet().iterator(); for (String key : keys) {
while (it.hasNext()) { NodeTemplate node = nodeTemplates.get(key);
Map.Entry node = (Map.Entry) it.next(); if (byName && key.equals(filterValue)) {
Map<String, Object> nodeValue = (Map<String, Object>) node.getValue(); Map<String, NodeTemplate> ntMap = new HashMap<>();
if (byName && node.getKey().equals(filterValue)) { ntMap.put(key, node);
nodeList.add(node); nodeList.add(ntMap);
} }
if (byType) { if (byType) {
String type = (String) nodeValue.get("type"); if (node.getType().equals(filterValue)) {
if (type.equals(filterValue)) { Map<String, NodeTemplate> ntMap = new HashMap<>();
nodeList.add(node); ntMap.put(key, node);
nodeList.add(ntMap);
} }
} }
} }
return nodeList; return nodeList;
} }
public static List<Map.Entry> getNodesByType(ToscaTemplate toscaTemplate, String nodeTypeName) { public static List<Map<String, NodeTemplate>> getNodesByType(ToscaTemplate toscaTemplate, String nodeTypeName) {
return getNodes(toscaTemplate, "type", nodeTypeName); return getNodes(toscaTemplate, "type", nodeTypeName);
} }
...@@ -101,112 +100,6 @@ public class TOSCAUtils { ...@@ -101,112 +100,6 @@ public class TOSCAUtils {
return outputPair; return outputPair;
} }
public static List<Map.Entry> getDockerContainers(ToscaTemplate toscaTemplate) {
TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
Map<String, Object> nodeTemplates = topologyTemplate.getNodeTemplates();
Iterator it = nodeTemplates.entrySet().iterator();
List<Map.Entry> dockerContainers = new ArrayList<>();
while (it.hasNext()) {
Map.Entry node = (Map.Entry) it.next();
Map<String, Object> nodeValue = (Map<String, Object>) node.getValue();
String type = (String) nodeValue.get("type");
if (type.equals("tosca.nodes.ARTICONF.Container.Application.Docker")) {
dockerContainers.add(node);
}
}
return dockerContainers;
}
public static List<Map<String, Object>> tosca2KubernetesDeployment(ToscaTemplate toscaTemplate) {
List<Map.Entry> dockerContainers = getDockerContainers(toscaTemplate);
List<Map<String, Object>> deployments = new ArrayList<>();
Iterator<Map.Entry> dicIt = dockerContainers.iterator();
while (dicIt.hasNext()) {
Map.Entry docker = dicIt.next();
String name = (String) docker.getKey();
Map<String, Object> labels = new HashMap();
labels.put("app", name);
Map<String, Object> metadata = new HashMap();
metadata.put("labels", labels);
metadata.put("name", name);
Map<String, Object> selector = new HashMap();
selector.put("matchLabels", labels);
Map<String, Object> template = new HashMap();
template.put("metadata", metadata);
Map<String, Object> dockerValues = (Map<String, Object>) docker.getValue();
List<Map<String, Object>> containersList = createContainerList(dockerValues, name);
Map<String, Object> spec1 = new HashMap();
spec1.put("containers", containersList);
template.put("spec", spec1);
Map<String, Object> topSpec = new HashMap();
topSpec.put("selector", selector);
topSpec.put("replicas", 1);
topSpec.put("template", template);
Map<String, Object> deployment = new HashMap();
deployment.put("spec", topSpec);
deployment.put("metadata", metadata);
deployment.put("kind", "Deployment");
deployment.put("apiVersion", "apps/v1");
deployments.add(deployment);
}
return deployments;
}
public static List<Map<String, Object>> tosca2KubernetesService(ToscaTemplate toscaTemplate) {
List<Map.Entry> dockerContainers = getDockerContainers(toscaTemplate);
List<Map<String, Object>> services = new ArrayList<>();
Iterator<Map.Entry> dicIt = dockerContainers.iterator();
while (dicIt.hasNext()) {
Map.Entry docker = dicIt.next();
String name = (String) docker.getKey();
Map<String, Object> dockerValues = (Map<String, Object>) docker.getValue();
Map<String, Object> spec = new HashMap();
spec.put("type", "NodePort");
Map<String, Object> properties = (Map<String, Object>) dockerValues.get("properties");
List<String> toscaPortsList = (List<String>) properties.get("ports");
List< Map<String, Object>> portList = new ArrayList<>();
if (toscaPortsList != null) {
for (String portEntry : toscaPortsList) {
String[] portsArray = portEntry.split(":");
Map<String, Object> portMap = new HashMap();
portMap.put("port", Integer.valueOf(portsArray[1]));
portList.add(portMap);
}
spec.put("ports", portList);
}
Map<String, Object> selector = new HashMap();
selector.put("app", name);
spec.put("selector", selector);
Map<String, Object> labels = new HashMap();
labels.put("app", name);
Map<String, Object> metadata = new HashMap();
metadata.put("labels", labels);
metadata.put("name", name);
Map<String, Object> service = new HashMap();
service.put("spec", spec);
service.put("metadata", metadata);
service.put("kind", "Service");
service.put("apiVersion", "v1");
services.add(service);
}
return services;
}
private static List<Map<String, Object>> getImageEnvirmoent(Map<String, Object> properties) { private static List<Map<String, Object>> getImageEnvirmoent(Map<String, Object> properties) {
Map<String, Object> envMap = (Map<String, Object>) properties.get("environment"); Map<String, Object> envMap = (Map<String, Object>) properties.get("environment");
...@@ -231,54 +124,23 @@ public class TOSCAUtils { ...@@ -231,54 +124,23 @@ public class TOSCAUtils {
return imageFile; return imageFile;
} }
private static List<Map<String, Object>> createContainerList(Map<String, Object> dockerValues, String name) { public static List<Map<String, NodeTemplate>> getRelatedNodes(NodeTemplate node, ToscaTemplate toscaTemplate) {
Map<String, Object> properties = (Map<String, Object>) dockerValues.get("properties");
List<Map<String, Object>> imageEnv = getImageEnvirmoent(properties);
String imageFile = getImageFile(dockerValues); if (node.getRequirements() != null) {
Map<String, Object> container = new HashMap();
container.put("image", imageFile);
container.put("name", name);
container.put("env", imageEnv);
List<String> toscaPortsList = (List<String>) properties.get("ports");
if (toscaPortsList != null) {
List< Map<String, Object>> portList = new ArrayList<>();
for (String portEntry : toscaPortsList) {
String[] portsArray = portEntry.split(":");
Map<String, Object> portMap = new HashMap();
portMap.put("containerPort", Integer.valueOf(portsArray[0]));
portList.add(portMap);
}
container.put("ports", portList);
}
List<Map<String, Object>> containersList = new ArrayList<>();
containersList.add(container);
return containersList;
}
public static List<Map.Entry> getRelatedNodes(Map<String, Object> node, ToscaTemplate toscaTemplate) {
String nodeName = node.keySet().iterator().next();
Map<String, Object> nodeMap = (Map<String, Object>) node.get(nodeName);
if (nodeMap.containsKey("requirements")) {
List<String> nodeNames = new ArrayList<>(); List<String> nodeNames = new ArrayList<>();
List<Map<String, Object>> requirements = (List<Map<String, Object>>) nodeMap.get("requirements"); List<Map<String, Object>> requirements = node.getRequirements();
for (Map<String, Object> requirement : requirements) { for (Map<String, Object> requirement : requirements) {
String reqName = requirement.keySet().iterator().next(); String reqName = requirement.keySet().iterator().next();
Map<String, Object> requirementMap = (Map<String, Object>) requirement.get(reqName); Map<String, Object> requirementMap = (Map<String, Object>) requirement.get(reqName);
// String requirementCapability = (String) requirementMap.get("capability");
String relatedNode = (String) requirementMap.get("node"); String relatedNode = (String) requirementMap.get("node");
nodeNames.add(relatedNode); nodeNames.add(relatedNode);
} }
List<Map.Entry> retaltedNodes = new ArrayList<>(); List<Map<String, NodeTemplate>> retaltedNodes = new ArrayList<>();
for (String name : nodeNames) { for (String name : nodeNames) {
List<Map.Entry> relatedNode = getNodesByName(toscaTemplate, name); List<Map<String, NodeTemplate>> relatedNode = getNodesByName(toscaTemplate, name);
for (Map.Entry rNode : relatedNode) { for (Map<String, NodeTemplate> rNode : relatedNode) {
retaltedNodes.add(rNode); retaltedNodes.add(rNode);
} }
} }
return retaltedNodes; return retaltedNodes;
} }
...@@ -286,28 +148,22 @@ public class TOSCAUtils { ...@@ -286,28 +148,22 @@ public class TOSCAUtils {
} }
private static List<Map.Entry> getNodesByName(ToscaTemplate toscaTemplate, String name) { private static List<Map<String, NodeTemplate>> getNodesByName(ToscaTemplate toscaTemplate, String name) {
return getNodes(toscaTemplate, "name", name); return getNodes(toscaTemplate, "name", name);
} }
public static boolean nodeIsOfType(Map.Entry node, String type) { public static boolean nodeIsOfType(NodeTemplate node, String type) {
String nodeName = (String) node.getKey(); if (node.getType().equals(type)) {
Map<String, Object> nodeMap = (Map<String, Object>) node.getValue();
if (nodeMap.containsKey("type") && nodeMap.get("type").equals(type)) {
return true; return true;
} }
return false; return false;
} }
public static Object getNodeProperty(Map.Entry node, String propertyName) { public static Object getNodeProperty(NodeTemplate node, String propertyName) {
Map<String, Object> nodeMap = (Map<String, Object>) node.getValue(); if (node.getProperties() != null) {
if (nodeMap.containsKey("properties") ) { return node.getProperties().get(propertyName);
Map<String, Object> properties = (Map<String, Object>) nodeMap.get("properties");
return properties.get(propertyName);
} }
return null; return null;
} }
} }
package nl.uva.sne.drip.model; package nl.uva.sne.drip.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.util.Objects; import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -10,19 +7,14 @@ import java.util.HashMap; ...@@ -10,19 +7,14 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.data.annotation.Id;
/** /**
* Credentials * Credentials
*/ */
@Validated @Validated
@JsonInclude(Include.NON_NULL) @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-25T14:09:25.182Z")
public class Credentials {
@Id
@JsonIgnore
private String id;
public class Credentials {
@JsonProperty("protocol") @JsonProperty("protocol")
private String protocol = null; private String protocol = null;
...@@ -47,23 +39,13 @@ public class Credentials { ...@@ -47,23 +39,13 @@ public class Credentials {
return this; return this;
} }
@JsonIgnore
public String getId() {
return id;
}
public void setID(String id) {
this.id = id;
}
/** /**
* Get protocol * Get protocol
*
* @return protocol * @return protocol
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getProtocol() { public String getProtocol() {
return protocol; return protocol;
} }
...@@ -79,12 +61,11 @@ public class Credentials { ...@@ -79,12 +61,11 @@ public class Credentials {
/** /**
* Get tokenType * Get tokenType
*
* @return tokenType * @return tokenType
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getTokenType() { public String getTokenType() {
return tokenType; return tokenType;
} }
...@@ -100,12 +81,11 @@ public class Credentials { ...@@ -100,12 +81,11 @@ public class Credentials {
/** /**
* Get token * Get token
*
* @return token * @return token
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getToken() { public String getToken() {
return token; return token;
} }
...@@ -129,12 +109,11 @@ public class Credentials { ...@@ -129,12 +109,11 @@ public class Credentials {
/** /**
* Get keys * Get keys
*
* @return keys * @return keys
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getKeys() { public Map<String, String> getKeys() {
return keys; return keys;
} }
...@@ -150,12 +129,11 @@ public class Credentials { ...@@ -150,12 +129,11 @@ public class Credentials {
/** /**
* Get user * Get user
*
* @return user * @return user
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getUser() { public String getUser() {
return user; return user;
} }
...@@ -171,12 +149,11 @@ public class Credentials { ...@@ -171,12 +149,11 @@ public class Credentials {
/** /**
* Get cloudProviderName * Get cloudProviderName
*
* @return cloudProviderName * @return cloudProviderName
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getCloudProviderName() { public String getCloudProviderName() {
return cloudProviderName; return cloudProviderName;
} }
...@@ -185,6 +162,7 @@ public class Credentials { ...@@ -185,6 +162,7 @@ public class Credentials {
this.cloudProviderName = cloudProviderName; this.cloudProviderName = cloudProviderName;
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {
...@@ -194,12 +172,12 @@ public class Credentials { ...@@ -194,12 +172,12 @@ public class Credentials {
return false; return false;
} }
Credentials credentials = (Credentials) o; Credentials credentials = (Credentials) o;
return Objects.equals(this.protocol, credentials.protocol) return Objects.equals(this.protocol, credentials.protocol) &&
&& Objects.equals(this.tokenType, credentials.tokenType) Objects.equals(this.tokenType, credentials.tokenType) &&
&& Objects.equals(this.token, credentials.token) Objects.equals(this.token, credentials.token) &&
&& Objects.equals(this.keys, credentials.keys) Objects.equals(this.keys, credentials.keys) &&
&& Objects.equals(this.user, credentials.user) Objects.equals(this.user, credentials.user) &&
&& Objects.equals(this.cloudProviderName, credentials.cloudProviderName); Objects.equals(this.cloudProviderName, credentials.cloudProviderName);
} }
@Override @Override
...@@ -233,3 +211,4 @@ public class Credentials { ...@@ -233,3 +211,4 @@ public class Credentials {
return o.toString().replace("\n", "\n "); return o.toString().replace("\n", "\n ");
} }
} }
package nl.uva.sne.drip.model; package nl.uva.sne.drip.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.util.Objects; import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -16,7 +14,8 @@ import javax.validation.Valid; ...@@ -16,7 +14,8 @@ import javax.validation.Valid;
* NodeTemplate * NodeTemplate
*/ */
@Validated @Validated
@JsonInclude(Include.NON_NULL) @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-25T14:09:25.182Z")
public class NodeTemplate { public class NodeTemplate {
@JsonProperty("name") @JsonProperty("name")
private String name = null; private String name = null;
......
package nl.uva.sne.drip.model; package nl.uva.sne.drip.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.util.Objects; import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
...@@ -16,7 +14,8 @@ import javax.validation.Valid; ...@@ -16,7 +14,8 @@ import javax.validation.Valid;
* TopologyTemplate * TopologyTemplate
*/ */
@Validated @Validated
@JsonInclude(Include.NON_NULL) @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-25T14:47:27.096Z")
public class TopologyTemplate { public class TopologyTemplate {
@JsonProperty("description") @JsonProperty("description")
private String description = null; private String description = null;
...@@ -35,7 +34,7 @@ public class TopologyTemplate { ...@@ -35,7 +34,7 @@ public class TopologyTemplate {
@JsonProperty("node_templates") @JsonProperty("node_templates")
@Valid @Valid
private Map<String, Object> nodeTemplates = null; private Map<String, NodeTemplate> nodeTemplates = null;
@JsonProperty("relationship_templates") @JsonProperty("relationship_templates")
@Valid @Valid
...@@ -156,14 +155,14 @@ public class TopologyTemplate { ...@@ -156,14 +155,14 @@ public class TopologyTemplate {
this.outputs = outputs; this.outputs = outputs;
} }
public TopologyTemplate nodeTemplates(Map<String, Object> nodeTemplates) { public TopologyTemplate nodeTemplates(Map<String, NodeTemplate> nodeTemplates) {
this.nodeTemplates = nodeTemplates; this.nodeTemplates = nodeTemplates;
return this; return this;
} }
public TopologyTemplate putNodeTemplatesItem(String key, Object nodeTemplatesItem) { public TopologyTemplate putNodeTemplatesItem(String key, NodeTemplate nodeTemplatesItem) {
if (this.nodeTemplates == null) { if (this.nodeTemplates == null) {
this.nodeTemplates = new HashMap<String, Object>(); this.nodeTemplates = new HashMap<String, NodeTemplate>();
} }
this.nodeTemplates.put(key, nodeTemplatesItem); this.nodeTemplates.put(key, nodeTemplatesItem);
return this; return this;
...@@ -175,12 +174,13 @@ public class TopologyTemplate { ...@@ -175,12 +174,13 @@ public class TopologyTemplate {
**/ **/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
@Valid
public Map<String, Object> getNodeTemplates() { public Map<String, NodeTemplate> getNodeTemplates() {
return nodeTemplates; return nodeTemplates;
} }
public void setNodeTemplates(Map<String, Object> nodeTemplates) { public void setNodeTemplates(Map<String, NodeTemplate> nodeTemplates) {
this.nodeTemplates = nodeTemplates; this.nodeTemplates = nodeTemplates;
} }
......
...@@ -2,9 +2,6 @@ package nl.uva.sne.drip.model; ...@@ -2,9 +2,6 @@ package nl.uva.sne.drip.model;
import java.util.Objects; import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -12,20 +9,14 @@ import java.util.List; ...@@ -12,20 +9,14 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.data.annotation.Id;
/** /**
* ToscaTemplate * ToscaTemplate
*/ */
@Validated @Validated
@JsonInclude(Include.NON_NULL) @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-25T14:09:25.182Z")
public class ToscaTemplate { public class ToscaTemplate {
@Id
@JsonIgnore
private String id;
@JsonProperty("tosca_definitions_version") @JsonProperty("tosca_definitions_version")
private String toscaDefinitionsVersion = null; private String toscaDefinitionsVersion = null;
...@@ -97,23 +88,13 @@ public class ToscaTemplate { ...@@ -97,23 +88,13 @@ public class ToscaTemplate {
return this; return this;
} }
@JsonIgnore
public String getId() {
return id;
}
public void setID(String id) {
this.id = id;
}
/** /**
* Get toscaDefinitionsVersion * Get toscaDefinitionsVersion
*
* @return toscaDefinitionsVersion * @return toscaDefinitionsVersion
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getToscaDefinitionsVersion() { public String getToscaDefinitionsVersion() {
return toscaDefinitionsVersion; return toscaDefinitionsVersion;
} }
...@@ -129,12 +110,11 @@ public class ToscaTemplate { ...@@ -129,12 +110,11 @@ public class ToscaTemplate {
/** /**
* Get toscaDefaultNamespace * Get toscaDefaultNamespace
*
* @return toscaDefaultNamespace * @return toscaDefaultNamespace
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getToscaDefaultNamespace() { public String getToscaDefaultNamespace() {
return toscaDefaultNamespace; return toscaDefaultNamespace;
} }
...@@ -150,12 +130,11 @@ public class ToscaTemplate { ...@@ -150,12 +130,11 @@ public class ToscaTemplate {
/** /**
* Get templateName * Get templateName
*
* @return templateName * @return templateName
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getTemplateName() { public String getTemplateName() {
return templateName; return templateName;
} }
...@@ -171,7 +150,7 @@ public class ToscaTemplate { ...@@ -171,7 +150,7 @@ public class ToscaTemplate {
public ToscaTemplate addImportsItem(Map<String, String> importsItem) { public ToscaTemplate addImportsItem(Map<String, String> importsItem) {
if (this.imports == null) { if (this.imports == null) {
this.imports = new ArrayList<>(); this.imports = new ArrayList<Map<String, String>>();
} }
this.imports.add(importsItem); this.imports.add(importsItem);
return this; return this;
...@@ -179,10 +158,8 @@ public class ToscaTemplate { ...@@ -179,10 +158,8 @@ public class ToscaTemplate {
/** /**
* Get imports * Get imports
*
* @return imports * @return imports
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
@Valid @Valid
...@@ -210,12 +187,11 @@ public class ToscaTemplate { ...@@ -210,12 +187,11 @@ public class ToscaTemplate {
/** /**
* Get repositories * Get repositories
*
* @return repositories * @return repositories
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getRepositories() { public Map<String, String> getRepositories() {
return repositories; return repositories;
} }
...@@ -231,7 +207,7 @@ public class ToscaTemplate { ...@@ -231,7 +207,7 @@ public class ToscaTemplate {
public ToscaTemplate putDslDefinitionsItem(String key, String dslDefinitionsItem) { public ToscaTemplate putDslDefinitionsItem(String key, String dslDefinitionsItem) {
if (this.dslDefinitions == null) { if (this.dslDefinitions == null) {
this.dslDefinitions = new HashMap<>(); this.dslDefinitions = new HashMap<String, String>();
} }
this.dslDefinitions.put(key, dslDefinitionsItem); this.dslDefinitions.put(key, dslDefinitionsItem);
return this; return this;
...@@ -239,12 +215,11 @@ public class ToscaTemplate { ...@@ -239,12 +215,11 @@ public class ToscaTemplate {
/** /**
* Get dslDefinitions * Get dslDefinitions
*
* @return dslDefinitions * @return dslDefinitions
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getDslDefinitions() { public Map<String, String> getDslDefinitions() {
return dslDefinitions; return dslDefinitions;
} }
...@@ -260,7 +235,7 @@ public class ToscaTemplate { ...@@ -260,7 +235,7 @@ public class ToscaTemplate {
public ToscaTemplate putNodeTypesItem(String key, Object nodeTypesItem) { public ToscaTemplate putNodeTypesItem(String key, Object nodeTypesItem) {
if (this.nodeTypes == null) { if (this.nodeTypes == null) {
this.nodeTypes = new HashMap<>(); this.nodeTypes = new HashMap<String, Object>();
} }
this.nodeTypes.put(key, nodeTypesItem); this.nodeTypes.put(key, nodeTypesItem);
return this; return this;
...@@ -268,12 +243,11 @@ public class ToscaTemplate { ...@@ -268,12 +243,11 @@ public class ToscaTemplate {
/** /**
* Get nodeTypes * Get nodeTypes
*
* @return nodeTypes * @return nodeTypes
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getNodeTypes() { public Map<String, Object> getNodeTypes() {
return nodeTypes; return nodeTypes;
} }
...@@ -289,10 +263,8 @@ public class ToscaTemplate { ...@@ -289,10 +263,8 @@ public class ToscaTemplate {
/** /**
* Get topologyTemplate * Get topologyTemplate
*
* @return topologyTemplate * @return topologyTemplate
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
@Valid @Valid
...@@ -312,7 +284,7 @@ public class ToscaTemplate { ...@@ -312,7 +284,7 @@ public class ToscaTemplate {
public ToscaTemplate putRelationshipTypesItem(String key, Object relationshipTypesItem) { public ToscaTemplate putRelationshipTypesItem(String key, Object relationshipTypesItem) {
if (this.relationshipTypes == null) { if (this.relationshipTypes == null) {
this.relationshipTypes = new HashMap<>(); this.relationshipTypes = new HashMap<String, Object>();
} }
this.relationshipTypes.put(key, relationshipTypesItem); this.relationshipTypes.put(key, relationshipTypesItem);
return this; return this;
...@@ -320,12 +292,11 @@ public class ToscaTemplate { ...@@ -320,12 +292,11 @@ public class ToscaTemplate {
/** /**
* Get relationshipTypes * Get relationshipTypes
*
* @return relationshipTypes * @return relationshipTypes
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getRelationshipTypes() { public Map<String, Object> getRelationshipTypes() {
return relationshipTypes; return relationshipTypes;
} }
...@@ -341,7 +312,7 @@ public class ToscaTemplate { ...@@ -341,7 +312,7 @@ public class ToscaTemplate {
public ToscaTemplate putRelationshipTemplatesItem(String key, Object relationshipTemplatesItem) { public ToscaTemplate putRelationshipTemplatesItem(String key, Object relationshipTemplatesItem) {
if (this.relationshipTemplates == null) { if (this.relationshipTemplates == null) {
this.relationshipTemplates = new HashMap<>(); this.relationshipTemplates = new HashMap<String, Object>();
} }
this.relationshipTemplates.put(key, relationshipTemplatesItem); this.relationshipTemplates.put(key, relationshipTemplatesItem);
return this; return this;
...@@ -349,12 +320,11 @@ public class ToscaTemplate { ...@@ -349,12 +320,11 @@ public class ToscaTemplate {
/** /**
* Get relationshipTemplates * Get relationshipTemplates
*
* @return relationshipTemplates * @return relationshipTemplates
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getRelationshipTemplates() { public Map<String, Object> getRelationshipTemplates() {
return relationshipTemplates; return relationshipTemplates;
} }
...@@ -370,7 +340,7 @@ public class ToscaTemplate { ...@@ -370,7 +340,7 @@ public class ToscaTemplate {
public ToscaTemplate putCapabilityTypesItem(String key, Object capabilityTypesItem) { public ToscaTemplate putCapabilityTypesItem(String key, Object capabilityTypesItem) {
if (this.capabilityTypes == null) { if (this.capabilityTypes == null) {
this.capabilityTypes = new HashMap<>(); this.capabilityTypes = new HashMap<String, Object>();
} }
this.capabilityTypes.put(key, capabilityTypesItem); this.capabilityTypes.put(key, capabilityTypesItem);
return this; return this;
...@@ -378,12 +348,11 @@ public class ToscaTemplate { ...@@ -378,12 +348,11 @@ public class ToscaTemplate {
/** /**
* Get capabilityTypes * Get capabilityTypes
*
* @return capabilityTypes * @return capabilityTypes
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getCapabilityTypes() { public Map<String, Object> getCapabilityTypes() {
return capabilityTypes; return capabilityTypes;
} }
...@@ -399,7 +368,7 @@ public class ToscaTemplate { ...@@ -399,7 +368,7 @@ public class ToscaTemplate {
public ToscaTemplate putArtifactTypesItem(String key, Object artifactTypesItem) { public ToscaTemplate putArtifactTypesItem(String key, Object artifactTypesItem) {
if (this.artifactTypes == null) { if (this.artifactTypes == null) {
this.artifactTypes = new HashMap<>(); this.artifactTypes = new HashMap<String, Object>();
} }
this.artifactTypes.put(key, artifactTypesItem); this.artifactTypes.put(key, artifactTypesItem);
return this; return this;
...@@ -407,12 +376,11 @@ public class ToscaTemplate { ...@@ -407,12 +376,11 @@ public class ToscaTemplate {
/** /**
* Get artifactTypes * Get artifactTypes
*
* @return artifactTypes * @return artifactTypes
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getArtifactTypes() { public Map<String, Object> getArtifactTypes() {
return artifactTypes; return artifactTypes;
} }
...@@ -428,7 +396,7 @@ public class ToscaTemplate { ...@@ -428,7 +396,7 @@ public class ToscaTemplate {
public ToscaTemplate putDataTypesItem(String key, Object dataTypesItem) { public ToscaTemplate putDataTypesItem(String key, Object dataTypesItem) {
if (this.dataTypes == null) { if (this.dataTypes == null) {
this.dataTypes = new HashMap<>(); this.dataTypes = new HashMap<String, Object>();
} }
this.dataTypes.put(key, dataTypesItem); this.dataTypes.put(key, dataTypesItem);
return this; return this;
...@@ -436,12 +404,11 @@ public class ToscaTemplate { ...@@ -436,12 +404,11 @@ public class ToscaTemplate {
/** /**
* Get dataTypes * Get dataTypes
*
* @return dataTypes * @return dataTypes
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getDataTypes() { public Map<String, Object> getDataTypes() {
return dataTypes; return dataTypes;
} }
...@@ -457,7 +424,7 @@ public class ToscaTemplate { ...@@ -457,7 +424,7 @@ public class ToscaTemplate {
public ToscaTemplate putInterfaceTypesItem(String key, Object interfaceTypesItem) { public ToscaTemplate putInterfaceTypesItem(String key, Object interfaceTypesItem) {
if (this.interfaceTypes == null) { if (this.interfaceTypes == null) {
this.interfaceTypes = new HashMap<>(); this.interfaceTypes = new HashMap<String, Object>();
} }
this.interfaceTypes.put(key, interfaceTypesItem); this.interfaceTypes.put(key, interfaceTypesItem);
return this; return this;
...@@ -465,12 +432,11 @@ public class ToscaTemplate { ...@@ -465,12 +432,11 @@ public class ToscaTemplate {
/** /**
* Get interfaceTypes * Get interfaceTypes
*
* @return interfaceTypes * @return interfaceTypes
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getInterfaceTypes() { public Map<String, Object> getInterfaceTypes() {
return interfaceTypes; return interfaceTypes;
} }
...@@ -486,7 +452,7 @@ public class ToscaTemplate { ...@@ -486,7 +452,7 @@ public class ToscaTemplate {
public ToscaTemplate putPolicyTypesItem(String key, String policyTypesItem) { public ToscaTemplate putPolicyTypesItem(String key, String policyTypesItem) {
if (this.policyTypes == null) { if (this.policyTypes == null) {
this.policyTypes = new HashMap<>(); this.policyTypes = new HashMap<String, String>();
} }
this.policyTypes.put(key, policyTypesItem); this.policyTypes.put(key, policyTypesItem);
return this; return this;
...@@ -494,12 +460,11 @@ public class ToscaTemplate { ...@@ -494,12 +460,11 @@ public class ToscaTemplate {
/** /**
* Get policyTypes * Get policyTypes
*
* @return policyTypes * @return policyTypes
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, String> getPolicyTypes() { public Map<String, String> getPolicyTypes() {
return policyTypes; return policyTypes;
} }
...@@ -515,7 +480,7 @@ public class ToscaTemplate { ...@@ -515,7 +480,7 @@ public class ToscaTemplate {
public ToscaTemplate putGroupTypesItem(String key, Object groupTypesItem) { public ToscaTemplate putGroupTypesItem(String key, Object groupTypesItem) {
if (this.groupTypes == null) { if (this.groupTypes == null) {
this.groupTypes = new HashMap<>(); this.groupTypes = new HashMap<String, Object>();
} }
this.groupTypes.put(key, groupTypesItem); this.groupTypes.put(key, groupTypesItem);
return this; return this;
...@@ -523,12 +488,11 @@ public class ToscaTemplate { ...@@ -523,12 +488,11 @@ public class ToscaTemplate {
/** /**
* Get groupTypes * Get groupTypes
*
* @return groupTypes * @return groupTypes
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Map<String, Object> getGroupTypes() { public Map<String, Object> getGroupTypes() {
return groupTypes; return groupTypes;
} }
...@@ -544,12 +508,11 @@ public class ToscaTemplate { ...@@ -544,12 +508,11 @@ public class ToscaTemplate {
/** /**
* Get description * Get description
*
* @return description * @return description
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getDescription() { public String getDescription() {
return description; return description;
} }
...@@ -565,12 +528,11 @@ public class ToscaTemplate { ...@@ -565,12 +528,11 @@ public class ToscaTemplate {
/** /**
* Get templateAuthor * Get templateAuthor
*
* @return templateAuthor * @return templateAuthor
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getTemplateAuthor() { public String getTemplateAuthor() {
return templateAuthor; return templateAuthor;
} }
...@@ -579,6 +541,7 @@ public class ToscaTemplate { ...@@ -579,6 +541,7 @@ public class ToscaTemplate {
this.templateAuthor = templateAuthor; this.templateAuthor = templateAuthor;
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {
...@@ -588,24 +551,24 @@ public class ToscaTemplate { ...@@ -588,24 +551,24 @@ public class ToscaTemplate {
return false; return false;
} }
ToscaTemplate toscaTemplate = (ToscaTemplate) o; ToscaTemplate toscaTemplate = (ToscaTemplate) o;
return Objects.equals(this.toscaDefinitionsVersion, toscaTemplate.toscaDefinitionsVersion) return Objects.equals(this.toscaDefinitionsVersion, toscaTemplate.toscaDefinitionsVersion) &&
&& Objects.equals(this.toscaDefaultNamespace, toscaTemplate.toscaDefaultNamespace) Objects.equals(this.toscaDefaultNamespace, toscaTemplate.toscaDefaultNamespace) &&
&& Objects.equals(this.templateName, toscaTemplate.templateName) Objects.equals(this.templateName, toscaTemplate.templateName) &&
&& Objects.equals(this.imports, toscaTemplate.imports) Objects.equals(this.imports, toscaTemplate.imports) &&
&& Objects.equals(this.repositories, toscaTemplate.repositories) Objects.equals(this.repositories, toscaTemplate.repositories) &&
&& Objects.equals(this.dslDefinitions, toscaTemplate.dslDefinitions) Objects.equals(this.dslDefinitions, toscaTemplate.dslDefinitions) &&
&& Objects.equals(this.nodeTypes, toscaTemplate.nodeTypes) Objects.equals(this.nodeTypes, toscaTemplate.nodeTypes) &&
&& Objects.equals(this.topologyTemplate, toscaTemplate.topologyTemplate) Objects.equals(this.topologyTemplate, toscaTemplate.topologyTemplate) &&
&& Objects.equals(this.relationshipTypes, toscaTemplate.relationshipTypes) Objects.equals(this.relationshipTypes, toscaTemplate.relationshipTypes) &&
&& Objects.equals(this.relationshipTemplates, toscaTemplate.relationshipTemplates) Objects.equals(this.relationshipTemplates, toscaTemplate.relationshipTemplates) &&
&& Objects.equals(this.capabilityTypes, toscaTemplate.capabilityTypes) Objects.equals(this.capabilityTypes, toscaTemplate.capabilityTypes) &&
&& Objects.equals(this.artifactTypes, toscaTemplate.artifactTypes) Objects.equals(this.artifactTypes, toscaTemplate.artifactTypes) &&
&& Objects.equals(this.dataTypes, toscaTemplate.dataTypes) Objects.equals(this.dataTypes, toscaTemplate.dataTypes) &&
&& Objects.equals(this.interfaceTypes, toscaTemplate.interfaceTypes) Objects.equals(this.interfaceTypes, toscaTemplate.interfaceTypes) &&
&& Objects.equals(this.policyTypes, toscaTemplate.policyTypes) Objects.equals(this.policyTypes, toscaTemplate.policyTypes) &&
&& Objects.equals(this.groupTypes, toscaTemplate.groupTypes) Objects.equals(this.groupTypes, toscaTemplate.groupTypes) &&
&& Objects.equals(this.description, toscaTemplate.description) Objects.equals(this.description, toscaTemplate.description) &&
&& Objects.equals(this.templateAuthor, toscaTemplate.templateAuthor); Objects.equals(this.templateAuthor, toscaTemplate.templateAuthor);
} }
@Override @Override
...@@ -651,3 +614,4 @@ public class ToscaTemplate { ...@@ -651,3 +614,4 @@ public class ToscaTemplate {
return o.toString().replace("\n", "\n "); return o.toString().replace("\n", "\n ");
} }
} }
...@@ -2,22 +2,17 @@ package nl.uva.sne.drip.model; ...@@ -2,22 +2,17 @@ package nl.uva.sne.drip.model;
import java.util.Objects; import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import javax.validation.constraints.*;
import org.springframework.data.annotation.Id;
/** /**
* User * User
*/ */
@Validated @Validated
public class User { @javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2019-10-25T14:09:25.182Z")
public class User {
@JsonProperty("id") @JsonProperty("id")
@Id
private Long id = null; private Long id = null;
@JsonProperty("username") @JsonProperty("username")
...@@ -45,12 +40,11 @@ public class User { ...@@ -45,12 +40,11 @@ public class User {
/** /**
* Get id * Get id
*
* @return id * @return id
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public Long getId() { public Long getId() {
return id; return id;
} }
...@@ -66,12 +60,11 @@ public class User { ...@@ -66,12 +60,11 @@ public class User {
/** /**
* Get username * Get username
*
* @return username * @return username
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getUsername() { public String getUsername() {
return username; return username;
} }
...@@ -87,12 +80,11 @@ public class User { ...@@ -87,12 +80,11 @@ public class User {
/** /**
* Get firstName * Get firstName
*
* @return firstName * @return firstName
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getFirstName() { public String getFirstName() {
return firstName; return firstName;
} }
...@@ -108,12 +100,11 @@ public class User { ...@@ -108,12 +100,11 @@ public class User {
/** /**
* Get lastName * Get lastName
*
* @return lastName * @return lastName
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getLastName() { public String getLastName() {
return lastName; return lastName;
} }
...@@ -129,12 +120,11 @@ public class User { ...@@ -129,12 +120,11 @@ public class User {
/** /**
* Get email * Get email
*
* @return email * @return email
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getEmail() { public String getEmail() {
return email; return email;
} }
...@@ -150,12 +140,11 @@ public class User { ...@@ -150,12 +140,11 @@ public class User {
/** /**
* Get password * Get password
*
* @return password * @return password
* **/
*/
@ApiModelProperty(value = "") @ApiModelProperty(value = "")
public String getPassword() { public String getPassword() {
return password; return password;
} }
...@@ -171,12 +160,11 @@ public class User { ...@@ -171,12 +160,11 @@ public class User {
/** /**
* User Status * User Status
*
* @return userStatus * @return userStatus
* **/
*/
@ApiModelProperty(value = "User Status") @ApiModelProperty(value = "User Status")
public Integer getUserStatus() { public Integer getUserStatus() {
return userStatus; return userStatus;
} }
...@@ -185,6 +173,7 @@ public class User { ...@@ -185,6 +173,7 @@ public class User {
this.userStatus = userStatus; this.userStatus = userStatus;
} }
@Override @Override
public boolean equals(java.lang.Object o) { public boolean equals(java.lang.Object o) {
if (this == o) { if (this == o) {
...@@ -194,13 +183,13 @@ public class User { ...@@ -194,13 +183,13 @@ public class User {
return false; return false;
} }
User user = (User) o; User user = (User) o;
return Objects.equals(this.id, user.id) return Objects.equals(this.id, user.id) &&
&& Objects.equals(this.username, user.username) Objects.equals(this.username, user.username) &&
&& Objects.equals(this.firstName, user.firstName) Objects.equals(this.firstName, user.firstName) &&
&& Objects.equals(this.lastName, user.lastName) Objects.equals(this.lastName, user.lastName) &&
&& Objects.equals(this.email, user.email) Objects.equals(this.email, user.email) &&
&& Objects.equals(this.password, user.password) Objects.equals(this.password, user.password) &&
&& Objects.equals(this.userStatus, user.userStatus); Objects.equals(this.userStatus, user.userStatus);
} }
@Override @Override
...@@ -235,3 +224,4 @@ public class User { ...@@ -235,3 +224,4 @@ public class User {
return o.toString().replace("\n", "\n "); return o.toString().replace("\n", "\n ");
} }
} }
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.commons.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import nl.uva.sne.drip.model.NodeTemplate;
import nl.uva.sne.drip.model.ToscaTemplate;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author alogo
*/
public class TOSCAUtilsTest {
private static ToscaTemplate toscaTemplate;
public TOSCAUtilsTest() {
}
@BeforeClass
public static void setUpClass() throws IOException {
String toscaFilePath = "../TOSCA/application_example_output.yaml";
String ymlStr = new String(Files.readAllBytes(Paths.get(toscaFilePath)));
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
toscaTemplate = objectMapper.readValue(ymlStr, ToscaTemplate.class);
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getNodesByType method, of class TOSCAUtils.
*/
@Test
public void testGetNodesByType() {
System.out.println("getNodesByType");
String nodeTypeName = "tosca.nodes.ARTICONF.VM.topology";
List<Map<String, NodeTemplate>> result = testGetNodesByType(nodeTypeName);
assertEquals(1, result.size());
nodeTypeName = "tosca.nodes.ARTICONF.VM.Compute";
result = testGetNodesByType(nodeTypeName);
assertEquals(2, result.size());
}
/**
* Test of getRelatedNodes method, of class TOSCAUtils.
*/
@Test
public void testGetRelatedNodes() {
System.out.println("getRelatedNodes");
String nodeTypeName = "tosca.nodes.ARTICONF.VM.topology";
List<Map<String, NodeTemplate>> vmTopologies = TOSCAUtils.getNodesByType(toscaTemplate, nodeTypeName);
NodeTemplate vmTopology = vmTopologies.get(0).get(vmTopologies.get(0).keySet().iterator().next());
nodeTypeName = "tosca.nodes.ARTICONF.VM.Compute";
List<Map<String, NodeTemplate>> result = TOSCAUtils.getRelatedNodes(vmTopology, toscaTemplate);
assertEquals(2, result.size());
for (Map<String, NodeTemplate> node : result) {
String name = node.keySet().iterator().next();
assertEquals(nodeTypeName, node.get(name).getType());
}
}
/**
* Test of nodeIsOfType method, of class TOSCAUtils.
*/
@Test
public void testNodeIsOfType() {
System.out.println("nodeIsOfType");
String nodeTypeName = "tosca.nodes.ARTICONF.VM.topology";
List<Map<String, NodeTemplate>> vmTopologies = TOSCAUtils.getNodesByType(toscaTemplate, nodeTypeName);
NodeTemplate vmTopology = vmTopologies.get(0).get(vmTopologies.get(0).keySet().iterator().next());
boolean expResult = true;
boolean result = TOSCAUtils.nodeIsOfType(vmTopology, nodeTypeName);
assertEquals(expResult, result);
expResult = false;
nodeTypeName = "tosca.nodes.ARTICONF";
result = TOSCAUtils.nodeIsOfType(vmTopology, nodeTypeName);
assertEquals(expResult, result);
}
/**
* Test of getNodeProperty method, of class TOSCAUtils.
*/
@Test
public void testGetNodeProperty() {
System.out.println("getNodeProperty");
testGetVMProperties();
}
private void testGetVMProperties() {
String nodeTypeName = "tosca.nodes.ARTICONF.VM.Compute";
List<Map<String, NodeTemplate>> vms = TOSCAUtils.getNodesByType(toscaTemplate, nodeTypeName);
assertEquals(2, vms.size());
Map<String, Object> vmProertyMap = new HashMap<>();
vmProertyMap.put("disk_size", "50000 MB");
vmProertyMap.put("host_name", "vm");
vmProertyMap.put("mem_size", "6000 MB");
vmProertyMap.put("num_cores", 2);
vmProertyMap.put("os", "ubuntu 16");
vmProertyMap.put("user_name", "vm_user");
for (Map<String, NodeTemplate> vmMap : vms) {
Set<String> keys = vmProertyMap.keySet();
NodeTemplate vm = vmMap.get(vmMap.keySet().iterator().next());
for (String propName : keys) {
Object result = TOSCAUtils.getNodeProperty(vm, propName);
assertEquals(vmProertyMap.get(propName), result);
}
}
}
private List<Map<String, NodeTemplate>> testGetNodesByType(String nodeTypeName) {
List<Map<String, NodeTemplate>> result = TOSCAUtils.getNodesByType(toscaTemplate, nodeTypeName);
for (Map<String, NodeTemplate> node : result) {
String name = node.keySet().iterator().next();
assertEquals(nodeTypeName, node.get(name).getType());
}
return result;
}
}
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