2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
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.adapter.vnf.mapper;
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.hamcrest.CoreMatchers.equalTo;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertThat;
27 import static org.mockito.ArgumentMatchers.any;
28 import static org.mockito.Mockito.doNothing;
29 import java.util.Arrays;
30 import java.util.HashMap;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.MockitoAnnotations;
35 import org.mockito.Spy;
36 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
41 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
42 import org.onap.so.entity.MsoRequest;
44 public class VnfAdapterVfModuleObjectMapperTest {
47 private VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper();
50 public void before() {
51 MockitoAnnotations.initMocks(this);
55 public void createVnfcSubInterfaceKeyTest() {
57 assertEquals("type_0_subint_role_port_0", mapper.createVnfcSubInterfaceKey("type", 0, "role", 0));
61 public void createGlobalVnfcSubInterfaceKeyTest() {
63 assertEquals("type_subint_role_port_0", mapper.createGlobalVnfcSubInterfaceKey("type", "role", 0));
67 public void addPairToMapTest() {
68 Map<String, Object> map = new HashMap<>();
70 mapper.addPairToMap(map, "test", "_key", Arrays.asList("a", "b"));
72 assertEquals("a,b", map.get("test_key"));
74 mapper.addPairToMap(map, "test", "_key2", Arrays.asList());
76 assertThat(map.containsKey("test_key2"), equalTo(false));
78 mapper.addPairToMap(map, "test", "_key3", "myVal");
80 assertEquals("myVal", map.get("test_key3"));
85 public void test_deleteVfModuleNoHeatIdRequestMapper() throws Exception {
86 DeleteVfModuleRequest expectedDeleteVfModuleRequest = new DeleteVfModuleRequest();
88 CloudRegion cloudRegion = new CloudRegion();
89 cloudRegion.setLcpCloudRegionId("lcpCloudRegionId");
90 expectedDeleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
92 cloudRegion.setTenantId("tenantId");
93 expectedDeleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
95 GenericVnf genericVnf = new GenericVnf();
96 VfModule vfModule = new VfModule();
97 vfModule.setHeatStackId("heatStackId");
98 expectedDeleteVfModuleRequest.setVfModuleStackId("heatStackId");
99 expectedDeleteVfModuleRequest.setSkipAAI(true);
101 MsoRequest msoRequest = new MsoRequest();
102 RequestContext requestContext = new RequestContext();
103 requestContext.setMsoRequestId("msoRequestId");
104 msoRequest.setRequestId(requestContext.getMsoRequestId());
105 ServiceInstance serviceInstance = new ServiceInstance();
106 serviceInstance.setServiceInstanceId("serviceInstanceId");
107 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
108 expectedDeleteVfModuleRequest.setMsoRequest(msoRequest);
110 String messageId = "messageId";
111 String endpoint = "endpoint";
112 doNothing().when(mapper).setIdAndUrl(any());
113 expectedDeleteVfModuleRequest.setMessageId(messageId);
114 expectedDeleteVfModuleRequest.setNotificationUrl(endpoint + "/VNFAResponse/" + messageId);
116 DeleteVfModuleRequest actualDeleteVfModuleRequest =
117 mapper.deleteVfModuleRequestMapper(requestContext, cloudRegion, serviceInstance, genericVnf, vfModule);
119 assertThat(actualDeleteVfModuleRequest,
120 sameBeanAs(expectedDeleteVfModuleRequest).ignoring("messageId").ignoring("notificationUrl"));