From 729eb6708fd48294c32da856c46515ff14a831d0 Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Tue, 24 Oct 2017 18:45:00 +0300 Subject: align MME - [BUG323816] Don't add a property to a newly generated csar if the value is not set and the default value is not provided Change-Id: I76b312ef8140ca6207aa7604026c1b0a89bfbe02 Issue-ID:SDC-500 Signed-off-by: Tal Gitelman --- .../sdc/be/tosca/PropertyConvertorTest.java | 131 +++++++++++++-------- 1 file changed, 81 insertions(+), 50 deletions(-) (limited to 'catalog-be/src/test/java') 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 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(); + dataTypes.put(property.getName(), new DataTypeDefinition()); + } - - @Test - public void testConvertProperties() throws Exception { - PropertyConvertor testSubject; - Component component = null; - ToscaNodeType toscaNodeType = null; - Map dataTypes = null; - Either 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 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 properties = new ArrayList(); + properties.add(property); + properties.add(property1); + resource.setProperties(properties); + Either 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 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 properties = new ArrayList(); + properties.add(property); + properties.add(property1); + resource.setProperties(properties); + Either 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 properties = new ArrayList(); + properties.add(property); + properties.add(property1); + resource.setProperties(properties); + Either result = PropertyConvertor.getInstance().convertProperties(resource, new ToscaNodeType(), dataTypes); + assertTrue(result.isLeft()); + assertNull(result.left().value().getProperties()); + } } \ No newline at end of file -- cgit 1.2.3-korg