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;
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;
44 public class ToscaResourceInputTest {
46 public MockitoRule rule = MockitoJUnit.rule();
49 ISdcCsarHelper sdcCsarHelper;
52 NodeTemplate nodeTemplate;
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();
71 HashMap<String, Object> hashMap = new HashMap();
72 hashMap.put("name", "node1");
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);
81 toscaResourceInstaller.processResourceSequence(toscaResourceStructure, service);
82 assertEquals(service.getResourceOrder(), "node1");
86 public void resouceInputTest() throws ArtifactInstallerException {
87 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
88 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
90 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
92 HashMap hashMap = new HashMap();
93 hashMap.put("customizationUUID", "id1");
94 Metadata metadata = new Metadata(hashMap);
96 LinkedHashMap propertyMap = new LinkedHashMap();
97 propertyMap.put("prop1", property);
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");
104 String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
105 assertEquals("{\\\"prop1\\\":\\\"value1\\\"}", resourceInput);
109 public void resouceInputGetInputTest() throws ArtifactInstallerException {
110 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
111 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
113 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
115 HashMap hashMap = new HashMap();
116 hashMap.put("customizationUUID", "id1");
117 Metadata metadata = new Metadata(hashMap);
119 LinkedHashMap propertyMap = new LinkedHashMap();
120 propertyMap.put("prop1", property);
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");
131 String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
132 assertEquals("{\\\"prop1\\\":\\\"res_key|default_value\\\"}", resourceInput);
136 public void resouceInputGetInputDefaultIntegerTest() throws ArtifactInstallerException {
137 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
138 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
140 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
142 HashMap hashMap = new HashMap();
143 hashMap.put("customizationUUID", "id1");
144 Metadata metadata = new Metadata(hashMap);
146 LinkedHashMap propertyMap = new LinkedHashMap();
147 propertyMap.put("prop1", property);
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));
158 String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
159 assertEquals("{\\\"prop1\\\":\\\"res_key|10\\\"}", resourceInput);
163 public void resouceInputGetInputNoPropertyTest() throws ArtifactInstallerException {
164 ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
165 ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
167 toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
169 HashMap hashMap = new HashMap();
170 hashMap.put("customizationUUID", "id1");
171 Metadata metadata = new Metadata(hashMap);
173 LinkedHashMap propertyMap = new LinkedHashMap();
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);
180 String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
181 assertEquals("{}", resourceInput);