2 * ============LICENSE_START=======================================================
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
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=========================================================
20 package org.onap.so.asdc.installer.heat;
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;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.HashMap;
40 import java.util.LinkedHashMap;
42 import static org.junit.Assert.assertEquals;
43 import static org.mockito.Matchers.any;
44 import static org.mockito.Mockito.when;
46 public class ToscaResourceInputTest {
48 public MockitoRule rule = MockitoJUnit.rule();
51 ISdcCsarHelper sdcCsarHelper;
54 NodeTemplate nodeTemplate;
66 public void processResourceSequenceTest() {
67 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
68 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
69 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
70 ArrayList<Input> inputs = new ArrayList<>();
71 Service service = new Service();
73 HashMap<String, Object> hashMap = new HashMap();
74 hashMap.put("name", "node1");
76 Metadata metadata = new Metadata(hashMap);
77 when(nodeTemplate.getMetaData()).thenReturn(metadata);
78 when(sdcCsarHelper.getServiceInputs()).thenReturn(inputs);
79 when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
80 when(sdcCsarHelper.getRequirementsOf(any())).thenReturn(null);
83 toscaResourceInstaller.processResourceSequence(toscaResourceStructure, service);
84 assertEquals(service.getResourceOrder(), "node1");
88 public void resouceInputTest() throws ArtifactInstallerException {
89 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
90 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
92 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
94 HashMap hashMap = new HashMap();
95 hashMap.put("customizationUUID", "id1");
96 Metadata metadata = new Metadata(hashMap);
98 LinkedHashMap propertyMap = new LinkedHashMap();
99 propertyMap.put("prop1", property);
101 when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
102 when(nodeTemplate.getMetaData()).thenReturn(metadata);
103 when(nodeTemplate.getProperties()).thenReturn(propertyMap);
104 when(property.getValue()).thenReturn("value1");
106 String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
107 assertEquals("{\\\"prop1\\\":\\\"value1\\\"}", resourceInput);
111 public void resouceInputGetInputTest() throws ArtifactInstallerException {
112 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
113 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
115 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
117 HashMap hashMap = new HashMap();
118 hashMap.put("customizationUUID", "id1");
119 Metadata metadata = new Metadata(hashMap);
121 LinkedHashMap propertyMap = new LinkedHashMap();
122 propertyMap.put("prop1", property);
124 when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
125 when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
126 when(nodeTemplate.getMetaData()).thenReturn(metadata);
127 when(nodeTemplate.getProperties()).thenReturn(propertyMap);
128 when(property.getValue()).thenReturn(getInput);
129 when(getInput.getInputName()).thenReturn("res_key");
130 when(input.getName()).thenReturn("res_key");
131 when(input.getDefault()).thenReturn("default_value");
133 String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
134 assertEquals("{\\\"prop1\\\":\\\"res_key|default_value\\\"}", resourceInput);
138 public void resouceInputGetInputDefaultIntegerTest() throws ArtifactInstallerException {
139 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
140 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
142 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
144 HashMap hashMap = new HashMap();
145 hashMap.put("customizationUUID", "id1");
146 Metadata metadata = new Metadata(hashMap);
148 LinkedHashMap propertyMap = new LinkedHashMap();
149 propertyMap.put("prop1", property);
151 when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
152 when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
153 when(nodeTemplate.getMetaData()).thenReturn(metadata);
154 when(nodeTemplate.getProperties()).thenReturn(propertyMap);
155 when(property.getValue()).thenReturn(getInput);
156 when(getInput.getInputName()).thenReturn("res_key");
157 when(input.getName()).thenReturn("res_key");
158 when(input.getDefault()).thenReturn(new Integer(10));
160 String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
161 assertEquals("{\\\"prop1\\\":\\\"res_key|10\\\"}", resourceInput);
165 public void resouceInputGetInputNoPropertyTest() throws ArtifactInstallerException {
166 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
167 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
169 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
171 HashMap hashMap = new HashMap();
172 hashMap.put("customizationUUID", "id1");
173 Metadata metadata = new Metadata(hashMap);
175 LinkedHashMap propertyMap = new LinkedHashMap();
177 when(sdcCsarHelper.getServiceNodeTemplates()).thenReturn(Arrays.asList(nodeTemplate));
178 when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
179 when(nodeTemplate.getMetaData()).thenReturn(metadata);
180 when(nodeTemplate.getProperties()).thenReturn(propertyMap);
182 String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
183 assertEquals("{}", resourceInput);