From 08fee6aa89ec2a0fd021c969af78ba422f86949f Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 27 Nov 2020 17:26:46 +0000 Subject: Add metadata to topology inputs Change-Id: If57e16003532d59552fa0b5cacc69a792e5b877a Issue-ID: SDC-3399 Signed-off-by: MichaelMorris --- .../sdc/be/components/impl/InputsBusinessLogic.java | 1 + .../java/org/openecomp/sdc/be/tosca/PropertyConvertor.java | 1 + .../org/openecomp/sdc/be/tosca/model/ToscaProperty.java | 5 +++++ .../sdc/be/components/impl/InputsBusinessLogicTest.java | 14 ++++++++++++-- .../org/openecomp/sdc/be/tosca/PropertyConvertorTest.java | 10 ++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) (limited to 'catalog-be') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java index d6459f4ad9..c99b13a118 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java @@ -340,6 +340,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { String updateInputObjectValue = updateInputObjectValue(currInput, newInput, dataTypes); currInput.setDefaultValue(updateInputObjectValue); currInput.setOwnerId(userId); + currInput.setMetadata(newInput.getMetadata()); if (newInput.isRequired() != null) { currInput.setRequired(newInput.isRequired()); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java index 4ccf7b1499..4c4f19bb87 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java @@ -105,6 +105,7 @@ public class PropertyConvertor { if(propertyType.equals(PropertyType.CAPABILITY)) { prop.setStatus(property.getStatus()); } + prop.setMetadata(property.getMetadata()); return prop; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java index fd3696eb2a..952423e039 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaProperty.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.tosca.model; import java.util.List; +import java.util.Map; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -47,6 +48,9 @@ public class ToscaProperty { @Getter @Setter private String status; + @Getter + @Setter + private Map metadata; public ToscaProperty(final ToscaProperty toscaProperty) { this.type = toscaProperty.type; @@ -56,6 +60,7 @@ public class ToscaProperty { this.entry_schema = toscaProperty.entry_schema; this.status = toscaProperty.status; this.constraints = toscaProperty.constraints; + this.metadata = toscaProperty.metadata; } public Object getDefaultp() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java index 4b021c357c..c83f73b269 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java @@ -764,6 +764,9 @@ public class InputsBusinessLogicTest { oldInputDef.setType(INPUT_TYPE); oldInputDef.setDefaultValue(OLD_VALUE); oldInputDef.setRequired(Boolean.FALSE); + Map oldMetadata = new HashMap<>(); + oldMetadata.put("key1", "value1"); + oldInputDef.setMetadata(oldMetadata); oldInputDefs.add(oldInputDef); service.setInputs(oldInputDefs); @@ -773,6 +776,10 @@ public class InputsBusinessLogicTest { inputDef.setType(INPUT_TYPE); inputDef.setDefaultValue(NEW_VALUE); // update value inputDef.setRequired(Boolean.TRUE); // update value + Map newMetadata = new HashMap<>(); + newMetadata.put("key1", "value2"); + newMetadata.put("key2", "value3"); + inputDef.setMetadata(newMetadata); newInputDefs.add(inputDef); // used in validateComponentExists @@ -792,8 +799,11 @@ public class InputsBusinessLogicTest { testInstance.updateInputsValue(service.getComponentType(), COMPONENT_ID, newInputDefs, USER_ID, true, false); assertThat(result.isLeft()).isTrue(); // check if values are updated - assertEquals(service.getInputs().get(0).getDefaultValue(), NEW_VALUE); - assertEquals(service.getInputs().get(0).isRequired(), Boolean.TRUE); + assertEquals(NEW_VALUE, service.getInputs().get(0).getDefaultValue()); + assertEquals(Boolean.TRUE, service.getInputs().get(0).isRequired()); + assertEquals(2, service.getInputs().get(0).getMetadata().size()); + assertEquals("value2", service.getInputs().get(0).getMetadata().get("key1")); + assertEquals("value3", service.getInputs().get(0).getMetadata().get("key2")); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java index d7c53d5bec..05ff278fc0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java @@ -90,6 +90,16 @@ public class PropertyConvertorTest { assertNotNull(result); assertEquals(Integer.valueOf(def), result.getDefaultp()); } + + @Test + public void convertPropertyWithMetadata() { + Map metadata = new HashMap<>(); + metadata.put("key1", "value"); + property.setMetadata(metadata); + ToscaProperty result = propertyConvertor.convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY); + assertNotNull(result); + assertEquals(metadata, result.getMetadata()); + } @Test public void convertPropertiesWhenValueAndDefaultNullInOne() { -- cgit 1.2.3-korg