Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / merge / input / BaseComponentInputsMerge.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.merge.input;
22
23 import org.junit.runner.RunWith;
24 import org.mockito.ArgumentCaptor;
25 import org.mockito.Captor;
26 import org.mockito.Mock;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
29 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
30 import org.openecomp.sdc.be.model.InputDefinition;
31 import org.openecomp.sdc.be.model.Resource;
32 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
33
34 import java.util.List;
35 import java.util.Map;
36 import java.util.function.Function;
37 import java.util.stream.Collectors;
38
39 import static org.mockito.Mockito.verify;
40
41 @RunWith(MockitoJUnitRunner.class)
42 public abstract class BaseComponentInputsMerge {
43
44     @Mock
45     protected ToscaOperationFacade toscaOperationFacade;
46
47     @Mock
48     InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogic;
49
50     @Mock
51     DeclaredInputsResolver declaredInputsResolver;
52
53     @Captor
54     ArgumentCaptor<Map<String, List<PropertyDataDefinition>>> getInputPropertiesCaptor;
55
56     Resource prevResource, currResource;
57     protected static final String RESOURCE_ID = "newResourceId";
58
59     public void setUp() throws Exception {
60         prevResource = new ResourceBuilder()
61                 .addInput("input1")
62                 .addInput("input2")
63                 .addComponentInstance("inst1")
64                 .build();
65
66         currResource = new ResourceBuilder()
67                 .addComponentInstance("inst1")
68                 .addInstanceProperty("inst1", "prop1")
69                 .addInstanceProperty("inst1", "prop2")
70                 .addInstanceInput("inst2", "prop3")
71                 .addGroupProperty("group1", "prop1")
72                 .addPolicyProperty("policy1", "prop2")
73                 .addInput("input1")
74                 .setUniqueId(RESOURCE_ID)
75                 .build();
76     }
77
78     void verifyCallToMergeComponentInputs(Resource oldResource, List<InputDefinition> inputsToMerge) {
79         Map<String, InputDefinition> oldInputsByName = oldResource.getInputs().stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
80         Map<String, InputDefinition> inputsToMergeByName = inputsToMerge.stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
81         verify(inputsValuesMergingBusinessLogic).mergeComponentInputs(oldInputsByName, inputsToMergeByName);
82     }
83 }