Prepare for Junit5
[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.jupiter.api.extension.ExtendWith;
24 import org.mockito.ArgumentCaptor;
25 import org.mockito.Captor;
26 import org.mockito.Mock;
27 import org.mockito.junit.jupiter.MockitoExtension;
28 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
29 import org.openecomp.sdc.be.config.ConfigurationManager;
30 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
31 import org.openecomp.sdc.be.model.InputDefinition;
32 import org.openecomp.sdc.be.model.Resource;
33 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
34
35 import java.util.List;
36 import java.util.Map;
37 import java.util.function.Function;
38 import java.util.stream.Collectors;
39 import org.openecomp.sdc.common.impl.ExternalConfiguration;
40 import org.openecomp.sdc.common.impl.FSConfigurationSource;
41
42 import static org.mockito.Mockito.verify;
43
44 @ExtendWith(MockitoExtension.class)
45 public abstract class BaseComponentInputsMerge {
46     private final ConfigurationManager configurationManager = new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
47
48     @Mock
49     protected ToscaOperationFacade toscaOperationFacade;
50
51     @Mock
52     InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogic;
53
54     @Mock
55     DeclaredInputsResolver declaredInputsResolver;
56
57     @Captor
58     ArgumentCaptor<Map<String, List<PropertyDataDefinition>>> getInputPropertiesCaptor;
59
60     Resource prevResource, currResource;
61     protected static final String RESOURCE_ID = "newResourceId";
62
63     public void setUp() throws Exception {
64         prevResource = new ResourceBuilder()
65                 .addInput("input1")
66                 .addInput("input2")
67                 .addComponentInstance("inst1")
68                 .build();
69
70         currResource = new ResourceBuilder()
71                 .addComponentInstance("inst1")
72                 .addInstanceProperty("inst1", "prop1")
73                 .addInstanceProperty("inst1", "prop2")
74                 .addInstanceInput("inst2", "prop3")
75                 .addGroupProperty("group1", "prop1")
76                 .addPolicyProperty("policy1", "prop2")
77                 .addInput("input1")
78                 .setUniqueId(RESOURCE_ID)
79                 .build();
80     }
81
82     void verifyCallToMergeComponentInputs(Resource oldResource, List<InputDefinition> inputsToMerge) {
83         Map<String, InputDefinition> oldInputsByName = oldResource.getInputs().stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
84         Map<String, InputDefinition> inputsToMergeByName = inputsToMerge.stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
85         verify(inputsValuesMergingBusinessLogic).mergeComponentInputs(oldInputsByName, inputsToMergeByName);
86     }
87 }