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 com.google.gson.JsonObject;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
30 import org.onap.so.serviceinstancebeans.ModelInfo;
31 import org.onap.so.serviceinstancebeans.Resources;
32 import org.onap.so.serviceinstancebeans.Service;
33 import org.onap.so.serviceinstancebeans.VfModules;
34 import org.onap.so.serviceinstancebeans.Vnfs;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
39 import static org.junit.Assert.assertEquals;
40 import static org.mockito.ArgumentMatchers.anyList;
41 import static org.mockito.Mockito.doReturn;
43 @RunWith(MockitoJUnitRunner.Silent.class)
44 public class ConfigureInstanceParamsForVfModuleTest {
47 private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
50 private ExtractServiceFromUserParameters extractServiceFromUserParameters;
52 private static final String TEST_VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4";
53 private static final String TEST_VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce2";
54 private static final String TEST_INSTANCE_PARAM_VALUE_1 = "vf-module-1-value";
55 private static final String TEST_INSTANCE_PARAM_VALUE_2 = "vf-module-2-value";
56 private static final String TEST_INSTANCE_PARAM_KEY_1 = "instance-param-1";
57 private static final String TEST_INSTANCE_PARAM_KEY_2 = "instance-param-2";
60 public void testInstanceParamsForVfModule() throws Exception {
62 List<Map<String, Object>> userParamsFromRequest = createRequestParameters();
63 JsonObject jsonObject = new JsonObject();
64 doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList());
67 configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, userParamsFromRequest,
68 TEST_VNF_MODEL_CUSTOMIZATION_UUID, TEST_VF_MODULE_CUSTOMIZATION_UUID);
71 assertEquals(TEST_INSTANCE_PARAM_VALUE_1, jsonObject.get(TEST_INSTANCE_PARAM_KEY_1).getAsString());
72 assertEquals(TEST_INSTANCE_PARAM_VALUE_2, jsonObject.get(TEST_INSTANCE_PARAM_KEY_2).getAsString());
75 private List<Map<String, Object>> createRequestParameters() {
76 List<Map<String, Object>> userParams = new ArrayList<>();
77 Map<String, Object> userParamMap = new HashMap<>();
78 userParamMap.put("service", getUserParams());
79 userParams.add(userParamMap);
83 private Service getUserParams() {
84 Service service = new Service();
85 Resources resources = new Resources();
86 resources.setVnfs(createVnfs());
87 service.setResources(resources);
91 private List<Vnfs> createVnfs() {
92 Vnfs searchedVnf = createVnf();
93 List<Vnfs> vnfList = new ArrayList<>();
94 vnfList.add(searchedVnf);
98 private Vnfs createVnf() {
99 Vnfs vnf = new Vnfs();
100 ModelInfo modelInfoForVnf = new ModelInfo();
101 modelInfoForVnf.setModelCustomizationId(TEST_VNF_MODEL_CUSTOMIZATION_UUID);
102 vnf.setModelInfo(modelInfoForVnf);
104 VfModules vfModule = new VfModules();
106 ModelInfo modelInfoForVfModule = new ModelInfo();
107 modelInfoForVfModule.setModelCustomizationId(TEST_VF_MODULE_CUSTOMIZATION_UUID);
109 vfModule.setModelInfo(modelInfoForVfModule);
111 // Set instance parameters.
112 List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>();
113 Map<String, String> instanceParams = new HashMap<>();
114 instanceParams.put("instance-param-1", TEST_INSTANCE_PARAM_VALUE_1);
115 instanceParams.put("instance-param-2", TEST_INSTANCE_PARAM_VALUE_2);
117 instanceParamsListSearchedVfModule.add(instanceParams);
118 vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
120 List<VfModules> vfModules = new ArrayList<>();
121 vfModules.add(vfModule);
123 vnf.setVfModules(vfModules);