Replaced all tabs with spaces in java and pom.xml
[so.git] / asdc-controller / src / test / java / org / onap / so / asdc / installer / heat / ToscaResourceInputTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Huawei 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 package org.onap.so.asdc.installer.heat;
21
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.mockito.Mock;
25 import org.mockito.junit.MockitoJUnit;
26 import org.mockito.junit.MockitoRule;
27 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
28 import org.onap.sdc.toscaparser.api.NodeTemplate;
29 import org.onap.sdc.toscaparser.api.Property;
30 import org.onap.sdc.toscaparser.api.elements.Metadata;
31 import org.onap.sdc.toscaparser.api.functions.GetInput;
32 import org.onap.sdc.toscaparser.api.parameters.Input;
33 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
34 import org.onap.so.asdc.installer.ToscaResourceStructure;
35 import org.onap.so.db.catalog.beans.Service;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.HashMap;
39 import java.util.LinkedHashMap;
40 import static org.junit.Assert.assertEquals;
41 import static org.mockito.Matchers.any;
42 import static org.mockito.Mockito.when;
43
44 public class ToscaResourceInputTest {
45     @Rule
46     public MockitoRule rule = MockitoJUnit.rule();
47
48     @Mock
49     ISdcCsarHelper sdcCsarHelper;
50
51     @Mock
52     NodeTemplate nodeTemplate;
53
54     @Mock
55     Property property;
56
57     @Mock
58     GetInput getInput;
59
60     @Mock
61     Input input;
62
63     @Test
64     public void processResourceSequenceTest() {
65         ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
66         ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
67         toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
68         ArrayList<Input> inputs = new ArrayList<>();
69         Service service = new Service();
70
71         HashMap<String, Object> hashMap = new HashMap();
72         hashMap.put("name", "node1");
73
74         Metadata metadata = new Metadata(hashMap);
75         when(nodeTemplate.getMetaData()).thenReturn(metadata);
76         when(sdcCsarHelper.getServiceInputs()).thenReturn(inputs);
77         when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
78         when(sdcCsarHelper.getRequirementsOf(any())).thenReturn(null);
79
80
81         toscaResourceInstaller.processResourceSequence(toscaResourceStructure, service);
82         assertEquals(service.getResourceOrder(), "node1");
83     }
84
85     @Test
86     public void resouceInputTest() throws ArtifactInstallerException {
87         ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
88         ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
89
90         toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
91
92         HashMap hashMap = new HashMap();
93         hashMap.put("customizationUUID", "id1");
94         Metadata metadata = new Metadata(hashMap);
95
96         LinkedHashMap propertyMap = new LinkedHashMap();
97         propertyMap.put("prop1", property);
98
99         when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
100         when(nodeTemplate.getMetaData()).thenReturn(metadata);
101         when(nodeTemplate.getProperties()).thenReturn(propertyMap);
102         when(property.getValue()).thenReturn("value1");
103
104         String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
105         assertEquals("{\\\"prop1\\\":\\\"value1\\\"}", resourceInput);
106     }
107
108     @Test
109     public void resouceInputGetInputTest() throws ArtifactInstallerException {
110         ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
111         ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
112
113         toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
114
115         HashMap hashMap = new HashMap();
116         hashMap.put("customizationUUID", "id1");
117         Metadata metadata = new Metadata(hashMap);
118
119         LinkedHashMap propertyMap = new LinkedHashMap();
120         propertyMap.put("prop1", property);
121
122         when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
123         when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
124         when(nodeTemplate.getMetaData()).thenReturn(metadata);
125         when(nodeTemplate.getProperties()).thenReturn(propertyMap);
126         when(property.getValue()).thenReturn(getInput);
127         when(getInput.getInputName()).thenReturn("res_key");
128         when(input.getName()).thenReturn("res_key");
129         when(input.getDefault()).thenReturn("default_value");
130
131         String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
132         assertEquals("{\\\"prop1\\\":\\\"res_key|default_value\\\"}", resourceInput);
133     }
134
135     @Test
136     public void resouceInputGetInputDefaultIntegerTest() throws ArtifactInstallerException {
137         ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
138         ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
139
140         toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
141
142         HashMap hashMap = new HashMap();
143         hashMap.put("customizationUUID", "id1");
144         Metadata metadata = new Metadata(hashMap);
145
146         LinkedHashMap propertyMap = new LinkedHashMap();
147         propertyMap.put("prop1", property);
148
149         when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
150         when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
151         when(nodeTemplate.getMetaData()).thenReturn(metadata);
152         when(nodeTemplate.getProperties()).thenReturn(propertyMap);
153         when(property.getValue()).thenReturn(getInput);
154         when(getInput.getInputName()).thenReturn("res_key");
155         when(input.getName()).thenReturn("res_key");
156         when(input.getDefault()).thenReturn(new Integer(10));
157
158         String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
159         assertEquals("{\\\"prop1\\\":\\\"res_key|10\\\"}", resourceInput);
160     }
161
162     @Test
163     public void resouceInputGetInputNoPropertyTest() throws ArtifactInstallerException {
164         ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
165         ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
166
167         toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
168
169         HashMap hashMap = new HashMap();
170         hashMap.put("customizationUUID", "id1");
171         Metadata metadata = new Metadata(hashMap);
172
173         LinkedHashMap propertyMap = new LinkedHashMap();
174
175         when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
176         when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
177         when(nodeTemplate.getMetaData()).thenReturn(metadata);
178         when(nodeTemplate.getProperties()).thenReturn(propertyMap);
179
180         String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
181         assertEquals("{}", resourceInput);
182     }
183 }