2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.so.client.cds;
23 import com.fasterxml.jackson.databind.JsonNode;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.junit.Test;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.Spy;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
30 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
31 import org.onap.so.client.exception.PayloadGenerationException;
32 import org.onap.so.serviceinstancebeans.Service;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import java.util.List;
36 import static org.assertj.core.api.Assertions.assertThat;
37 import static org.junit.Assert.assertNotNull;
38 import static org.junit.Assert.assertTrue;
39 import static org.mockito.Mockito.*;
41 public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest {
44 private ObjectMapper objectMapper;
47 protected ExtractServiceFromUserParameters extractServiceFromUserParameters;
51 protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
54 private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
58 public void testRequestPayloadForConfigDeployVfModule() throws Exception {
60 setScopeAndAction(VF_SCOPE, DEPLOY_ACTION);
61 ServiceInstance serviceInstance = createServiceInstance();
63 doReturn(serviceInstance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
64 ResourceKey.SERVICE_INSTANCE_ID);
65 doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
66 ResourceKey.GENERIC_VNF_ID);
67 doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
68 ResourceKey.VF_MODULE_ID);
69 doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList());
70 doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(),
74 vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution);
75 String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get();
78 ObjectMapper mapper = new ObjectMapper();
79 JsonNode payloadJson = mapper.readTree(payload);
80 JsonNode requestNode = payloadJson.findValue("configDeploy-request");
81 JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties");
83 assertNotNull(payload);
84 assertTrue(verfiyJsonFromString(payload));
85 assertThat(requestNode.get("resolution-key").asText()).isEqualTo(VF_MODULE_NAME);
86 assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
87 assertThat(propertiesNode.get("vf-module-id").asText()).isEqualTo(VF_MODULE_ID);
88 assertThat(propertiesNode.get("vf-module-name").asText()).isEqualTo(VF_MODULE_NAME);
89 assertThat(propertiesNode.get("vf-module-customization-uuid").asText()).isEqualTo(VF_MODULE_CUSTOMIZATION_UUID);
90 assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
91 assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);
95 public void testRequestPayloadForConfigDeployVfModuleWithoutUserParams() throws Exception {
97 setScopeAndActionWithoutUserParams(VF_SCOPE, DEPLOY_ACTION);
98 ServiceInstance serviceInstance = createServiceInstance();
100 doReturn(serviceInstance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
101 ResourceKey.SERVICE_INSTANCE_ID);
102 doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
103 ResourceKey.GENERIC_VNF_ID);
104 doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
105 ResourceKey.VF_MODULE_ID);
106 doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList());
107 doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(),
110 vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution);
111 String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get();
114 ObjectMapper mapper = new ObjectMapper();
115 JsonNode payloadJson = mapper.readTree(payload);
116 JsonNode requestNode = payloadJson.findValue("configDeploy-request");
117 JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties");
119 assertNotNull(payload);
120 assertTrue(verfiyJsonFromString(payload));
121 assertThat(requestNode.get("resolution-key").asText()).isEqualTo(VF_MODULE_NAME);
122 assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
123 assertThat(propertiesNode.get("vf-module-id").asText()).isEqualTo(VF_MODULE_ID);
124 assertThat(propertiesNode.get("vf-module-name").asText()).isEqualTo(VF_MODULE_NAME);
125 assertThat(propertiesNode.get("vf-module-customization-uuid").asText()).isEqualTo(VF_MODULE_CUSTOMIZATION_UUID);
126 assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
127 assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);