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 com.google.gson.JsonObject;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.UUID;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Spy;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
36 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
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;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import java.util.List;
45 import static org.assertj.core.api.Assertions.assertThat;
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertNotNull;
48 import static org.junit.Assert.assertTrue;
49 import static org.mockito.Mockito.*;
51 public class VfModuleCDSRequestProviderTest extends AbstractVnfCDSRequestProviderTest {
54 private ObjectMapper objectMapper;
57 protected ExtractServiceFromUserParameters extractServiceFromUserParameters;
61 protected ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule;
64 private VfModuleCDSRequestProvider vfModuleCDSRequestProvider;
68 public void testRequestPayloadForConfigDeployVfModule() throws Exception {
70 setScopeAndAction(VF_SCOPE, DEPLOY_ACTION);
71 ServiceInstance serviceInstance = createServiceInstance();
73 doReturn(serviceInstance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
74 ResourceKey.SERVICE_INSTANCE_ID);
75 doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
76 ResourceKey.GENERIC_VNF_ID);
77 doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
78 ResourceKey.VF_MODULE_ID);
79 doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList());
80 doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(),
84 vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution);
85 String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get();
88 ObjectMapper mapper = new ObjectMapper();
89 JsonNode payloadJson = mapper.readTree(payload);
90 JsonNode requestNode = payloadJson.findValue("configDeploy-request");
91 JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties");
93 assertNotNull(payload);
94 assertTrue(verfiyJsonFromString(payload));
95 assertThat(requestNode.get("resolution-key").asText()).isEqualTo(VF_MODULE_NAME);
96 assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
97 assertThat(propertiesNode.get("vf-module-id").asText()).isEqualTo(VF_MODULE_ID);
98 assertThat(propertiesNode.get("vf-module-name").asText()).isEqualTo(VF_MODULE_NAME);
99 assertThat(propertiesNode.get("vf-module-customization-uuid").asText()).isEqualTo(VF_MODULE_CUSTOMIZATION_UUID);
100 assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
101 assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);
105 public void testRequestPayloadForConfigDeployVfModuleWithoutUserParams() throws Exception {
107 setScopeAndActionWithoutUserParams(VF_SCOPE, DEPLOY_ACTION);
108 ServiceInstance serviceInstance = createServiceInstance();
110 doReturn(serviceInstance).when(extractPojosForBB).extractByKey(buildingBlockExecution,
111 ResourceKey.SERVICE_INSTANCE_ID);
112 doReturn(createGenericVnf()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
113 ResourceKey.GENERIC_VNF_ID);
114 doReturn(createVfModule()).when(extractPojosForBB).extractByKey(buildingBlockExecution,
115 ResourceKey.VF_MODULE_ID);
116 doReturn(getUserParams()).when(extractServiceFromUserParameters).getServiceFromRequestUserParams(anyList());
117 doCallRealMethod().when(configureInstanceParamsForVfModule).populateInstanceParams(any(), any(), anyString(),
120 vfModuleCDSRequestProvider.setExecutionObject(buildingBlockExecution);
121 String payload = vfModuleCDSRequestProvider.buildRequestPayload(DEPLOY_ACTION).get();
124 ObjectMapper mapper = new ObjectMapper();
125 JsonNode payloadJson = mapper.readTree(payload);
126 JsonNode requestNode = payloadJson.findValue("configDeploy-request");
127 JsonNode propertiesNode = payloadJson.findValue("configDeploy-properties");
129 assertNotNull(payload);
130 assertTrue(verfiyJsonFromString(payload));
131 assertThat(requestNode.get("resolution-key").asText()).isEqualTo(VF_MODULE_NAME);
132 assertThat(propertiesNode.get("service-instance-id").asText()).isEqualTo(SERVICE_INSTANCE_ID);
133 assertThat(propertiesNode.get("vf-module-id").asText()).isEqualTo(VF_MODULE_ID);
134 assertThat(propertiesNode.get("vf-module-name").asText()).isEqualTo(VF_MODULE_NAME);
135 assertThat(propertiesNode.get("vf-module-customization-uuid").asText()).isEqualTo(VF_MODULE_CUSTOMIZATION_UUID);
136 assertThat(propertiesNode.get("service-model-uuid").asText()).isEqualTo(SERVICE_MODEL_UUID);
137 assertThat(propertiesNode.get("vnf-id").asText()).isEqualTo(GENERIC_VNF_ID);