aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-10-25 10:13:48 +0000
committerGerrit Code Review <gerrit@onap.org>2017-10-25 10:13:48 +0000
commitd2469cabc662eef291f55f791700bd8c7c6ded10 (patch)
tree2788cbbcfa61c86f46ed3fdf5f2e2897aba82675 /catalog-be
parentfa9d07d3ed584cadbb44de89c886d92591eae23f (diff)
parent3a7c314a597a7ceda028696b9542be15e747b2af (diff)
Merge "align MME" into release-1.1.0
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java20
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/tosca/PropertyConvertorTest.java131
2 files changed, 94 insertions, 57 deletions
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 646a7ecc8b..68adbd5ae3 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
@@ -74,7 +74,9 @@ public class PropertyConvertor {
props.stream().filter(p -> p.getOwnerId() == null || p.getOwnerId().equals(component.getUniqueId())).forEach(property -> {
ToscaProperty prop = convertProperty(dataTypes, property, false);
- properties.put(property.getName(), prop);
+ if (prop != null) {
+ properties.put(property.getName(), prop);
+ }
});
if (!properties.isEmpty()) {
toscaNodeType.setProperties(properties);
@@ -98,13 +100,17 @@ public class PropertyConvertor {
}
log.trace("try to convert property {} from type {} with default value [{}]", property.getName(), property.getType(), property.getDefaultValue());
prop.setDefaultp(convertToToscaObject(property.getType(), property.getDefaultValue(), innerType, dataTypes));
+
+ if (prop.getDefaultp() == null) {
+ return null;
+ }
prop.setType(property.getType());
- prop.setDescription(property.getDescription());
- if (isCapabiltyProperty) {
- prop.setStatus(property.getStatus());
- prop.setRequired(property.isRequired());
- }
- return prop;
+ prop.setDescription(property.getDescription());
+ if (isCapabiltyProperty) {
+ prop.setStatus(property.getStatus());
+ prop.setRequired(property.isRequired());
+ }
+ return prop;
}
public Object convertToToscaObject(String propertyType, String value, String innerType, Map<String, DataTypeDefinition> dataTypes) {
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 e6f1ac82fb..a987e0243b 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
@@ -1,71 +1,102 @@
package org.openecomp.sdc.be.tosca;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-import javax.annotation.Generated;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Before;
import org.junit.Test;
-import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import fj.data.Either;
public class PropertyConvertorTest {
+ private PropertyDefinition property;
+ Map<String, DataTypeDefinition> dataTypes;
- private PropertyConvertor createTestSubject() {
- return new PropertyConvertor();
- }
-
-
- @Test
- public void testGetInstance() throws Exception {
- PropertyConvertor result;
-
- // default test
- result = PropertyConvertor.getInstance();
- }
+ @Before
+ public void setUp(){
+ property = new PropertyDefinition();
+ property.setName("myProperty");
+ property.setType(ToscaPropertyType.INTEGER.getType());
+ dataTypes = new HashMap<String, DataTypeDefinition>();
+ dataTypes.put(property.getName(), new DataTypeDefinition());
+ }
-
- @Test
- public void testConvertProperties() throws Exception {
- PropertyConvertor testSubject;
- Component component = null;
- ToscaNodeType toscaNodeType = null;
- Map<String, DataTypeDefinition> dataTypes = null;
- Either<ToscaNodeType, ToscaError> result;
- // default test
- testSubject = createTestSubject();
- result = testSubject.convertProperties(component, toscaNodeType, dataTypes);
- }
+ @Test
+ public void convertPropertyWhenValueAndDefaultNull() {
+ assertNull(PropertyConvertor.getInstance().convertProperty(dataTypes, property, false));
+ }
-
- @Test
- public void testConvertProperty() throws Exception {
- PropertyConvertor testSubject;
- Map<String, DataTypeDefinition> dataTypes = null;
- PropertyDefinition property = null;
- boolean isCapabiltyProperty = false;
- ToscaProperty result;
+ @Test
+ public void convertPropertyWhenValueNullAndDefaultNotEmpty() {
+ final String def = "1";
+ property.setDefaultValue(def);
+ ToscaProperty result = PropertyConvertor.getInstance().convertProperty(dataTypes, property, false);
+ assertNotNull(result);
+ assertEquals(Integer.valueOf(def).intValue(), result.getDefaultp());
+ }
- // default test
- testSubject = createTestSubject();
- }
+ @Test
+ public void convertPropertiesWhenValueAndDefaultNullInOne() {
+ PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("otherProperty");
+ property1.setType(ToscaPropertyType.INTEGER.getType());
+ property1.setDefaultValue("2");
+ dataTypes.put(property1.getName(), new DataTypeDefinition());
+ Resource resource = new Resource();
+ List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
+ properties.add(property);
+ properties.add(property1);
+ resource.setProperties(properties);
+ Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
+ assertTrue(result.isLeft());
+ assertEquals(1, result.left().value().getProperties().size());
+ }
-
- @Test
- public void testConvertToToscaObject() throws Exception {
- PropertyConvertor testSubject;
- String propertyType = "";
- String value = "";
- String innerType = "";
- Map<String, DataTypeDefinition> dataTypes = null;
- Object result;
+ @Test
+ public void convertPropertiesWhenValueAndDefaultExist() {
+ PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("otherProperty");
+ property1.setType(ToscaPropertyType.INTEGER.getType());
+ property1.setDefaultValue("2");
+ property.setDefaultValue("1");
+ dataTypes.put(property1.getName(), new DataTypeDefinition());
+ Resource resource = new Resource();
+ List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
+ properties.add(property);
+ properties.add(property1);
+ resource.setProperties(properties);
+ Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
+ assertTrue(result.isLeft());
+ assertEquals(2, result.left().value().getProperties().size());
+ }
- // default test
- testSubject = createTestSubject();
- }
+ @Test
+ public void convertPropertiesWhenValueAndDefaultNullInAll() {
+ PropertyDefinition property1 = new PropertyDefinition();
+ property1.setName("otherProperty");
+ property1.setType(ToscaPropertyType.INTEGER.getType());
+ dataTypes.put(property1.getName(), new DataTypeDefinition());
+ Resource resource = new Resource();
+ List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
+ properties.add(property);
+ properties.add(property1);
+ resource.setProperties(properties);
+ Either<ToscaNodeType, ToscaError> result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes);
+ assertTrue(result.isLeft());
+ assertNull(result.left().value().getProperties());
+ }
} \ No newline at end of file