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;
30 import java.util.Arrays;
31 import java.util.HashMap;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.MockitoAnnotations;
37 import org.mockito.Spy;
38 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
43 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
44 import org.onap.so.entity.MsoRequest;
46 public class VnfAdapterVfModuleObjectMapperTest {
49 private VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper();
52 public void before() {
53 MockitoAnnotations.initMocks(this);
57 public void createVnfcSubInterfaceKeyTest() {
59 assertEquals("type_0_subint_role_port_0", mapper.createVnfcSubInterfaceKey("type", 0, "role", 0));
63 public void createGlobalVnfcSubInterfaceKeyTest() {
65 assertEquals("type_subint_role_port_0", mapper.createGlobalVnfcSubInterfaceKey("type", "role", 0));
69 public void addPairToMapTest() {
70 Map<String, Object> map = new HashMap<>();
72 mapper.addPairToMap(map, "test", "_key", Arrays.asList("a", "b"));
74 assertEquals("a,b", map.get("test_key"));
76 mapper.addPairToMap(map, "test", "_key2", Arrays.asList());
78 assertThat(map.containsKey("test_key2"), equalTo(false));
80 mapper.addPairToMap(map, "test", "_key3", "myVal");
82 assertEquals("myVal", map.get("test_key3"));
87 public void test_deleteVfModuleNoHeatIdRequestMapper() throws Exception {
88 DeleteVfModuleRequest expectedDeleteVfModuleRequest = new DeleteVfModuleRequest();
90 CloudRegion cloudRegion = new CloudRegion();
91 cloudRegion.setLcpCloudRegionId("lcpCloudRegionId");
92 expectedDeleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
94 cloudRegion.setTenantId("tenantId");
95 expectedDeleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
97 GenericVnf genericVnf = new GenericVnf();
98 VfModule vfModule = new VfModule();
99 vfModule.setHeatStackId("heatStackId");
100 expectedDeleteVfModuleRequest.setVfModuleStackId("heatStackId");
101 expectedDeleteVfModuleRequest.setSkipAAI(true);
103 MsoRequest msoRequest = new MsoRequest();
104 RequestContext requestContext = new RequestContext();
105 requestContext.setMsoRequestId("msoRequestId");
106 msoRequest.setRequestId(requestContext.getMsoRequestId());
107 ServiceInstance serviceInstance = new ServiceInstance();
108 serviceInstance.setServiceInstanceId("serviceInstanceId");
109 msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
110 expectedDeleteVfModuleRequest.setMsoRequest(msoRequest);
112 String messageId = "messageId";
113 String endpoint = "endpoint";
114 doNothing().when(mapper).setIdAndUrl(any());
115 expectedDeleteVfModuleRequest.setMessageId(messageId);
116 expectedDeleteVfModuleRequest.setNotificationUrl(endpoint + "/VNFAResponse/" + messageId);
118 DeleteVfModuleRequest actualDeleteVfModuleRequest = mapper.deleteVfModuleRequestMapper(requestContext, cloudRegion,
119 serviceInstance, genericVnf, vfModule);
121 assertThat(actualDeleteVfModuleRequest, sameBeanAs(expectedDeleteVfModuleRequest).ignoring("messageId").ignoring("notificationUrl"));