2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Bell Canada
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.onap.so.client.cds;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.when;
26 import com.google.gson.JsonObject;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
31 import java.util.UUID;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.junit.MockitoJUnitRunner;
37 import org.onap.so.serviceinstancebeans.ModelInfo;
38 import org.onap.so.serviceinstancebeans.Resources;
39 import org.onap.so.serviceinstancebeans.Service;
40 import org.onap.so.serviceinstancebeans.VfModules;
41 import org.onap.so.serviceinstancebeans.Vnfs;
43 @RunWith(MockitoJUnitRunner.class)
44 public class ConfigureInstanceParamsForVfModuleTest {
47 private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
50 private ExtractServiceFromUserParameters extractServiceFromUserParameters;
52 private static final String VNF_CUSTOMIZATION_ID = UUID.randomUUID().toString();
53 private static final String VFMODULE_1_CUSTOMIZATION_ID = UUID.randomUUID().toString();
54 private static final String VFMODULE_2_CUSTOMIZATION_ID = UUID.randomUUID().toString();
55 private static final String VFMODULE_1_INSTANCE_NAME = "vfmodule-instance-1";
56 private static final String VFMODULE_2_INSTANCE_NAME = "vfmodule-instance-2";
57 private static final List<Map<String, String>> VFMODULE_1_INSTANCE_PARAMS =
58 Arrays.asList(Map.of("param-1", "xyz", "param-2", "123"), Map.of("param-3", "CCC"));
59 private static final List<Map<String, String>> VFMODULE_2_INSTANCE_PARAMS =
60 Arrays.asList(Map.of("param-1", "abc", "param-2", "999"), Map.of("param-3", "AAA"));
64 public void testPopulateInstanceParamsByInstanceName() throws Exception {
65 Service service = new Service();
66 Resources resources = new Resources();
67 resources.setVnfs(createVnfs());
68 service.setResources(resources);
70 when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(service);
71 JsonObject jsonObject = new JsonObject();
73 configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID,
74 VFMODULE_2_CUSTOMIZATION_ID, VFMODULE_2_INSTANCE_NAME);
76 assertEquals("abc", jsonObject.get("param-1").getAsString());
77 assertEquals("999", jsonObject.get("param-2").getAsString());
78 assertEquals("AAA", jsonObject.get("param-3").getAsString());
82 public void testPopulateInstanceParamsByCustomizationId() throws Exception {
83 Service service = new Service();
84 Resources resources = new Resources();
85 resources.setVnfs(createVnfs());
86 service.setResources(resources);
88 when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(service);
89 JsonObject jsonObject = new JsonObject();
91 // No instance name is passed
92 configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID,
93 VFMODULE_1_CUSTOMIZATION_ID, null);
95 assertEquals("xyz", jsonObject.get("param-1").getAsString());
96 assertEquals("123", jsonObject.get("param-2").getAsString());
97 assertEquals("CCC", jsonObject.get("param-3").getAsString());
100 private List<Vnfs> createVnfs() {
101 Vnfs vnf1 = new Vnfs();
102 ModelInfo modelInfo = new ModelInfo();
103 modelInfo.setModelCustomizationId(VNF_CUSTOMIZATION_ID);
104 vnf1.setModelInfo(modelInfo);
106 VfModules vfModule1 = new VfModules();
107 modelInfo = new ModelInfo();
108 modelInfo.setModelCustomizationId(VFMODULE_1_CUSTOMIZATION_ID);
109 vfModule1.setModelInfo(modelInfo);
110 vfModule1.setInstanceName(VFMODULE_1_INSTANCE_NAME);
111 vfModule1.setInstanceParams(VFMODULE_1_INSTANCE_PARAMS);
113 VfModules vfModule2 = new VfModules();
114 modelInfo = new ModelInfo();
115 modelInfo.setModelCustomizationId(VFMODULE_2_CUSTOMIZATION_ID);
116 vfModule2.setModelInfo(modelInfo);
117 vfModule2.setInstanceName(VFMODULE_2_INSTANCE_NAME);
118 vfModule2.setInstanceParams(VFMODULE_2_INSTANCE_PARAMS);
120 vnf1.setVfModules(Arrays.asList(vfModule1, vfModule2));
122 return Arrays.asList(vnf1);