package org.openecomp.sdc.be.datatypes.elements;
-import java.util.List;
-
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+
+import java.util.List;
+
+import static org.junit.Assert.*;
public class PropertyDataDefinitionTest {
+ private PropertyDataDefinition propDef;
+
+ @Before
+ public void setUp() {
+ propDef = new PropertyDataDefinition();
+ }
+
+ @Test
+ public void setStringField() {
+ final String name = "name";
+ assertNull(propDef.getName());
+ assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.NAME));
+ propDef.setToscaPresentationValue(JsonPresentationFields.NAME, name);
+ assertEquals(name, propDef.getName());
+ assertEquals(name, propDef.getToscaPresentationValue(JsonPresentationFields.NAME));
+ }
+
+ @Test
+ public void setDefaultValue() {
+ final String defaultValue = "text";
+ assertNull(propDef.getDefaultValue());
+ assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
+ propDef.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, defaultValue);
+ assertEquals(defaultValue, propDef.getDefaultValue());
+ assertEquals(defaultValue, propDef.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
+ }
+
+ @Test
+ public void setValueNotDefinedInPropDataDefinition() {
+ final String defaultValue = "VF";
+ assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.COMPONENT_TYPE));
+ propDef.setToscaPresentationValue(JsonPresentationFields.COMPONENT_TYPE, defaultValue);
+ assertEquals(defaultValue, propDef.getToscaPresentationValue(JsonPresentationFields.COMPONENT_TYPE));
+ }
+
+ @Test
+ public void setBooleanField() {
+ assertFalse((Boolean) propDef.getToscaPresentationValue(JsonPresentationFields.PASSWORD));
+ assertFalse(propDef.isPassword());
+ propDef.setToscaPresentationValue(JsonPresentationFields.PASSWORD, Boolean.TRUE);
+ assertTrue(propDef.isPassword());
+ assertTrue((Boolean) propDef.getToscaPresentationValue(JsonPresentationFields.PASSWORD));
+ }
+
+ @Test
+ public void mergeDefaultValueWhenItWasNullBeforeMerge() {
+ final String defaultValue = "12345";
+ final String type = "1";
+ PropertyDataDefinition propForMerge = new PropertyDataDefinition();
+ propForMerge.setType(type);
+
+ propDef.setType(type);
+ propDef.setDefaultValue(defaultValue);
+ assertNull(propForMerge.getDefaultValue());
+ assertNull(propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
+ propDef.mergeFunction(propForMerge, true);
+ assertEquals(defaultValue, propForMerge.getDefaultValue());
+ assertEquals(defaultValue, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
+ }
+
+ @Test
+ public void mergeDefaultValueAndOverrideIt() {
+ final String defaultValue = "12345";
+ final String defaultValueForOther = "7890";
+ final String type = "1";
+ PropertyDataDefinition propForMerge = new PropertyDataDefinition();
+ propForMerge.setType(type);
+ propForMerge.setDefaultValue(defaultValueForOther);
+
+ propDef.setType(type);
+ propDef.setDefaultValue(defaultValue);
+ assertEquals(defaultValueForOther, propForMerge.getDefaultValue());
+ assertEquals(defaultValueForOther, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
+ propDef.mergeFunction(propForMerge, true);
+ assertEquals(defaultValue, propForMerge.getDefaultValue());
+ assertEquals(defaultValue, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
+ }
+
+ @Test
+ public void mergeDefaultValueWhenOverridingIsNotAllowed() {
+ final String defaultValue = "12345";
+ final String defaultValueForOther = "7890";
+ final String type = "1";
+ PropertyDataDefinition propForMerge = new PropertyDataDefinition();
+ propForMerge.setType(type);
+ propForMerge.setDefaultValue(defaultValueForOther);
+
+ propDef.setType(type);
+ propDef.setDefaultValue(defaultValue);
+ assertEquals(defaultValueForOther, propForMerge.getDefaultValue());
+ assertEquals(defaultValueForOther, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
+ propDef.mergeFunction(propForMerge, false);
+ assertEquals(defaultValueForOther, propForMerge.getDefaultValue());
+ assertEquals(defaultValueForOther, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
+ }
+
private PropertyDataDefinition createTestSubject() {
return new PropertyDataDefinition();
}
testSubject = createTestSubject();
new PropertyDataDefinition(testSubject);
}
-
+
@Test
public void testGetInputPath() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getInputPath();
}
-
+
@Test
public void testSetInputPath() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setInputPath(inputPath);
}
-
+
@Test
public void testGetName() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getName();
}
-
+
@Test
public void testSetName() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setName(name);
}
-
+
@Test
public void testGetValue() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getValue();
}
-
+
@Test
public void testSetValue() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setValue(value);
}
-
+
@Test
public void testIsDefinition() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.isDefinition();
}
-
+
@Test
public void testSetDefinition() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setDefinition(definition);
}
-
+
@Test
public void testGetType() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getType();
}
-
+
@Test
public void testGetDefaultValue() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getDefaultValue();
}
-
+
@Test
public void testSetDefaultValue() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setDefaultValue(defaultValue);
}
-
+
@Test
public void testSetType() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setType(type);
}
-
+
@Test
public void testIsRequired() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.isRequired();
}
-
+
@Test
public void testSetRequired() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setRequired(required);
}
-
+
@Test
public void testGetDescription() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getDescription();
}
-
+
@Test
public void testSetDescription() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setDescription(description);
}
-
+
@Test
public void testIsPassword() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.isPassword();
}
-
+
@Test
public void testSetPassword() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setPassword(password);
}
-
+
@Test
public void testGetUniqueId() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getUniqueId();
}
-
+
@Test
public void testSetUniqueId() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setUniqueId(uniqueId);
}
-
+
@Test
public void testGetSchema() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getSchema();
}
-
+
@Test
public void testSetSchema() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setSchema(entrySchema);
}
-
+
@Test
public void testGetLabel() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getLabel();
}
-
+
@Test
public void testSetLabel() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setLabel(label);
}
-
+
@Test
public void testIsHidden() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.isHidden();
}
-
+
@Test
public void testSetHidden() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setHidden(hidden);
}
-
+
@Test
public void testIsImmutable() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.isImmutable();
}
-
+
@Test
public void testSetImmutable() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setImmutable(immutable);
}
-
+
@Test
public void testGetParentUniqueId() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getParentUniqueId();
}
-
+
@Test
public void testSetParentUniqueId() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setParentUniqueId(parentUniqueId);
}
-
+
@Test
public void testGetGetInputValues() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getGetInputValues();
}
-
+
@Test
public void testSetGetInputValues() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setGetInputValues(getInputValues);
}
-
+
@Test
public void testGetStatus() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getStatus();
}
-
+
@Test
public void testSetStatus() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setStatus(status);
}
-
+
@Test
public void testGetInputId() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getInputId();
}
-
+
@Test
public void testSetInputId() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setInputId(inputId);
}
-
+
@Test
public void testGetInstanceUniqueId() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getInstanceUniqueId();
}
-
+
@Test
public void testSetInstanceUniqueId() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setInstanceUniqueId(instanceUniqueId);
}
-
+
@Test
public void testGetPropertyId() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.getPropertyId();
}
-
+
@Test
public void testSetPropertyId() throws Exception {
PropertyDataDefinition testSubject;
testSubject.setPropertyId(propertyId);
}
-
+
@Test
public void testToString() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.toString();
}
-
+
@Test
public void testHashCode() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.hashCode();
}
-
+
@Test
public void testEquals() throws Exception {
PropertyDataDefinition testSubject;
result = testSubject.equals(createTestSubject());
Assert.assertEquals(true, result);
}
-
+
@Test
public void testConvertPropertyDataToInstancePropertyData() throws Exception {
PropertyDataDefinition testSubject;
testSubject = createTestSubject();
testSubject.convertPropertyDataToInstancePropertyData();
}
-
+
@Test
public void testTypeEquals() throws Exception {
PropertyDataDefinition testSubject;
testSubject.typeEquals(null);
testSubject.typeEquals(createTestSubject());
}
-
+
@Test
public void testMergeFunction() throws Exception {
PropertyDataDefinition testSubject;
// default test
testSubject = createTestSubject();
testSubject.mergeFunction(createTestSubject(), false);
+
}
-}
\ No newline at end of file
+}