summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-03-10 02:44:53 -0700
committersebdet <sebastien.determe@intl.att.com>2020-03-10 15:42:26 -0700
commit8604d37f2f6bdd011de62ec474b6883413d30348 (patch)
treedc3ec068758b17ab33d35865457cd6c352fa147c /src
parent3af9347e47302e3f6754cba8ea2b63772980a5d9 (diff)
Fix the tosca converter
Fix the new tosca converter to support metadata section Issue-ID: CLAMP-580 Signed-off-by: sebdet <sebastien.determe@intl.att.com> Change-Id: I9068bd9dc89851c630660a7f78fae1cb70bdc178
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/MetadataParser.java (renamed from src/main/java/org/onap/clamp/loop/service/ServiceRepository.java)26
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/Template.java66
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/TemplateField.java (renamed from src/main/java/org/onap/clamp/clds/tosca/update/Field.java)33
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/ToscaConverterManager.java (renamed from src/main/java/org/onap/clamp/clds/tosca/update/TemplateManagement.java)73
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/ToscaConverterToJson.java (renamed from src/main/java/org/onap/clamp/clds/tosca/update/ParserToJson.java)48
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/ToscaElement.java (renamed from src/main/java/org/onap/clamp/clds/tosca/update/Component.java)6
-rw-r--r--src/main/java/org/onap/clamp/clds/tosca/update/ToscaItemsParser.java (renamed from src/main/java/org/onap/clamp/clds/tosca/update/Extractor.java)83
-rw-r--r--src/main/java/org/onap/clamp/loop/service/CsarServiceInstaller.java2
-rw-r--r--src/main/java/org/onap/clamp/policy/Policy.java8
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java21
-rw-r--r--src/main/resources/META-INF/resources/swagger.html2
-rw-r--r--src/main/resources/application-noaaf.properties7
-rw-r--r--src/main/resources/clds/tosca_update/default-tosca-types.yaml (renamed from src/main/resources/clds/tosca_update/defaultToscaTypes.yaml)0
-rw-r--r--src/main/resources/clds/tosca_update/templates.properties15
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java8
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java22
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java18
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java6
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/ToscaConverterManagerTest.java (renamed from src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java)118
-rw-r--r--src/test/java/org/onap/clamp/clds/tosca/update/ToscaElementTest.java (renamed from src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java)12
-rw-r--r--src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java5
21 files changed, 297 insertions, 282 deletions
diff --git a/src/main/java/org/onap/clamp/loop/service/ServiceRepository.java b/src/main/java/org/onap/clamp/clds/tosca/update/MetadataParser.java
index a6c5ff187..fb70231fb 100644
--- a/src/main/java/org/onap/clamp/loop/service/ServiceRepository.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/MetadataParser.java
@@ -1,8 +1,9 @@
+
/*-
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,12 +22,25 @@
*
*/
-package org.onap.clamp.loop.service;
+package org.onap.clamp.clds.tosca.update;
-import org.springframework.data.repository.CrudRepository;
-import org.springframework.stereotype.Repository;
+import com.google.gson.JsonObject;
+import org.onap.clamp.tosca.DictionaryService;
-@Repository
-public interface ServiceRepository extends CrudRepository<Service, String> {
+public class MetadataParser {
+ /**
+ * This method is used to start the processing of the metadata field.
+ *
+ * @param property The property metadata as Json Object
+ * @param dictionaryService the Dictionary service, if null nothing will be done
+ * @return The jsonObject structure that must be added to the json schema
+ */
+ public static JsonObject processAllMetadataElement(Property property, DictionaryService dictionaryService) {
+ if (dictionaryService != null) {
+ return null;
+ } else {
+ return null;
+ }
+ }
}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/Template.java b/src/main/java/org/onap/clamp/clds/tosca/update/Template.java
index 4507e3d71..6a531aeea 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/Template.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/Template.java
@@ -33,16 +33,16 @@ public class Template {
* name parameter is used as "key", in the LinkedHashMap of Templates.
*/
private String name;
- private List<Field> fields;
+ private List<TemplateField> templateFields;
public Template(String name) {
this.name = name;
- this.fields = new ArrayList<>();
+ this.templateFields = new ArrayList<>();
}
- public Template(String name, List<Field> fields) {
+ public Template(String name, List<TemplateField> templateFields) {
this.name = name;
- this.fields = fields;
+ this.templateFields = templateFields;
}
public String getName() {
@@ -53,12 +53,12 @@ public class Template {
this.name = name;
}
- public List<Field> getFields() {
- return fields;
+ public List<TemplateField> getTemplateFields() {
+ return templateFields;
}
- public void setFields(List<Field> fields) {
- this.fields = fields;
+ public void setTemplateFields(List<TemplateField> templateFields) {
+ this.templateFields = templateFields;
}
/**
@@ -68,8 +68,8 @@ public class Template {
* @return Ture if it exists, false otherwise
*/
public boolean hasFields(String fieldName) {
- for (Field field : this.getFields()) {
- if (field.getTitle().equals(fieldName)) {
+ for (TemplateField templateField : this.getTemplateFields()) {
+ if (templateField.getTitle().equals(fieldName)) {
return true;
}
}
@@ -82,21 +82,21 @@ public class Template {
* @param fieldName The field name
* @return THe Field found
*/
- public Field getSpecificField(String fieldName) {
- for (Field field : this.getFields()) {
- if (field.getTitle().equals(fieldName)) {
- return field;
+ public TemplateField getSpecificField(String fieldName) {
+ for (TemplateField templateField : this.getTemplateFields()) {
+ if (templateField.getTitle().equals(fieldName)) {
+ return templateField;
}
}
return null;
}
- public void addField(Field field) {
- fields.add(field);
+ public void addField(TemplateField templateField) {
+ templateFields.add(templateField);
}
- public void removeField(Field field) {
- fields.remove(field);
+ public void removeField(TemplateField templateField) {
+ templateFields.remove(templateField);
}
/**
@@ -106,9 +106,9 @@ public class Template {
* @param state True or false
*/
public void setVisibility(String nameField, boolean state) {
- for (Field field : this.fields) {
- if (field.getTitle().equals(nameField)) {
- field.setVisible(state);
+ for (TemplateField templateField : this.templateFields) {
+ if (templateField.getTitle().equals(nameField)) {
+ templateField.setVisible(state);
}
}
}
@@ -120,9 +120,9 @@ public class Template {
* @param state true or false
*/
public void setStatic(String nameField, boolean state) {
- for (Field field : this.fields) {
- if (field.getTitle().equals(nameField)) {
- field.setStaticValue(state);
+ for (TemplateField templateField : this.templateFields) {
+ if (templateField.getTitle().equals(nameField)) {
+ templateField.setStaticValue(state);
}
}
}
@@ -134,9 +134,9 @@ public class Template {
* @param newValue The new value as Object
*/
public void updateValueField(String nameField, Object newValue) {
- for (Field field : this.fields) {
- if (field.getTitle().equals(nameField)) {
- field.setValue(newValue);
+ for (TemplateField templateField : this.templateFields) {
+ if (templateField.getTitle().equals(nameField)) {
+ templateField.setValue(newValue);
}
}
}
@@ -149,18 +149,18 @@ public class Template {
*/
public boolean checkFields(Template template) {
boolean duplicateFields = false;
- if (template.getFields().size() == this.getFields().size()) {
+ if (template.getTemplateFields().size() == this.getTemplateFields().size()) {
int countMatchingFields = 0;
//loop each component of first
- for (Field templateFieldToCheck : template.getFields()) {
- for (Field templateField : this.getFields()) {
+ for (TemplateField templateFieldToCheck : template.getTemplateFields()) {
+ for (TemplateField templateField : this.getTemplateFields()) {
if (templateFieldToCheck.compareWithField(templateField)) {
countMatchingFields++;
}
}
}
- if (template.getFields().size() == countMatchingFields) {
+ if (template.getTemplateFields().size() == countMatchingFields) {
duplicateFields = true;
}
}
@@ -212,13 +212,13 @@ public class Template {
*/
public void injectStaticValue(JsonObject jsonSchema, String fieldName) {
if (isVisible(fieldName)) {
- Field toInject = this.getSpecificField(fieldName);
+ TemplateField toInject = this.getSpecificField(fieldName);
jsonSchema.addProperty(fieldName, (String) toInject.getValue());
}
}
@Override
public String toString() {
- return " fields : " + fields;
+ return " templateFields : " + templateFields;
}
}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/Field.java b/src/main/java/org/onap/clamp/clds/tosca/update/TemplateField.java
index e01f14c43..34446436a 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/Field.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/TemplateField.java
@@ -23,13 +23,13 @@
package org.onap.clamp.clds.tosca.update;
-public class Field {
+public class TemplateField {
private String title;
private Object value;
private Boolean visible;
private Boolean staticValue;
- public Field(String title) {
+ public TemplateField(String title) {
this.title = title;
}
@@ -41,7 +41,7 @@ public class Field {
* @param visible visible or not
* @param staticValue The static value
*/
- public Field(String title, Object value, Boolean visible, Boolean staticValue) {
+ public TemplateField(String title, Object value, Boolean visible, Boolean staticValue) {
this.title = title;
this.value = value;
this.visible = visible;
@@ -98,18 +98,18 @@ public class Field {
return false;
}
- Field field = (Field) otherField;
+ TemplateField templateField = (TemplateField) otherField;
- if (title != null ? !title.equals(field.title) : field.title != null) {
+ if (title != null ? !title.equals(templateField.title) : templateField.title != null) {
return false;
}
- if (value != null ? !value.equals(field.value) : field.value != null) {
+ if (value != null ? !value.equals(templateField.value) : templateField.value != null) {
return false;
}
- if (visible != null ? !visible.equals(field.visible) : field.visible != null) {
+ if (visible != null ? !visible.equals(templateField.visible) : templateField.visible != null) {
return false;
}
- return staticValue != null ? staticValue.equals(field.staticValue) : field.staticValue == null;
+ return staticValue != null ? staticValue.equals(templateField.staticValue) : templateField.staticValue == null;
}
@Override
@@ -121,9 +121,9 @@ public class Field {
return false;
}
- Field field = (Field) object;
+ TemplateField templateField = (TemplateField) object;
- return title != null ? title.equals(field.title) : field.title == null;
+ return title != null ? title.equals(templateField.title) : templateField.title == null;
}
@Override
@@ -134,14 +134,15 @@ public class Field {
/**
* This method test the entire equality.
*
- * @param field1 object one
- * @param field2 object two
+ * @param templateField1 object one
+ * @param templateField2 object two
* @return true if they are totally equals (all attributes, false otherwise
*/
- public static boolean fieldsEquals(Field field1, Field field2) {
- return (field2.getTitle().equals(field1.getTitle()) && field2.getValue().equals(field1.getValue())
- && field2.getVisible().equals(field1.getVisible())
- && field2.getStaticValue().equals(field1.getStaticValue()));
+ public static boolean fieldsEquals(TemplateField templateField1, TemplateField templateField2) {
+ return (templateField2.getTitle().equals(templateField1.getTitle())
+ && templateField2.getValue().equals(templateField1.getValue())
+ && templateField2.getVisible().equals(templateField1.getVisible())
+ && templateField2.getStaticValue().equals(templateField1.getStaticValue()));
}
}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/TemplateManagement.java b/src/main/java/org/onap/clamp/clds/tosca/update/ToscaConverterManager.java
index 743077151..b3224b045 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/TemplateManagement.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/ToscaConverterManager.java
@@ -32,25 +32,26 @@ import java.util.List;
import java.util.Map;
import org.onap.clamp.clds.util.JsonUtils;
-public class TemplateManagement {
+public class ToscaConverterManager {
private LinkedHashMap<String, Template> templates;
- private LinkedHashMap<String, Component> components;
- private ParserToJson parserToJson;
- private Extractor extractor;
+ private LinkedHashMap<String, ToscaElement> components;
+ private ToscaConverterToJson toscaConverterToJson;
+ private ToscaItemsParser toscaItemsParser;
/**
* Constructor.
*
- * @param yamlContent Yaml content as string
- * @param templateProperties template properties as string
+ * @param toscaYamlContent Policy Tosca Yaml content as string
+ * @param nativeToscaDatatypes The tosca yaml with tosca native datatypes
+ * @param templateProperties template properties as string
* @throws IOException in case of failure
*/
- public TemplateManagement(String yamlContent, String nativeComponent, String templateProperties)
+ public ToscaConverterManager(String toscaYamlContent, String nativeToscaDatatypes, String templateProperties)
throws IOException {
- if (yamlContent != null && !yamlContent.isEmpty()) {
- this.extractor = new Extractor(yamlContent, nativeComponent);
- this.components = extractor.getAllItems();
+ if (toscaYamlContent != null && !toscaYamlContent.isEmpty()) {
+ this.toscaItemsParser = new ToscaItemsParser(toscaYamlContent, nativeToscaDatatypes);
+ this.components = toscaItemsParser.getAllItemsFound();
this.templates = initializeTemplates(templateProperties);
}
else {
@@ -59,20 +60,20 @@ public class TemplateManagement {
}
//GETTERS & SETTERS
- public LinkedHashMap<String, Component> getComponents() {
+ public LinkedHashMap<String, ToscaElement> getComponents() {
return components;
}
- public void setComponents(LinkedHashMap<String, Component> components) {
+ public void setComponents(LinkedHashMap<String, ToscaElement> components) {
this.components = components;
}
- public ParserToJson getParseToJson() {
- return parserToJson;
+ public ToscaConverterToJson getParseToJson() {
+ return toscaConverterToJson;
}
- public void setParseToJson(ParserToJson parserToJson) {
- this.parserToJson = parserToJson;
+ public void setParseToJson(ToscaConverterToJson toscaConverterToJson) {
+ this.toscaConverterToJson = toscaConverterToJson;
}
public LinkedHashMap<String, Template> getTemplates() {
@@ -83,18 +84,18 @@ public class TemplateManagement {
this.templates = templates;
}
- public Extractor getExtractor() {
- return extractor;
+ public ToscaItemsParser getToscaItemsParser() {
+ return toscaItemsParser;
}
/**
* Add a template.
*
- * @param name name
- * @param fields fields
+ * @param name name
+ * @param templateFields fields
*/
- public void addTemplate(String name, List<Field> fields) {
- Template template = new Template(name, fields);
+ public void addTemplate(String name, List<TemplateField> templateFields) {
+ Template template = new Template(name, templateFields);
//If it is true, the operation does not have any interest :
// replace OR put two different object with the same body
if (!templates.containsKey(template.getName()) || !this.hasTemplate(template)) {
@@ -114,18 +115,18 @@ public class TemplateManagement {
/**
* Update Template : adding with true flag, removing with false.
*
- * @param nameTemplate name template
- * @param field field name
- * @param operation operation
+ * @param nameTemplate name template
+ * @param templateField field name
+ * @param operation operation
*/
- public void updateTemplate(String nameTemplate, Field field, Boolean operation) {
+ public void updateTemplate(String nameTemplate, TemplateField templateField, Boolean operation) {
// Operation = true && field is not present => add Field
- if (operation && !this.templates.get(nameTemplate).getFields().contains(field)) {
- this.templates.get(nameTemplate).addField(field);
+ if (operation && !this.templates.get(nameTemplate).getTemplateFields().contains(templateField)) {
+ this.templates.get(nameTemplate).addField(templateField);
}
// Operation = false && field is present => remove Field
- else if (!operation && this.templates.get(nameTemplate).getFields().contains(field)) {
- this.templates.get(nameTemplate).removeField(field);
+ else if (!operation && this.templates.get(nameTemplate).getTemplateFields().contains(templateField)) {
+ this.templates.get(nameTemplate).removeField(templateField);
}
}
@@ -151,12 +152,12 @@ public class TemplateManagement {
* @param componentName name
* @return an json object
*/
- public JsonObject launchTranslation(String componentName) throws UnknownComponentException {
- this.parserToJson = new ParserToJson(components, templates);
- if (parserToJson.matchComponent(componentName) == null) {
+ public JsonObject startConversionToJson(String componentName) throws UnknownComponentException {
+ this.toscaConverterToJson = new ToscaConverterToJson(components, templates);
+ if (toscaConverterToJson.matchComponent(componentName) == null) {
throw new UnknownComponentException(componentName);
}
- return parserToJson.getJsonProcess(componentName, "object");
+ return toscaConverterToJson.getJsonProcess(componentName, "object");
}
/**
@@ -180,8 +181,8 @@ public class TemplateManagement {
Object fieldValue = bodyFieldAsJson.get("defaultValue").getAsString();
Boolean fieldVisible = bodyFieldAsJson.get("visible").getAsBoolean();
Boolean fieldStatic = bodyFieldAsJson.get("static").getAsBoolean();
- Field bodyField = new Field(fieldName, fieldValue, fieldVisible, fieldStatic);
- template.getFields().add(bodyField);
+ TemplateField bodyTemplateField = new TemplateField(fieldName, fieldValue, fieldVisible, fieldStatic);
+ template.getTemplateFields().add(bodyTemplateField);
}
generatedTemplates.put(template.getName(), template);
}
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/ParserToJson.java b/src/main/java/org/onap/clamp/clds/tosca/update/ToscaConverterToJson.java
index 3c5cf975b..297d568be 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/ParserToJson.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/ToscaConverterToJson.java
@@ -29,12 +29,20 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
+import org.onap.clamp.tosca.DictionaryService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
-public class ParserToJson {
- private LinkedHashMap<String, Component> components;
+@Component
+public class ToscaConverterToJson {
+ private LinkedHashMap<String, ToscaElement> components;
private LinkedHashMap<String, Template> templates;
- public ParserToJson(LinkedHashMap<String, Component> components, LinkedHashMap<String, Template> templates) {
+ // if this one is set, the dictionary mechanism is enabled
+ @Autowired
+ private DictionaryService dictionaryService;
+
+ public ToscaConverterToJson(LinkedHashMap<String, ToscaElement> components, LinkedHashMap<String, Template> templates) {
this.components = components;
this.templates = templates;
}
@@ -61,28 +69,28 @@ public class ParserToJson {
/**
* Return the classical/general fields of the component, & launch the properties deployment.
*
- * @param component the compo
+ * @param toscaElement the compo
* @return a json object
*/
- public JsonObject getFieldAsObject(Component component) {
+ public JsonObject getFieldAsObject(ToscaElement toscaElement) {
JsonObject globalFields = new JsonObject();
if (templates.get("object").hasFields("title")) {
- globalFields.addProperty("title", component.getName());
+ globalFields.addProperty("title", toscaElement.getName());
}
if (templates.get("object").hasFields("type")) {
globalFields.addProperty("type", "object");
}
if (templates.get("object").hasFields("description")) {
- if (component.getDescription() != null) {
- globalFields.addProperty("description", component.getDescription());
+ if (toscaElement.getDescription() != null) {
+ globalFields.addProperty("description", toscaElement.getDescription());
}
}
if (templates.get("object").hasFields("required")) {
- globalFields.add("required", this.getRequirements(component.getName()));
+ globalFields.add("required", this.getRequirements(toscaElement.getName()));
}
if (templates.get("object").hasFields("properties")) {
- globalFields.add("properties", this.deploy(component.getName()));
+ globalFields.add("properties", this.deploy(toscaElement.getName()));
}
return globalFields;
}
@@ -95,7 +103,7 @@ public class ParserToJson {
*/
public JsonArray getRequirements(String nameComponent) {
JsonArray requirements = new JsonArray();
- Component toParse = components.get(nameComponent);
+ ToscaElement toParse = components.get(nameComponent);
//Check for a father component, and launch the same process
if (!toParse.getDerivedFrom().equals("tosca.datatypes.Root")
&& !toParse.getDerivedFrom().equals("tosca.policies.Root")) {
@@ -121,7 +129,7 @@ public class ParserToJson {
*/
public JsonObject deploy(String nameComponent) {
JsonObject jsonSchema = new JsonObject();
- Component toParse = components.get(nameComponent);
+ ToscaElement toParse = components.get(nameComponent);
//Check for a father component, and launch the same process
if (!toParse.getDerivedFrom().equals("tosca.datatypes.Root")
&& !toParse.getDerivedFrom().equals("tosca.policies.Root")) {
@@ -212,6 +220,8 @@ public class ParserToJson {
}
break;
case "metadata":
+ propertiesInJson.add("enum", MetadataParser.processAllMetadataElement(property,
+ dictionaryService));
break;
case "constraints":
property.addConstraintsAsJson(propertiesInJson,
@@ -222,7 +232,7 @@ public class ParserToJson {
//Here, a way to check if entry is a component (datatype) or a simple string
if (matchComponent(this.extractSpecificFieldFromMap(property, "entry_schema")) != null) {
String nameComponent = this.extractSpecificFieldFromMap(property, "entry_schema");
- ParserToJson child = new ParserToJson(components, templates);
+ ToscaConverterToJson child = new ToscaConverterToJson(components, templates);
JsonObject propertiesContainer = new JsonObject();
switch ((String) property.getItems().get("type")) {
@@ -270,17 +280,17 @@ public class ParserToJson {
* @param name the name
* @return a component
*/
- public Component matchComponent(String name) {
- Component correspondingComponent = null;
+ public ToscaElement matchComponent(String name) {
+ ToscaElement correspondingToscaElement = null;
if (components == null) {
return null;
}
- for (Component component : components.values()) {
- if (component.getName().equals(name)) {
- correspondingComponent = component;
+ for (ToscaElement toscaElement : components.values()) {
+ if (toscaElement.getName().equals(name)) {
+ correspondingToscaElement = toscaElement;
}
}
- return correspondingComponent;
+ return correspondingToscaElement;
}
/**
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/Component.java b/src/main/java/org/onap/clamp/clds/tosca/update/ToscaElement.java
index 6db129d1a..d702cda55 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/Component.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/ToscaElement.java
@@ -26,7 +26,7 @@ package org.onap.clamp.clds.tosca.update;
import java.util.ArrayList;
import java.util.LinkedHashMap;
-public class Component {
+public class ToscaElement {
/**
* name parameter is used as "key", in the LinkedHashMap of Components.
@@ -38,7 +38,7 @@ public class Component {
private String description;
private LinkedHashMap<String, Property> properties;
- public Component() {
+ public ToscaElement() {
}
/**
@@ -49,7 +49,7 @@ public class Component {
* @param description description
*/
@SuppressWarnings({"unchecked", "rawtypes"})
- public Component(String name, String derivedFrom, String description) {
+ public ToscaElement(String name, String derivedFrom, String description) {
super();
this.name = name;
this.derivedFrom = derivedFrom;
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/Extractor.java b/src/main/java/org/onap/clamp/clds/tosca/update/ToscaItemsParser.java
index c6eabcd34..443a4b0cd 100644
--- a/src/main/java/org/onap/clamp/clds/tosca/update/Extractor.java
+++ b/src/main/java/org/onap/clamp/clds/tosca/update/ToscaItemsParser.java
@@ -23,64 +23,55 @@
package org.onap.clamp.clds.tosca.update;
+import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import org.yaml.snakeyaml.Yaml;
-public class Extractor {
- private LinkedHashMap<String, Component> allItems;
- private String source;
- private String nativeComponent;
+public class ToscaItemsParser {
+ private LinkedHashMap<String, ToscaElement> allItemsFound;
/**
* Constructor.
*
- * @param toParse Tosca to parse
- * @param nativeComponent The policy type to scan
+ * @param toscaYaml The tosca to parse
+ * @param toscaNativeDataTypeYaml THe name of the policy type to search
*/
- public Extractor(String toParse, String nativeComponent) {
+ public ToscaItemsParser(String toscaYaml, String toscaNativeDataTypeYaml) {
+ this.allItemsFound = searchAllToscaElements(toscaYaml, toscaNativeDataTypeYaml);
+ }
- this.source = toParse;
- this.nativeComponent = nativeComponent;
- allItems = new LinkedHashMap<String, Component>();
- getAllAsMaps();
+ public LinkedHashMap<String, ToscaElement> getAllItemsFound() {
+ return allItemsFound;
}
- public LinkedHashMap<String, Component> getAllItems() {
- return allItems;
+ private static LinkedHashMap<String, Object> searchAllDataTypesAndPolicyTypes(String toscaYaml) {
+ LinkedHashMap<String, LinkedHashMap<String, Object>> file =
+ (LinkedHashMap<String, LinkedHashMap<String, Object>>) new Yaml().load(toscaYaml);
+ // Get DataTypes
+ LinkedHashMap<String, Object> allItemsFound = file.get("data_types");
+ allItemsFound = (allItemsFound == null) ? (new LinkedHashMap<>()) : allItemsFound;
+ // Put the policies and datatypes in the same collection
+ allItemsFound.putAll(file.get("policy_types"));
+ return allItemsFound;
}
- public String getSource() {
- return source;
+ private static LinkedHashMap<String, Object> searchAllNativeToscaDataTypes(String toscaNativeYaml) {
+ return ((LinkedHashMap<String, LinkedHashMap<String, Object>>) new Yaml().load(toscaNativeYaml))
+ .get("data_types");
}
/**
* Yaml Parse gets raw policies and datatypes, in different sections : necessary to extract
* all entities and put them at the same level.
*
- * @return an object
+ * @return a map
*/
- @SuppressWarnings("unchecked")
- public LinkedHashMap<String, Object> getAllAsMaps() {
- Yaml yaml = new Yaml();
- Object contentFile = yaml.load(source);
- LinkedHashMap<String, LinkedHashMap<String, Object>> file =
- (LinkedHashMap<String, LinkedHashMap<String, Object>>) contentFile;
- // Get DataTypes
- LinkedHashMap<String, Object> dataTypes = file.get("data_types");
- dataTypes = (dataTypes == null) ? (new LinkedHashMap<>()) : dataTypes;
- // Get Policies : first, get topology and after extract policies from it
- LinkedHashMap<String, Object> policyTypes = file.get("policy_types");
- // Put the policies and datatypes in the same collection
- dataTypes.putAll(policyTypes);
-
- Object contentNativeFile = yaml.load(nativeComponent);
- LinkedHashMap<String, Object> dataTypesEmbedded =
- ((LinkedHashMap<String, LinkedHashMap<String, Object>>) contentNativeFile).get("data_types");
- dataTypes.putAll(dataTypesEmbedded);
-
- parseInComponent(dataTypes);
- return dataTypes;
+ private static LinkedHashMap<String, ToscaElement> searchAllToscaElements(String toscaYaml,
+ String nativeToscaYaml) {
+ LinkedHashMap<String, Object> allItemsFound = searchAllDataTypesAndPolicyTypes(toscaYaml);
+ allItemsFound.putAll(searchAllNativeToscaDataTypes(nativeToscaYaml));
+ return parseAllItemsFound(allItemsFound);
}
/**
@@ -88,17 +79,18 @@ public class Extractor {
*
* @param allMaps maps
*/
- @SuppressWarnings("unchecked")
- public void parseInComponent(LinkedHashMap<String, Object> allMaps) {
+ private static LinkedHashMap<String, ToscaElement> parseAllItemsFound(LinkedHashMap<String, Object> allMaps) {
+ LinkedHashMap<String, ToscaElement> allItemsFound = new LinkedHashMap<String, ToscaElement>();
//Component creations, from the file maps
for (Entry<String, Object> itemToParse : allMaps.entrySet()) {
LinkedHashMap<String, Object> componentBody = (LinkedHashMap<String, Object>) itemToParse.getValue();
- Component component = new Component(itemToParse.getKey(), (String) componentBody.get("derived_from"),
- (String) componentBody.get("description"));
+ ToscaElement toscaElement =
+ new ToscaElement(itemToParse.getKey(), (String) componentBody.get("derived_from"),
+ (String) componentBody.get("description"));
//If policy, version and type_version :
if (componentBody.get("type_version") != null) {
- component.setVersion((String) componentBody.get("type_version"));
- component.setTypeVersion((String) componentBody.get("type_version"));
+ toscaElement.setVersion((String) componentBody.get("type_version"));
+ toscaElement.setTypeVersion((String) componentBody.get("type_version"));
}
//Properties creation, from the map
if (componentBody.get("properties") != null) {
@@ -107,10 +99,11 @@ public class Extractor {
for (Entry<String, Object> itemToProperty : properties.entrySet()) {
Property property = new Property(itemToProperty.getKey(),
(LinkedHashMap<String, Object>) itemToProperty.getValue());
- component.addProperties(property);
+ toscaElement.addProperties(property);
}
}
- this.allItems.put(component.getName(), component);
+ allItemsFound.put(toscaElement.getName(), toscaElement);
}
+ return allItemsFound;
}
}
diff --git a/src/main/java/org/onap/clamp/loop/service/CsarServiceInstaller.java b/src/main/java/org/onap/clamp/loop/service/CsarServiceInstaller.java
index 889125fee..b7ed1de9a 100644
--- a/src/main/java/org/onap/clamp/loop/service/CsarServiceInstaller.java
+++ b/src/main/java/org/onap/clamp/loop/service/CsarServiceInstaller.java
@@ -54,7 +54,7 @@ public class CsarServiceInstaller {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarServiceInstaller.class);
@Autowired
- ServiceRepository serviceRepository;
+ ServicesRepository serviceRepository;
@Autowired
CdsServices cdsServices;
diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java
index d52e418e3..c9055bf9d 100644
--- a/src/main/java/org/onap/clamp/policy/Policy.java
+++ b/src/main/java/org/onap/clamp/policy/Policy.java
@@ -44,7 +44,7 @@ import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.json.JSONObject;
-import org.onap.clamp.clds.tosca.update.TemplateManagement;
+import org.onap.clamp.clds.tosca.update.ToscaConverterManager;
import org.onap.clamp.clds.tosca.update.UnknownComponentException;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
@@ -300,9 +300,9 @@ public abstract class Policy extends AuditEntity {
public static JsonObject generateJsonRepresentationFromToscaModel(String policyToscaModel,
String policyModelType)
throws IOException, UnknownComponentException {
- return new TemplateManagement(policyToscaModel,ResourceFileUtil.getResourceAsString(
- "clds/tosca_update/defaultToscaTypes.yaml"),
+ return new ToscaConverterManager(policyToscaModel,ResourceFileUtil.getResourceAsString(
+ "clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"))
- .launchTranslation(policyModelType);
+ .startConversionToJson(policyModelType);
}
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
index 357a96d21..ad6cbd941 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
@@ -23,11 +23,11 @@
package org.onap.clamp.policy.operational;
-import com.google.gson.JsonObject;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.template.PolicyModelsRepository;
import org.onap.clamp.policy.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -37,9 +37,13 @@ public class OperationalPolicyService implements PolicyService<OperationalPolicy
private final OperationalPolicyRepository operationalPolicyRepository;
+ private final PolicyModelsRepository policyModelsRepository;
+
@Autowired
- public OperationalPolicyService(OperationalPolicyRepository repository) {
+ public OperationalPolicyService(OperationalPolicyRepository repository,
+ PolicyModelsRepository policyModelsRepository) {
this.operationalPolicyRepository = repository;
+ this.policyModelsRepository = policyModelsRepository;
}
@Override
@@ -49,10 +53,8 @@ public class OperationalPolicyService implements PolicyService<OperationalPolicy
.map(policy ->
operationalPolicyRepository
.findById(policy.getName())
- .map(p -> setConfigurationJson(p, policy))
- .orElse(new OperationalPolicy(policy.getName(), loop,
- policy.getConfigurationsJson(),
- policy.getPolicyModel(), null, policy.getPdpGroup(), policy.getPdpSubgroup())))
+ .map(p -> setConfiguration(p, policy))
+ .orElse(initializeMissingFields(loop,policy)))
.collect(Collectors.toSet());
}
@@ -61,7 +63,12 @@ public class OperationalPolicyService implements PolicyService<OperationalPolicy
return operationalPolicyRepository.existsById(policyName);
}
- private OperationalPolicy setConfigurationJson(OperationalPolicy policy, OperationalPolicy newPolicy) {
+ private OperationalPolicy initializeMissingFields(Loop loop, OperationalPolicy policy) {
+ policy.setLoop(loop);
+ return policy;
+ }
+
+ private OperationalPolicy setConfiguration(OperationalPolicy policy, OperationalPolicy newPolicy) {
policy.setConfigurationsJson(newPolicy.getConfigurationsJson());
policy.setPdpGroup(newPolicy.getPdpGroup());
policy.setPdpSubgroup(newPolicy.getPdpSubgroup());
diff --git a/src/main/resources/META-INF/resources/swagger.html b/src/main/resources/META-INF/resources/swagger.html
index 69e9c7c15..29082abf1 100644
--- a/src/main/resources/META-INF/resources/swagger.html
+++ b/src/main/resources/META-INF/resources/swagger.html
@@ -692,7 +692,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
<div class="sect2">
<h3 id="_uri_scheme"><a class="anchor" href="#_uri_scheme"></a><a class="link" href="#_uri_scheme">1.2. URI scheme</a></h3>
<div class="paragraph">
-<p><em>Host</em> : localhost:39237<br>
+<p><em>Host</em> : localhost:46347<br>
<em>BasePath</em> : /restservices/clds/<br>
<em>Schemes</em> : HTTP</p>
</div>
diff --git a/src/main/resources/application-noaaf.properties b/src/main/resources/application-noaaf.properties
index 288511b3b..3ce033f64 100644
--- a/src/main/resources/application-noaaf.properties
+++ b/src/main/resources/application-noaaf.properties
@@ -176,4 +176,9 @@ clamp.config.security.permission.instance=dev
clamp.config.security.authentication.class=org.onap.aaf.cadi.principal.X509Principal
## Tosca converter
-clamp.config.tosca.converter.templates=classpath:/clds/tosca_updates/templates.json \ No newline at end of file
+clamp.config.tosca.converter.templates=classpath:/clds/tosca_updates/templates.json
+
+# Configuration settings for CDS
+clamp.config.cds.url=http4://blueprints-processor-http:8080
+clamp.config.cds.userName=ccsdkapps
+clamp.config.cds.password=ccsdkapps \ No newline at end of file
diff --git a/src/main/resources/clds/tosca_update/defaultToscaTypes.yaml b/src/main/resources/clds/tosca_update/default-tosca-types.yaml
index a11a73698..a11a73698 100644
--- a/src/main/resources/clds/tosca_update/defaultToscaTypes.yaml
+++ b/src/main/resources/clds/tosca_update/default-tosca-types.yaml
diff --git a/src/main/resources/clds/tosca_update/templates.properties b/src/main/resources/clds/tosca_update/templates.properties
deleted file mode 100644
index 5da239b1f..000000000
--- a/src/main/resources/clds/tosca_update/templates.properties
+++ /dev/null
@@ -1,15 +0,0 @@
-#Numeric types
-integer=type,description,title,deprecated,default,enum,const,multipleOf,maximum,exclusiveMaximum,minimum,exclusiveMinimum
-number=type,description,title,deprecated,default,enum,const,multipleOf,maximum,exclusiveMaximum,minimum,exclusiveMinimum
-range=type,description,title,deprecated,default,enum,const,multipleOf,maximum,exclusiveMaximum,minimum,exclusiveMinimum
-#
-boolean=type,description,title,deprecated,default,enum,const,readOnly,writeOnly
-#String types
-string=type,description,title,deprecated,default,enum,const,minLength,maxLength,pattern,format
-timestamp=type,description,title,deprecated,default,enum,const,minLength,maxLength,pattern,format
-scalar-unit.time=type,description,title,deprecated,default,enum,const,minLength,maxLength,pattern,format
-scalar-unit.frequency=type,description,title,deprecated,default,enum,const,minLength,maxLength,pattern,format
-scalar-unit.size=type,description,title,deprecated,default,enum,const,minLength,maxLength,pattern,format
-#Complex types
-array=type,description,title,deprecated,default,enum,const,minItems,maxItems,uniqueItems,minContains,maxContains
-object=type,description,title,deprecated,default,enum,const,properties,minProperties,maxProperties,required,dependentRequired,dependencies,readOnly,writeOnly
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java
index a99d4ab56..83c374e9d 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/ArrayFieldTest.java
@@ -37,12 +37,12 @@ public class ArrayFieldTest extends TestCase {
* @throws IOException in case of failure
*/
public void testDeploy() throws IOException {
- TemplateManagement templateManagement = new TemplateManagement(ResourceFileUtil.getResourceAsString(
+ ToscaConverterManager toscaConverterManager = new ToscaConverterManager(ResourceFileUtil.getResourceAsString(
"tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"),ResourceFileUtil.getResourceAsString(
- "clds/tosca_update/defaultToscaTypes.yaml"),
+ "clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor");
- Property property = component.getProperties().get("actor");
+ ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.Actor");
+ Property property = toscaElement.getProperties().get("actor");
ArrayField arrayParser = new ArrayField((ArrayList<Object>) property.getItems().get("default"));
JsonArray toTest = arrayParser.deploy();
String reference = "[1,\"String\",5.5,true]";
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java
index a4d329e29..a73fd6736 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/ConstraintTest.java
@@ -31,12 +31,12 @@ import org.onap.clamp.clds.util.ResourceFileUtil;
public class ConstraintTest extends TestCase {
- TemplateManagement templateManagement = new TemplateManagement(
+ ToscaConverterManager toscaConverterManager = new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/constraints.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Operation");
+ ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.Operation");
public ConstraintTest() throws IOException {
}
@@ -45,15 +45,15 @@ public class ConstraintTest extends TestCase {
* Test get value array.
*/
public void testGetValuesArray() {
- Property property = component.getProperties().get("timeout");
- Template template = templateManagement.getTemplates().get("integer");
+ Property property = toscaElement.getProperties().get("timeout");
+ Template template = toscaConverterManager.getTemplates().get("integer");
JsonObject resultProcess = new JsonObject();
property.addConstraintsAsJson(resultProcess, (ArrayList<Object>) property.getItems().get("constraints"),
template);
String reference = "{\"enum\":[3,4,5.5,6,10]}";
assertEquals(reference, String.valueOf(resultProcess));
- property = component.getProperties().get("success");
- template = templateManagement.getTemplates().get("string");
+ property = toscaElement.getProperties().get("success");
+ template = toscaConverterManager.getTemplates().get("string");
resultProcess = new JsonObject();
property.addConstraintsAsJson(resultProcess, (ArrayList<Object>) property.getItems().get("constraints"),
template);
@@ -66,8 +66,8 @@ public class ConstraintTest extends TestCase {
*/
public void testGetSpecificLength() {
//Test for string type, same process for array
- Property property = component.getProperties().get("id");
- Template template = templateManagement.getTemplates().get("string");
+ Property property = toscaElement.getProperties().get("id");
+ Template template = toscaConverterManager.getTemplates().get("string");
JsonObject resultProcess = new JsonObject();
property.addConstraintsAsJson(resultProcess, (ArrayList<Object>) property.getItems().get("constraints"),
template);
@@ -83,8 +83,8 @@ public class ConstraintTest extends TestCase {
*/
public void testGetLimitValue() {
//Test for array type, same process for string
- Property property = component.getProperties().get("description");
- Template template = templateManagement.getTemplates().get("array");
+ Property property = toscaElement.getProperties().get("description");
+ Template template = toscaConverterManager.getTemplates().get("array");
JsonObject resultProcess = new JsonObject();
property.addConstraintsAsJson(resultProcess, (ArrayList<Object>) property.getItems().get("constraints"),
template);
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java
index 62def32b8..bb1929f98 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/PropertyTest.java
@@ -40,12 +40,12 @@ public class PropertyTest extends TestCase {
* @throws IOException In case of failure
*/
public void testParseArray() throws IOException {
- TemplateManagement templateManagement = new TemplateManagement(
+ ToscaConverterManager toscaConverterManager = new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPoliciesEXTENTED.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor");
- Property property = component.getProperties().get("actor");
+ ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.Actor");
+ Property property = toscaElement.getProperties().get("actor");
JsonArray toTest = property.parseArray((ArrayList<Object>) property.getItems().get("default"));
assertNotNull(toTest);
}
@@ -56,13 +56,13 @@ public class PropertyTest extends TestCase {
* @throws IOException In case of failure
*/
public void testAddConstraintsAsJson() throws IOException {
- TemplateManagement templateManagement = new TemplateManagement(
+ ToscaConverterManager toscaConverterManager = new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- Component component = templateManagement.getComponents().get("onap.datatype.controlloop.operation.Failure");
- Property property = component.getProperties().get("category");
- Template template = templateManagement.getTemplates().get("string");
+ ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.operation.Failure");
+ Property property = toscaElement.getProperties().get("category");
+ Template template = toscaConverterManager.getTemplates().get("string");
JsonObject toTest = new JsonObject();
property.addConstraintsAsJson(toTest, (ArrayList<Object>) property.getItems().get("constraints"), template);
String test = "{\"enum\":[\"error\",\"timeout\",\"retries\",\"guard\",\"exception\"]}";
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java
index 4ffb4e28e..02c5747b6 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/TemplateTest.java
@@ -35,11 +35,11 @@ public class TemplateTest extends TestCase {
*/
public void testCheckFields() {
Template toTest = new Template("toTest");
- List<Field> fields = new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"),new Field(
+ List<TemplateField> templateFields = new ArrayList<>(Arrays.asList(new TemplateField("type"), new TemplateField("description"),new TemplateField(
"enum")));
- toTest.setFields(fields);
+ toTest.setTemplateFields(templateFields);
Template reference = new Template("toTest");
- reference.setFields(fields);
+ reference.setTemplateFields(templateFields);
assertTrue(toTest.checkFields(reference));
}
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ToscaConverterManagerTest.java
index aaa549386..493841215 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/update/TemplateManagementTest.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/ToscaConverterManagerTest.java
@@ -30,7 +30,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.onap.clamp.clds.util.ResourceFileUtil;
-public class TemplateManagementTest extends TestCase {
+public class ToscaConverterManagerTest extends TestCase {
/**
* Test the launch translation wit operational policies.
@@ -39,17 +39,17 @@ public class TemplateManagementTest extends TestCase {
* @throws UnknownComponentException In case of failure
*/
public void testLaunchTranslationTca() throws IOException, UnknownComponentException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
+ ".policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0&#63;"
+ "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
- "clds/tosca_update/defaultToscaTypes.yaml"),
+ "clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- assertNull(templateManagement.getParseToJson());
+ assertNull(toscaConverterManager.getParseToJson());
String componentName = "onap.policies.monitoring.cdap.tca.hi.lo.app";
- templateManagement.launchTranslation(componentName);
- assertNotNull(templateManagement.getParseToJson());
+ toscaConverterManager.startConversionToJson(componentName);
+ assertNotNull(toscaConverterManager.getParseToJson());
}
/**
@@ -59,17 +59,17 @@ public class TemplateManagementTest extends TestCase {
* @throws UnknownComponentException In case of failure
*/
public void testLaunchTranslationFrequencyLimiter() throws IOException, UnknownComponentException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
+ ".policies.controlloop.guard.common.FrequencyLimiter/versions/1.0.0&#63;"
+ "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
- "clds/tosca_update/defaultToscaTypes.yaml"),
+ "clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- assertNull(templateManagement.getParseToJson());
+ assertNull(toscaConverterManager.getParseToJson());
String componentName = "onap.policies.controlloop.guard.common.FrequencyLimiter";
- templateManagement.launchTranslation(componentName);
- assertNotNull(templateManagement.getParseToJson());
+ toscaConverterManager.startConversionToJson(componentName);
+ assertNotNull(toscaConverterManager.getParseToJson());
}
/**
@@ -79,17 +79,17 @@ public class TemplateManagementTest extends TestCase {
* @throws UnknownComponentException In case of failure
*/
public void testLaunchTranslationApex() throws IOException, UnknownComponentException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
+ ".policies.controlloop.operational.common.Apex/versions/1.0.0&#63;"
+ "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
- "clds/tosca_update/defaultToscaTypes.yaml"),
+ "clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- assertNull(templateManagement.getParseToJson());
+ assertNull(toscaConverterManager.getParseToJson());
String componentName = "onap.policies.controlloop.operational.common.Apex";
- templateManagement.launchTranslation(componentName);
- assertNotNull(templateManagement.getParseToJson());
+ toscaConverterManager.startConversionToJson(componentName);
+ assertNotNull(toscaConverterManager.getParseToJson());
}
/**
@@ -99,17 +99,17 @@ public class TemplateManagementTest extends TestCase {
* @throws UnknownComponentException In case of failure
*/
public void testLaunchTranslationDrools() throws IOException, UnknownComponentException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("http-cache/example/policy/api/v1/policytypes/onap"
+ ".policies.controlloop.operational.common.Drools/versions/1.0.0&#63;"
+ "connectionTimeToLive=5000/.file"), ResourceFileUtil.getResourceAsString(
- "clds/tosca_update/defaultToscaTypes.yaml"),
+ "clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- assertNull(templateManagement.getParseToJson());
+ assertNull(toscaConverterManager.getParseToJson());
String componentName = "onap.policies.controlloop.operational.common.Drools";
- templateManagement.launchTranslation(componentName);
- assertNotNull(templateManagement.getParseToJson());
+ toscaConverterManager.startConversionToJson(componentName);
+ assertNotNull(toscaConverterManager.getParseToJson());
}
/**
@@ -119,15 +119,15 @@ public class TemplateManagementTest extends TestCase {
* @throws UnknownComponentException In case of failure
*/
public void testLaunchTranslation() throws IOException, UnknownComponentException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- assertNull(templateManagement.getParseToJson());
+ assertNull(toscaConverterManager.getParseToJson());
String componentName = "onap.policies.controlloop.operational.common.Drools";
- templateManagement.launchTranslation(componentName);
- assertNotNull(templateManagement.getParseToJson());
+ toscaConverterManager.startConversionToJson(componentName);
+ assertNotNull(toscaConverterManager.getParseToJson());
}
/**
@@ -136,18 +136,18 @@ public class TemplateManagementTest extends TestCase {
* @throws IOException In case of failure
*/
public void testAddTemplate() throws IOException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- int count = templateManagement.getTemplates().size();
- List<Field> templateFields = new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"),
- new Field(
+ int count = toscaConverterManager.getTemplates().size();
+ List<TemplateField> templateFields = new ArrayList<>(Arrays.asList(new TemplateField("type"), new TemplateField("description"),
+ new TemplateField(
"required"),
- new Field("metadata"), new Field("constraints")));
- templateManagement.addTemplate("test", templateFields);
- assertNotSame(count, templateManagement.getTemplates().size());
+ new TemplateField("metadata"), new TemplateField("constraints")));
+ toscaConverterManager.addTemplate("test", templateFields);
+ assertNotSame(count, toscaConverterManager.getTemplates().size());
}
/**
@@ -156,14 +156,14 @@ public class TemplateManagementTest extends TestCase {
* @throws IOException In case of failure
*/
public void testRemoveTemplate() throws IOException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- int count = templateManagement.getTemplates().size();
- templateManagement.removeTemplate("string");
- assertNotSame(count, templateManagement.getTemplates().size());
+ int count = toscaConverterManager.getTemplates().size();
+ toscaConverterManager.removeTemplate("string");
+ assertNotSame(count, toscaConverterManager.getTemplates().size());
}
/**
@@ -172,14 +172,14 @@ public class TemplateManagementTest extends TestCase {
* @throws IOException In case of failure
*/
public void testUpdateTemplate() throws IOException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- int count = templateManagement.getTemplates().get("integer").getFields().size();
- templateManagement.updateTemplate("integer", new Field("type"), false);
- assertNotSame(count, templateManagement.getTemplates().get("integer").getFields().size());
+ int count = toscaConverterManager.getTemplates().get("integer").getTemplateFields().size();
+ toscaConverterManager.updateTemplate("integer", new TemplateField("type"), false);
+ assertNotSame(count, toscaConverterManager.getTemplates().get("integer").getTemplateFields().size());
}
/**
@@ -188,17 +188,17 @@ public class TemplateManagementTest extends TestCase {
* @throws IOException In case of failure
*/
public void testHasTemplate() throws IOException {
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
boolean has = true;
- List<Field> templateFieldsString =
- new ArrayList<>(Arrays.asList(new Field("type"), new Field("description"), new Field("required"),
- new Field("metadata"), new Field("constraints")));
+ List<TemplateField> templateFieldsString =
+ new ArrayList<>(Arrays.asList(new TemplateField("type"), new TemplateField("description"), new TemplateField("required"),
+ new TemplateField("metadata"), new TemplateField("constraints")));
Template templateTest = new Template("String", templateFieldsString);
- has = templateManagement.hasTemplate(templateTest);
+ has = toscaConverterManager.hasTemplate(templateTest);
assertEquals(false, has);
}
diff --git a/src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java b/src/test/java/org/onap/clamp/clds/tosca/update/ToscaElementTest.java
index 565547e4b..7ffba4e00 100644
--- a/src/test/java/org/onap/clamp/clds/tosca/update/ComponentTest.java
+++ b/src/test/java/org/onap/clamp/clds/tosca/update/ToscaElementTest.java
@@ -29,7 +29,7 @@ import java.util.Arrays;
import junit.framework.TestCase;
import org.onap.clamp.clds.util.ResourceFileUtil;
-public class ComponentTest extends TestCase {
+public class ToscaElementTest extends TestCase {
/**
* Test propertiesName.
@@ -38,13 +38,13 @@ public class ComponentTest extends TestCase {
*/
public void testPropertiesNames() throws IOException {
ArrayList<String> reference = new ArrayList<>(Arrays.asList("actor", "operation", "target", "payload"));
- TemplateManagement templateManagement =
- new TemplateManagement(
+ ToscaConverterManager toscaConverterManager =
+ new ToscaConverterManager(
ResourceFileUtil.getResourceAsString("tosca/new-converter/sampleOperationalPolicies.yaml"),
- ResourceFileUtil.getResourceAsString("clds/tosca_update/defaultToscaTypes.yaml"),
+ ResourceFileUtil.getResourceAsString("clds/tosca_update/default-tosca-types.yaml"),
ResourceFileUtil.getResourceAsString("clds/tosca_update/templates.json"));
- Component component = templateManagement.getComponents().get("onap.datatype.controlloop.Actor");
- assertEquals(reference, component.propertiesNames());
+ ToscaElement toscaElement = toscaConverterManager.getComponents().get("onap.datatype.controlloop.Actor");
+ assertEquals(reference, toscaElement.propertiesNames());
}
}
diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
index fd215dd39..a57a35ea4 100644
--- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
@@ -27,7 +27,6 @@
package org.onap.clamp.loop;
import static org.assertj.core.api.Assertions.assertThat;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -50,7 +49,7 @@ import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
-import org.onap.clamp.loop.service.ServiceRepository;
+import org.onap.clamp.loop.service.ServicesRepository;
import org.onap.clamp.loop.template.LoopTemplate;
import org.onap.clamp.loop.template.LoopTemplateLoopElementModel;
import org.onap.clamp.loop.template.LoopTemplatesRepository;
@@ -87,7 +86,7 @@ public class CsarInstallerItCase {
private LoopTemplatesRepository loopTemplatesRepo;
@Autowired
- ServiceRepository serviceRepository;
+ ServicesRepository serviceRepository;
@Autowired
PolicyModelsRepository policyModelsRepository;