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.input;
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;
34 import java.util.List;
36 import java.util.function.Function;
37 import java.util.stream.Collectors;
39 import static org.mockito.Mockito.verify;
41 @RunWith(MockitoJUnitRunner.class)
42 public abstract class BaseComponentInputsMerge {
45 protected ToscaOperationFacade toscaOperationFacade;
48 InputsValuesMergingBusinessLogic inputsValuesMergingBusinessLogic;
51 DeclaredInputsResolver declaredInputsResolver;
54 ArgumentCaptor<Map<String, List<PropertyDataDefinition>>> getInputPropertiesCaptor;
56 Resource prevResource, currResource;
57 protected static final String RESOURCE_ID = "newResourceId";
59 public void setUp() throws Exception {
60 prevResource = new ResourceBuilder()
65 currResource = new ResourceBuilder()
66 .addInstanceProperty("inst1", "prop1")
67 .addInstanceProperty("inst1", "prop2")
68 .addInstanceInput("inst2", "prop3")
69 .addGroupProperty("group1", "prop1")
70 .addPolicyProperty("policy1", "prop2")
72 .setUniqueId(RESOURCE_ID)
76 void verifyCallToMergeComponentInputs(Resource oldResource, List<InputDefinition> inputsToMerge) {
77 Map<String, InputDefinition> oldInputsByName = oldResource.getInputs().stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
78 Map<String, InputDefinition> inputsToMergeByName = inputsToMerge.stream().collect(Collectors.toMap(InputDefinition::getName, Function.identity()));
79 verify(inputsValuesMergingBusinessLogic).mergeComponentInputs(oldInputsByName, inputsToMergeByName);