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 com.google.common.collect.ImmutableMap;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
27 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
28 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
29 import org.openecomp.sdc.be.model.InputDefinition;
30 import org.openecomp.sdc.be.model.Resource;
32 import java.util.List;
35 import static java.util.Arrays.asList;
36 import static java.util.Collections.emptyMap;
37 import static java.util.Collections.singletonList;
38 import static org.assertj.core.api.Assertions.assertThat;
41 public class DeclaredInputsResolverTest {
43 private DeclaredInputsResolver testInstance;
44 private Resource prevResource, currResource;
47 public void setUp() throws Exception {
48 testInstance = new DeclaredInputsResolver();
49 prevResource = new ResourceBuilder()
56 currResource = new ResourceBuilder()
63 public void whenPropertiesMapIsEmpty_returnEmptyList() {
64 List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currResource, emptyMap());
65 assertThat(previouslyDeclaredInputsToMerge).isEmpty();
69 public void whenPrevResourceHasNoInputs_returnEmptyList() {
70 List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(new Resource(), currResource, emptyMap());
71 assertThat(previouslyDeclaredInputsToMerge).isEmpty();
75 public void whenAllPropertiesNotReferencingInput_returnEmptyList() {
76 PropertyDataDefinition prop1 = createProperty("prop1");
77 PropertyDataDefinition prop2 = createProperty("prop2");
78 Map<String, List<PropertyDataDefinition>> props = ImmutableMap.of("inst1", singletonList(prop1), "inst2", singletonList(prop2));
79 List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currResource, props);
80 assertThat(previouslyDeclaredInputsToMerge).isEmpty();
84 public void doNotReturnReferencedInputIfAlreadyExistInNewResource() {
85 PropertyDataDefinition prop1 = createPropertyReferencingInput("prop1", "input1");
86 PropertyDataDefinition prop2 = createPropertyReferencingInput("prop2", "input3");
87 Map<String, List<PropertyDataDefinition>> props = ImmutableMap.of("inst1", singletonList(prop1), "inst2", singletonList(prop2));
88 List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currResource, props);
89 assertThat(previouslyDeclaredInputsToMerge).isEmpty();
93 public void returnAllInputsReferencedByPropertyAndNotExistInNewResource() {
94 PropertyDataDefinition prop1 = createPropertyReferencingInput("prop1", "input1");
95 PropertyDataDefinition prop2 = createPropertyReferencingInput("prop2", "input2");
96 PropertyDataDefinition prop3 = createPropertyReferencingInput("prop3", "input3");
97 PropertyDataDefinition prop4 = createPropertyReferencingInput("prop4", "input4");
98 PropertyDataDefinition prop5 = createProperty("prop5");
99 Map<String, List<PropertyDataDefinition>> props = ImmutableMap.of("inst1", asList(prop1, prop3), "inst2", singletonList(prop2), "group1", asList(prop4, prop5));
100 List<InputDefinition> previouslyDeclaredInputsToMerge = testInstance.getPreviouslyDeclaredInputsToMerge(prevResource, currResource, props);
101 assertThat(previouslyDeclaredInputsToMerge)
103 .containsExactlyInAnyOrder("input2", "input4");
106 private PropertyDataDefinition createPropertyReferencingInput(String propName, String referencingInputName) {
107 return new PropertyDataDefinitionBuilder()
109 .addGetInputValue(referencingInputName)
113 private PropertyDataDefinition createProperty(String propName) {
114 return new PropertyDataDefinitionBuilder()