Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / property / PropertyDeserializationOrchestratorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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.property;
22
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;
37
38 import java.util.HashMap;
39 import java.util.Iterator;
40 import java.util.LinkedList;
41 import java.util.List;
42 import java.util.Map;
43
44 public class PropertyDeserializationOrchestratorTest {
45
46         @InjectMocks
47         PropertyDeclarationOrchestrator testSubject;
48
49         @Mock
50         List<PropertyDeclarator> propertyDeceleratorsMock;
51         
52         @Mock
53         private ComponentInstanceInputPropertyDeclarator componentInstanceInputPropertyDecelerator;
54         @Mock
55         private ComponentInstancePropertyDeclarator componentInstancePropertyDecelerator;
56         @Mock
57         private PolicyPropertyDeclarator policyPropertyDecelerator;
58
59         @Before
60         public void setUp() throws Exception {
61
62                 MockitoAnnotations.initMocks(this);
63         }
64
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;
74
75                 // default test
76                 result = testSubject.declarePropertiesToInputs(component, componentInstInputsMap);
77         }
78
79         @Test
80         public void testUnDeclarePropertiesAsInputs() throws Exception {
81                 Component component = new Resource();
82                 InputDefinition inputToDelete = new InputDefinition();
83                 StorageOperationStatus result;
84
85                 Iterator<PropertyDeclarator> mockIter = Mockito.mock(Iterator.class);
86                 Mockito.when(propertyDeceleratorsMock.iterator()).thenReturn(mockIter);
87                 Mockito.when(mockIter.hasNext()).thenReturn(false);
88                 
89                 // default test
90                 result = testSubject.unDeclarePropertiesAsInputs(component, inputToDelete);
91         }
92
93         @Test(expected = IllegalStateException.class)
94         public void testGetPropertyDecelerator() throws Exception {
95                 ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
96                 PropertyDeclarator result;
97
98                 // default test
99                 result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
100         }
101
102         @Test
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;
110
111                 // default test
112                 result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
113         }
114
115         @Test
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;
123
124                 // default test
125                 result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
126         }
127
128         @Test
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;
136
137                 // default test
138                 result = Deencapsulation.invoke(testSubject, "getPropertyDeclarator", componentInstInputsMap);
139         }
140 }