1 package org.openecomp.sdc.be.components.merge.property;
3 import org.junit.Before;
5 import org.mockito.InjectMocks;
6 import org.mockito.Mock;
7 import org.mockito.Mockito;
8 import org.mockito.MockitoAnnotations;
9 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionAbstractBuilder;
10 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
11 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
12 import org.openecomp.sdc.be.model.InputDefinition;
14 import java.util.Arrays;
15 import java.util.Collections;
16 import java.util.List;
18 import static org.mockito.Mockito.verify;
20 public class DataDefinitionsValuesMergingBusinessLogicTest {
22 private static final String DEFAULT_PROP_TYPE = "string";
25 private DataDefinitionsValuesMergingBusinessLogic testInstance;
28 private PropertyDataValueMergeBusinessLogic propertyDataValueMergeBusinessLogicMock;
31 public void setUp() throws Exception {
32 MockitoAnnotations.initMocks(this);
36 public void mergePropDataDefinition_propertiesNotOfSameType_dontMerge() throws Exception {
37 PropertyDataDefinition oldProp1 = createPropertyDataDefinition("prop1", "oldVal1");
39 PropertyDataDefinition newProp1 = createPropertyDataDefinition("prop1", null);
40 newProp1.setType("int");
42 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp1), Collections.emptyList(), Collections.singletonList(newProp1), Collections.emptyList());
43 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
47 public void mergePropDataDefinition_propertiesInnerTypesNotSame_dontMerge() throws Exception {
48 PropertyDataDefinition oldProp1 = new PropertyDataDefinitionBuilder()
51 .setSchemaType("string")
52 .setValue("val1").build();
54 PropertyDataDefinition newProp1 = new PropertyDataDefinitionBuilder()
58 .setValue("val1").build();
60 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp1), Collections.emptyList(), Collections.singletonList(newProp1), Collections.emptyList());
61 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
65 public void mergePropDataDefinition_getInputsToMerge_mergeInputsThatExistInNewVersion_mergeInputsThatDeclaredByUserInPrevVersion() throws Exception {
66 PropertyDataDefinition userDeclaredGetInput = createGetInputPropertyDataDefinition("prop1", "input1");
67 PropertyDataDefinition nonUserDeclaredGetInput = createGetInputPropertyDataDefinition("prop2", "input2", "input3");
69 PropertyDataDefinition newProp1 = createPropertyDataDefinition("prop1", "");
70 PropertyDataDefinition newProp2 = createPropertyDataDefinition("prop2", null);
72 InputDefinition oldDeclaredByUserInput1 = new InputDefinition();
73 oldDeclaredByUserInput1.setName("input1");
74 oldDeclaredByUserInput1.setInstanceUniqueId("instanceId");
76 InputDefinition oldNotDeclaredByUserInput2 = new InputDefinition();
77 oldNotDeclaredByUserInput2.setName("input2");
79 InputDefinition oldNotDeclaredByUserInput3 = new InputDefinition();
80 oldNotDeclaredByUserInput3.setName("input3");
82 InputDefinition newInput3 = new InputDefinition();
83 newInput3.setName("input3");
85 List<PropertyDataDefinition> oldProps = Arrays.asList(userDeclaredGetInput, nonUserDeclaredGetInput);
86 List<PropertyDataDefinition> newProps = Arrays.asList(newProp1, newProp2);
88 List<InputDefinition> oldInputs = Arrays.asList(oldDeclaredByUserInput1, oldNotDeclaredByUserInput2, oldNotDeclaredByUserInput3);
89 List<InputDefinition> newInputs = Collections.singletonList(newInput3);
91 testInstance.mergeInstanceDataDefinitions(oldProps, oldInputs, newProps, newInputs);
92 //get input prop was declared by user - ok to merge it although its input not exist (it will be added later)
93 verify(propertyDataValueMergeBusinessLogicMock).mergePropertyValue(userDeclaredGetInput, newProp1, Collections.singletonList("input1"));
94 //input 2 not exist in new version - dont merge it, input 3 exist in new version - ok to merge it
95 verify(propertyDataValueMergeBusinessLogicMock).mergePropertyValue(nonUserDeclaredGetInput, newProp2, Collections.singletonList("input3"));
99 public void mergePropDataDefinition_dontMergeOldPropsIfNotExistInNewVersion() throws Exception {
100 PropertyDataDefinition oldProp = createPropertyDataDefinition("prop1", "oldVal1");
101 PropertyDataDefinition newProp = createPropertyDataDefinition("prop2", null);
102 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp), Collections.emptyList(), Collections.singletonList(newProp), Collections.emptyList());
103 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
106 private PropertyDataDefinition createPropertyDataDefinition(String name, String value) {
107 return new PropertyDataDefinitionBuilder()
109 .setType(DEFAULT_PROP_TYPE)
110 .setValue(value).build();
113 private PropertyDataDefinition createGetInputPropertyDataDefinition(String name, String ... inputsNames) {
114 PropertyDataDefinitionAbstractBuilder propertyBuilder = new PropertyDataDefinitionBuilder()
116 .setType(DEFAULT_PROP_TYPE);
118 for (String inputName : inputsNames) {
119 propertyBuilder.addGetInputValue(inputName);
121 return propertyBuilder.build();