81d30e33c52dea3ce33243eff40e7775198d1573
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / adapter / vnf / mapper / VnfAdapterVfModuleObjectMapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.client.adapter.vnf.mapper;
22
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
30 import java.util.Arrays;
31 import java.util.HashMap;
32 import java.util.Map;
33
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;
45
46 public class VnfAdapterVfModuleObjectMapperTest {
47
48         @Spy
49         private VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper();
50
51         @Before
52         public void before() {
53                 MockitoAnnotations.initMocks(this);
54         }
55         
56         @Test
57         public void createVnfcSubInterfaceKeyTest() {
58                 
59                 assertEquals("type_0_subint_role_port_0", mapper.createVnfcSubInterfaceKey("type", 0, "role", 0));
60         }
61         
62         @Test
63         public void createGlobalVnfcSubInterfaceKeyTest() {
64                 
65                 assertEquals("type_subint_role_port_0", mapper.createGlobalVnfcSubInterfaceKey("type", "role", 0));
66         }
67         
68         @Test
69         public void addPairToMapTest() {
70                 Map<String, Object> map = new HashMap<>();
71                 
72                 mapper.addPairToMap(map, "test", "_key", Arrays.asList("a", "b"));
73                 
74                 assertEquals("a,b", map.get("test_key"));
75                 
76                 mapper.addPairToMap(map, "test", "_key2", Arrays.asList());
77                 
78                 assertThat(map.containsKey("test_key2"), equalTo(false));
79                 
80                 mapper.addPairToMap(map, "test", "_key3", "myVal");
81                 
82                 assertEquals("myVal", map.get("test_key3"));
83                 
84         }
85         
86         @Test
87         public void test_deleteVfModuleNoHeatIdRequestMapper() throws Exception {
88                 DeleteVfModuleRequest expectedDeleteVfModuleRequest = new DeleteVfModuleRequest();
89                 
90                 CloudRegion cloudRegion = new CloudRegion();
91                 cloudRegion.setLcpCloudRegionId("lcpCloudRegionId");
92                 expectedDeleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
93                 
94                 cloudRegion.setTenantId("tenantId");
95                 expectedDeleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
96                 
97                 GenericVnf genericVnf = new GenericVnf();
98                 VfModule vfModule = new VfModule();
99                 vfModule.setHeatStackId("heatStackId");
100                 expectedDeleteVfModuleRequest.setVfModuleStackId("heatStackId");
101                 expectedDeleteVfModuleRequest.setSkipAAI(true);
102                 
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);
111                 
112                 String messageId = "messageId";
113                 String endpoint = "endpoint";
114                 doNothing().when(mapper).setIdAndUrl(any());
115                 expectedDeleteVfModuleRequest.setMessageId(messageId);
116                 expectedDeleteVfModuleRequest.setNotificationUrl(endpoint + "/VNFAResponse/" + messageId);
117                 
118                 DeleteVfModuleRequest actualDeleteVfModuleRequest = mapper.deleteVfModuleRequestMapper(requestContext, cloudRegion, 
119                                 serviceInstance, genericVnf, vfModule);
120                 
121                 assertThat(actualDeleteVfModuleRequest, sameBeanAs(expectedDeleteVfModuleRequest).ignoring("messageId").ignoring("notificationUrl"));
122         }
123         
124 }