1 package org.openecomp.sdc.be.components.merge.property;
3 import static org.mockito.Mockito.verify;
5 import java.util.Arrays;
6 import java.util.Collections;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.mockito.InjectMocks;
12 import org.mockito.Mock;
13 import org.mockito.Mockito;
14 import org.mockito.MockitoAnnotations;
15 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
16 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
17 import org.openecomp.sdc.be.model.InputDefinition;
19 public class DataDefinitionsValuesMergingBusinessLogicTest {
21 private static final String DEFAULT_PROP_TYPE = "string";
24 private DataDefinitionsValuesMergingBusinessLogic testInstance;
27 private PropertyDataValueMergeBusinessLogic propertyDataValueMergeBusinessLogicMock;
30 public void setUp() throws Exception {
31 MockitoAnnotations.initMocks(this);
35 public void mergePropDataDefinition_propertiesNotOfSameType_dontMerge() throws Exception {
36 PropertyDataDefinition oldProp1 = createPropertyDataDefinition("prop1", "oldVal1");
38 PropertyDataDefinition newProp1 = createPropertyDataDefinition("prop1", null);
39 newProp1.setType("int");
41 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp1), Collections.emptyList(), Collections.singletonList(newProp1), Collections.emptyList());
42 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
46 public void mergePropDataDefinition_propertiesInnerTypesNotSame_dontMerge() throws Exception {
47 PropertyDataDefinition oldProp1 = new PropertyDataDefinitionBuilder()
50 .setSchemaType("string")
51 .setValue("val1").build();
53 PropertyDataDefinition newProp1 = new PropertyDataDefinitionBuilder()
57 .setValue("val1").build();
59 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp1), Collections.emptyList(), Collections.singletonList(newProp1), Collections.emptyList());
60 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
64 public void mergePropDataDefinition_getInputsToMerge_mergeInputsThatExistInNewVersion_mergeInputsThatDeclaredByUserInPrevVersion() throws Exception {
65 PropertyDataDefinition userDeclaredGetInput = createGetInputPropertyDataDefinition("prop1", "input1");
66 PropertyDataDefinition nonUserDeclaredGetInput = createGetInputPropertyDataDefinition("prop2", "input2", "input3");
68 PropertyDataDefinition newProp1 = createPropertyDataDefinition("prop1", "");
69 PropertyDataDefinition newProp2 = createPropertyDataDefinition("prop2", null);
71 InputDefinition oldDeclaredByUserInput1 = new InputDefinition();
72 oldDeclaredByUserInput1.setName("input1");
73 oldDeclaredByUserInput1.setInstanceUniqueId("instanceId");
75 InputDefinition oldNotDeclaredByUserInput2 = new InputDefinition();
76 oldNotDeclaredByUserInput2.setName("input2");
78 InputDefinition oldNotDeclaredByUserInput3 = new InputDefinition();
79 oldNotDeclaredByUserInput3.setName("input3");
81 InputDefinition newInput3 = new InputDefinition();
82 newInput3.setName("input3");
84 List<PropertyDataDefinition> oldProps = Arrays.asList(userDeclaredGetInput, nonUserDeclaredGetInput);
85 List<PropertyDataDefinition> newProps = Arrays.asList(newProp1, newProp2);
87 List<InputDefinition> oldInputs = Arrays.asList(oldDeclaredByUserInput1, oldNotDeclaredByUserInput2, oldNotDeclaredByUserInput3);
88 List<InputDefinition> newInputs = Collections.singletonList(newInput3);
90 testInstance.mergeInstanceDataDefinitions(oldProps, oldInputs, newProps, newInputs);
91 //get input prop was declared by user - ok to merge it although its input not exist (it will be added later)
92 verify(propertyDataValueMergeBusinessLogicMock).mergePropertyValue(userDeclaredGetInput, newProp1, Collections.singletonList("input1"));
93 //input 2 not exist in new version - dont merge it, input 3 exist in new version - ok to merge it
94 verify(propertyDataValueMergeBusinessLogicMock).mergePropertyValue(nonUserDeclaredGetInput, newProp2, Collections.singletonList("input3"));
98 public void mergePropDataDefinition_dontMergeOldPropsIfNotExistInNewVersion() throws Exception {
99 PropertyDataDefinition oldProp = createPropertyDataDefinition("prop1", "oldVal1");
100 PropertyDataDefinition newProp = createPropertyDataDefinition("prop2", null);
101 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp), Collections.emptyList(), Collections.singletonList(newProp), Collections.emptyList());
102 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
105 private PropertyDataDefinition createPropertyDataDefinition(String name, String value) {
106 return new PropertyDataDefinitionBuilder()
108 .setType(DEFAULT_PROP_TYPE)
109 .setValue(value).build();
112 private PropertyDataDefinition createGetInputPropertyDataDefinition(String name, String ... inputsNames) {
113 PropertyDataDefinitionBuilder propertyBuilder = new PropertyDataDefinitionBuilder()
115 .setType(DEFAULT_PROP_TYPE);
116 for (String inputName : inputsNames) {
117 propertyBuilder.addGetInputValue(inputName);
119 return propertyBuilder.build();