2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.property;
23 import fj.data.Either;
24 import mockit.Deencapsulation;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.openecomp.sdc.be.model.Component;
32 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
33 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
34 import org.openecomp.sdc.be.model.InputDefinition;
35 import org.openecomp.sdc.be.model.Resource;
36 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
38 import java.util.HashMap;
39 import java.util.Iterator;
40 import java.util.LinkedList;
41 import java.util.List;
44 public class PropertyDeserializationOrchestratorTest {
47 PropertyDeclarationOrchestrator testSubject;
50 List<PropertyDeclarator> propertyDeceleratorsMock;
53 private ComponentInstanceInputPropertyDeclarator componentInstanceInputPropertyDecelerator;
55 private ComponentInstancePropertyDeclarator componentInstancePropertyDecelerator;
57 private PolicyPropertyDeclarator policyPropertyDecelerator;
60 public void setUp() throws Exception {
62 MockitoAnnotations.openMocks(this);
65 @Test(expected = IllegalStateException.class)
66 public void testDeclarePropertiesToInputs() throws Exception {
67 Component component = new Resource();
68 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
69 componentInstInputsMap.setComponentInstanceInputsMap(new HashMap<>());
70 componentInstInputsMap.setComponentInstancePropInput(new HashMap<>());
71 componentInstInputsMap.setPolicyProperties(new HashMap<>());
72 componentInstInputsMap.setGroupProperties(new HashMap<>());
73 Either<List<InputDefinition>, StorageOperationStatus> result;
76 result = testSubject.declarePropertiesToInputs(component, componentInstInputsMap);
80 public void testUnDeclarePropertiesAsInputs() throws Exception {
81 Component component = new Resource();
82 InputDefinition inputToDelete = new InputDefinition();
83 StorageOperationStatus result;
85 Iterator<PropertyDeclarator> mockIter = Mockito.mock(Iterator.class);
86 Mockito.when(propertyDeceleratorsMock.iterator()).thenReturn(mockIter);
87 Mockito.when(mockIter.hasNext()).thenReturn(false);
90 result = testSubject.unDeclarePropertiesAsInputs(component, inputToDelete);
93 @Test(expected = IllegalStateException.class)
94 public void testGetPropertyDecelerator() throws Exception {
95 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
96 PropertyDeclarator result;
99 result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
103 public void testGetPropertyDeceleratorWithInputsMap() throws Exception {
104 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
105 Map<String, List<ComponentInstancePropInput>> componentInstanceInputsMap = new HashMap<>();
106 List<ComponentInstancePropInput> value = new LinkedList<>();
107 componentInstanceInputsMap.put("mock", value);
108 componentInstInputsMap.setComponentInstanceInputsMap(componentInstanceInputsMap);
109 PropertyDeclarator result;
112 result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
116 public void testGetPropertyDeceleratorWithCIProperties() throws Exception {
117 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
118 Map<String, List<ComponentInstancePropInput>> componentInstanceProperties = new HashMap<>();
119 List<ComponentInstancePropInput> value = new LinkedList<>();
120 componentInstanceProperties.put("mock", value);
121 componentInstInputsMap.setComponentInstancePropInput(componentInstanceProperties);
122 PropertyDeclarator result;
125 result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
129 public void testGetPropertyDeceleratorWithCIPolicy() throws Exception {
130 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
131 Map<String, List<ComponentInstancePropInput>> policyProperties = new HashMap<>();
132 List<ComponentInstancePropInput> value = new LinkedList<>();
133 policyProperties.put("mock", value);
134 componentInstInputsMap.setPolicyProperties(policyProperties);
135 PropertyDeclarator result;
138 result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);