diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java')
-rw-r--r-- | bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java | 135 |
1 files changed, 67 insertions, 68 deletions
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java index 9baf5dc5bf..be100652c0 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModuleTest.java @@ -20,27 +20,28 @@ package org.onap.so.client.cds; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.Resources; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.VfModules; import org.onap.so.serviceinstancebeans.Vnfs; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.doReturn; -@RunWith(MockitoJUnitRunner.Silent.class) +@RunWith(MockitoJUnitRunner.class) public class ConfigureInstanceParamsForVfModuleTest { @InjectMocks @@ -49,79 +50,77 @@ public class ConfigureInstanceParamsForVfModuleTest { @Mock private ExtractServiceFromUserParameters extractServiceFromUserParameters; - private static final String TEST_VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4"; - private static final String TEST_VF_MODULE_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce2"; - private static final String TEST_INSTANCE_PARAM_VALUE_1 = "vf-module-1-value"; - private static final String TEST_INSTANCE_PARAM_VALUE_2 = "vf-module-2-value"; - private static final String TEST_INSTANCE_PARAM_KEY_1 = "instance-param-1"; - private static final String TEST_INSTANCE_PARAM_KEY_2 = "instance-param-2"; + private static final String VNF_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VFMODULE_1_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VFMODULE_2_CUSTOMIZATION_ID = UUID.randomUUID().toString(); + private static final String VFMODULE_1_INSTANCE_NAME = "vfmodule-instance-1"; + private static final String VFMODULE_2_INSTANCE_NAME = "vfmodule-instance-2"; + private static final List<Map<String, String>> VFMODULE_1_INSTANCE_PARAMS = + Arrays.asList(Map.of("param-1", "xyz", "param-2", "123"), Map.of("param-3", "CCC")); + private static final List<Map<String, String>> VFMODULE_2_INSTANCE_PARAMS = + Arrays.asList(Map.of("param-1", "abc", "param-2", "999"), Map.of("param-3", "AAA")); + @Test - public void testInstanceParamsForVfModule() throws Exception { - // given - List<Map<String, Object>> userParamsFromRequest = createRequestParameters(); - JsonObject jsonObject = new JsonObject(); - doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList()); + public void testPopulateInstanceParamsByInstanceName() throws Exception { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfs()); + service.setResources(resources); - // when - configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, userParamsFromRequest, - TEST_VNF_MODEL_CUSTOMIZATION_UUID, TEST_VF_MODULE_CUSTOMIZATION_UUID); + when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(Optional.of(service)); + JsonObject jsonObject = new JsonObject(); - // verify - assertEquals(TEST_INSTANCE_PARAM_VALUE_1, jsonObject.get(TEST_INSTANCE_PARAM_KEY_1).getAsString()); - assertEquals(TEST_INSTANCE_PARAM_VALUE_2, jsonObject.get(TEST_INSTANCE_PARAM_KEY_2).getAsString()); - } + configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID, + VFMODULE_2_CUSTOMIZATION_ID, VFMODULE_2_INSTANCE_NAME); - private List<Map<String, Object>> createRequestParameters() { - List<Map<String, Object>> userParams = new ArrayList<>(); - Map<String, Object> userParamMap = new HashMap<>(); - userParamMap.put("service", getUserParams()); - userParams.add(userParamMap); - return userParams; + assertEquals("abc", jsonObject.get("param-1").getAsString()); + assertEquals("999", jsonObject.get("param-2").getAsString()); + assertEquals("AAA", jsonObject.get("param-3").getAsString()); } - private Service getUserParams() { + @Test + public void testPopulateInstanceParamsByCustomizationId() throws Exception { Service service = new Service(); Resources resources = new Resources(); resources.setVnfs(createVnfs()); service.setResources(resources); - return service; - } - - private List<Vnfs> createVnfs() { - Vnfs searchedVnf = createVnf(); - List<Vnfs> vnfList = new ArrayList<>(); - vnfList.add(searchedVnf); - return vnfList; - } - - private Vnfs createVnf() { - Vnfs vnf = new Vnfs(); - ModelInfo modelInfoForVnf = new ModelInfo(); - modelInfoForVnf.setModelCustomizationId(TEST_VNF_MODEL_CUSTOMIZATION_UUID); - vnf.setModelInfo(modelInfoForVnf); - - VfModules vfModule = new VfModules(); - ModelInfo modelInfoForVfModule = new ModelInfo(); - modelInfoForVfModule.setModelCustomizationId(TEST_VF_MODULE_CUSTOMIZATION_UUID); - - vfModule.setModelInfo(modelInfoForVfModule); - - // Set instance parameters. - List<Map<String, String>> instanceParamsListSearchedVfModule = new ArrayList<>(); - Map<String, String> instanceParams = new HashMap<>(); - instanceParams.put("instance-param-1", TEST_INSTANCE_PARAM_VALUE_1); - instanceParams.put("instance-param-2", TEST_INSTANCE_PARAM_VALUE_2); - - instanceParamsListSearchedVfModule.add(instanceParams); - vfModule.setInstanceParams(instanceParamsListSearchedVfModule); + when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(Optional.of(service)); + JsonObject jsonObject = new JsonObject(); - List<VfModules> vfModules = new ArrayList<>(); - vfModules.add(vfModule); + // No instance name is passed + configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID, + VFMODULE_1_CUSTOMIZATION_ID, null); - vnf.setVfModules(vfModules); + assertEquals("xyz", jsonObject.get("param-1").getAsString()); + assertEquals("123", jsonObject.get("param-2").getAsString()); + assertEquals("CCC", jsonObject.get("param-3").getAsString()); + } - return vnf; + private List<Vnfs> createVnfs() { + Vnfs vnf1 = new Vnfs(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VNF_CUSTOMIZATION_ID); + vnf1.setModelInfo(modelInfo); + + VfModules vfModule1 = new VfModules(); + modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VFMODULE_1_CUSTOMIZATION_ID); + vfModule1.setModelInfo(modelInfo); + vfModule1.setInstanceName(VFMODULE_1_INSTANCE_NAME); + vfModule1.setInstanceParams(VFMODULE_1_INSTANCE_PARAMS); + + VfModules vfModule2 = new VfModules(); + modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(VFMODULE_2_CUSTOMIZATION_ID); + vfModule2.setModelInfo(modelInfo); + vfModule2.setInstanceName(VFMODULE_2_INSTANCE_NAME); + vfModule2.setInstanceParams(VFMODULE_2_INSTANCE_PARAMS); + + vnf1.setVfModules(Arrays.asList(vfModule1, vfModule2)); + + return Arrays.asList(vnf1); } + } |