2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.merge.property;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.mockito.Mockito;
28 import org.mockito.MockitoAnnotations;
29 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionAbstractBuilder;
30 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
31 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
32 import org.openecomp.sdc.be.model.InputDefinition;
34 import java.util.Arrays;
35 import java.util.Collections;
36 import java.util.List;
38 import static org.mockito.Mockito.verify;
40 public class DataDefinitionsValuesMergingBusinessLogicTest {
42 private static final String DEFAULT_PROP_TYPE = "string";
45 private DataDefinitionsValuesMergingBusinessLogic testInstance;
48 private PropertyDataValueMergeBusinessLogic propertyDataValueMergeBusinessLogicMock;
51 public void setUp() throws Exception {
52 MockitoAnnotations.openMocks(this);
56 public void mergePropDataDefinition_propertiesNotOfSameType_dontMerge() throws Exception {
57 PropertyDataDefinition oldProp1 = createPropertyDataDefinition("prop1", "oldVal1");
59 PropertyDataDefinition newProp1 = createPropertyDataDefinition("prop1", null);
60 newProp1.setType("int");
62 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp1), Collections.emptyList(), Collections.singletonList(newProp1), Collections.emptyList());
63 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
67 public void mergePropDataDefinition_propertiesInnerTypesNotSame_dontMerge() throws Exception {
68 PropertyDataDefinition oldProp1 = new PropertyDataDefinitionBuilder()
71 .setSchemaType("string")
72 .setValue("val1").build();
74 PropertyDataDefinition newProp1 = new PropertyDataDefinitionBuilder()
78 .setValue("val1").build();
80 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp1), Collections.emptyList(), Collections.singletonList(newProp1), Collections.emptyList());
81 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
85 public void mergePropDataDefinition_getInputsToMerge_mergeInputsThatExistInNewVersion_mergeInputsThatDeclaredByUserInPrevVersion() throws Exception {
86 PropertyDataDefinition userDeclaredGetInput = createGetInputPropertyDataDefinition("prop1", "input1");
87 PropertyDataDefinition nonUserDeclaredGetInput = createGetInputPropertyDataDefinition("prop2", "input2", "input3");
89 PropertyDataDefinition newProp1 = createPropertyDataDefinition("prop1", "");
90 PropertyDataDefinition newProp2 = createPropertyDataDefinition("prop2", null);
92 InputDefinition oldDeclaredByUserInput1 = new InputDefinition();
93 oldDeclaredByUserInput1.setName("input1");
94 oldDeclaredByUserInput1.setInstanceUniqueId("instanceId");
96 InputDefinition oldNotDeclaredByUserInput2 = new InputDefinition();
97 oldNotDeclaredByUserInput2.setName("input2");
99 InputDefinition oldNotDeclaredByUserInput3 = new InputDefinition();
100 oldNotDeclaredByUserInput3.setName("input3");
102 InputDefinition newInput3 = new InputDefinition();
103 newInput3.setName("input3");
105 List<PropertyDataDefinition> oldProps = Arrays.asList(userDeclaredGetInput, nonUserDeclaredGetInput);
106 List<PropertyDataDefinition> newProps = Arrays.asList(newProp1, newProp2);
108 List<InputDefinition> oldInputs = Arrays.asList(oldDeclaredByUserInput1, oldNotDeclaredByUserInput2, oldNotDeclaredByUserInput3);
109 List<InputDefinition> newInputs = Collections.singletonList(newInput3);
111 testInstance.mergeInstanceDataDefinitions(oldProps, oldInputs, newProps, newInputs);
112 //get input prop was declared by user - ok to merge it although its input not exist (it will be added later)
113 verify(propertyDataValueMergeBusinessLogicMock).mergePropertyValue(userDeclaredGetInput, newProp1, Collections.singletonList("input1"));
114 //input 2 not exist in new version - dont merge it, input 3 exist in new version - ok to merge it
115 verify(propertyDataValueMergeBusinessLogicMock).mergePropertyValue(nonUserDeclaredGetInput, newProp2, Collections.singletonList("input3"));
119 public void mergePropDataDefinition_dontMergeOldPropsIfNotExistInNewVersion() throws Exception {
120 PropertyDataDefinition oldProp = createPropertyDataDefinition("prop1", "oldVal1");
121 PropertyDataDefinition newProp = createPropertyDataDefinition("prop2", null);
122 testInstance.mergeInstanceDataDefinitions(Collections.singletonList(oldProp), Collections.emptyList(), Collections.singletonList(newProp), Collections.emptyList());
123 Mockito.verifyZeroInteractions(propertyDataValueMergeBusinessLogicMock);
126 private PropertyDataDefinition createPropertyDataDefinition(String name, String value) {
127 return new PropertyDataDefinitionBuilder()
129 .setType(DEFAULT_PROP_TYPE)
130 .setValue(value).build();
133 private PropertyDataDefinition createGetInputPropertyDataDefinition(String name, String ... inputsNames) {
134 PropertyDataDefinitionAbstractBuilder propertyBuilder = new PropertyDataDefinitionBuilder()
136 .setType(DEFAULT_PROP_TYPE);
138 for (String inputName : inputsNames) {
139 propertyBuilder.addGetInputValue(inputName);
141 return propertyBuilder.build();