Improve test coverage
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / tosca / AttributeConverter.java
index 561480d..847947b 100644 (file)
@@ -16,6 +16,7 @@
  *  SPDX-License-Identifier: Apache-2.0
  *  ============LICENSE_END=========================================================
  */
+
 package org.openecomp.sdc.be.tosca;
 
 import com.google.gson.JsonElement;
@@ -27,6 +28,7 @@ import java.io.StringReader;
 import java.util.Map;
 import org.apache.commons.lang3.StringUtils;
 import org.onap.sdc.tosca.datatypes.model.EntrySchema;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
 import org.openecomp.sdc.be.model.AttributeDefinition;
 import org.openecomp.sdc.be.model.DataTypeDefinition;
 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
@@ -73,7 +75,14 @@ public class AttributeConverter {
         final ToscaAttribute toscaAttribute = new ToscaAttribute();
         LOGGER.trace("Converting attribute '{}' from type '{}' with default value '{}'", attributeDefinition.getName(), attributeDefinition.getType(),
             attributeDefinition.getDefaultValue());
-        toscaAttribute.setEntrySchema(convert(attributeDefinition.getEntry_schema()));
+        SchemaDefinition schema = attributeDefinition.getSchema();
+        if (schema != null && schema.getProperty() != null && schema.getProperty().getType() != null
+            && StringUtils.isNotEmpty(schema.getProperty().getType())) {
+            final ToscaSchemaDefinition toscaSchemaDefinition = new ToscaSchemaDefinition();
+            toscaSchemaDefinition.setType(schema.getProperty().getType());
+            toscaSchemaDefinition.setDescription(schema.getProperty().getDescription());
+            toscaAttribute.setEntrySchema(toscaSchemaDefinition);
+        }
         toscaAttribute.setType(attributeDefinition.getType());
         toscaAttribute.setDescription(attributeDefinition.getDescription());
         toscaAttribute.setStatus(attributeDefinition.getStatus());
@@ -88,16 +97,6 @@ public class AttributeConverter {
         return toscaAttribute;
     }
 
-    private ToscaSchemaDefinition convert(final EntrySchema entrySchema) {
-        if (entrySchema == null) {
-            return null;
-        }
-        final ToscaSchemaDefinition toscaSchemaDefinition = new ToscaSchemaDefinition();
-        toscaSchemaDefinition.setType(entrySchema.getType());
-        toscaSchemaDefinition.setDescription(entrySchema.getDescription());
-        return toscaSchemaDefinition;
-    }
-
     private Object convertToToscaObject(final AttributeDefinition attributeDefinition,
                                         String value,
                                         final boolean preserveEmptyValue) {
@@ -140,7 +139,8 @@ public class AttributeConverter {
                 return toscaMapValueConverter.handleComplexJsonValue(valueAsJson);
             }
             //if it is a data type
-            return toscaMapValueConverter.convertDataTypeToToscaObject(innerType, dataTypes, null, false, valueAsJson, preserveEmptyValue);
+            return toscaMapValueConverter.convertDataTypeToToscaObject(innerType, dataTypes, null, false, valueAsJson,
+                preserveEmptyValue, false);
         } catch (final JsonParseException e) {
             final String errorMsg = "Failed to parse json value";
             LOGGER.error(EcompLoggerErrorCode.SCHEMA_ERROR, "Attribute Converter", errorMsg, e);
@@ -173,8 +173,8 @@ public class AttributeConverter {
 
     public void convertAndAddValue(final Map<String, Object> attribs,
                                    final AttributeDefinition attribute) {
-        final Object convertedValue = convertToToscaObject(attribute, attribute.getDefaultValue(), false);
-        if (!ToscaValueBaseConverter.isEmptyObjectValue(convertedValue)) {
+        final Object convertedValue = convertToToscaObject(attribute, attribute.getValue(), false);
+        if (!ToscaValueBaseConverter.isEmptyObjectValue(convertedValue) && !attribute.isGetOutputAttribute()) {
             attribs.put(attribute.getName(), convertedValue);
         }
     }