9baf5dc5bf85a4eeac8f55ffd8f808ca66f20681
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / client / cds / ConfigureInstanceParamsForVfModuleTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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
21 package org.onap.so.client.cds;
22
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;
38 import java.util.Map;
39 import static org.junit.Assert.assertEquals;
40 import static org.mockito.ArgumentMatchers.anyList;
41 import static org.mockito.Mockito.doReturn;
42
43 @RunWith(MockitoJUnitRunner.Silent.class)
44 public class ConfigureInstanceParamsForVfModuleTest {
45
46     @InjectMocks
47     private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
48
49     @Mock
50     private ExtractServiceFromUserParameters extractServiceFromUserParameters;
51
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";
58
59     @Test
60     public void testInstanceParamsForVfModule() throws Exception {
61         // given
62         List<Map<String, Object>> userParamsFromRequest = createRequestParameters();
63         JsonObject jsonObject = new JsonObject();
64         doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList());
65
66         // when
67         configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, userParamsFromRequest,
68                 TEST_VNF_MODEL_CUSTOMIZATION_UUID, TEST_VF_MODULE_CUSTOMIZATION_UUID);
69
70         // verify
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());
73     }
74
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);
80         return userParams;
81     }
82
83     private Service getUserParams() {
84         Service service = new Service();
85         Resources resources = new Resources();
86         resources.setVnfs(createVnfs());
87         service.setResources(resources);
88         return service;
89     }
90
91     private List<Vnfs> createVnfs() {
92         Vnfs searchedVnf = createVnf();
93         List<Vnfs> vnfList = new ArrayList<>();
94         vnfList.add(searchedVnf);
95         return vnfList;
96     }
97
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);
103
104         VfModules vfModule = new VfModules();
105
106         ModelInfo modelInfoForVfModule = new ModelInfo();
107         modelInfoForVfModule.setModelCustomizationId(TEST_VF_MODULE_CUSTOMIZATION_UUID);
108
109         vfModule.setModelInfo(modelInfoForVfModule);
110
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);
116
117         instanceParamsListSearchedVfModule.add(instanceParams);
118         vfModule.setInstanceParams(instanceParamsListSearchedVfModule);
119
120         List<VfModules> vfModules = new ArrayList<>();
121         vfModules.add(vfModule);
122
123         vnf.setVfModules(vfModules);
124
125         return vnf;
126     }
127 }