Replaced all tabs with spaces in java and pom.xml
[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 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.Map;
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;
43
44 public class VnfAdapterVfModuleObjectMapperTest {
45
46     @Spy
47     private VnfAdapterVfModuleObjectMapper mapper = new VnfAdapterVfModuleObjectMapper();
48
49     @Before
50     public void before() {
51         MockitoAnnotations.initMocks(this);
52     }
53
54     @Test
55     public void createVnfcSubInterfaceKeyTest() {
56
57         assertEquals("type_0_subint_role_port_0", mapper.createVnfcSubInterfaceKey("type", 0, "role", 0));
58     }
59
60     @Test
61     public void createGlobalVnfcSubInterfaceKeyTest() {
62
63         assertEquals("type_subint_role_port_0", mapper.createGlobalVnfcSubInterfaceKey("type", "role", 0));
64     }
65
66     @Test
67     public void addPairToMapTest() {
68         Map<String, Object> map = new HashMap<>();
69
70         mapper.addPairToMap(map, "test", "_key", Arrays.asList("a", "b"));
71
72         assertEquals("a,b", map.get("test_key"));
73
74         mapper.addPairToMap(map, "test", "_key2", Arrays.asList());
75
76         assertThat(map.containsKey("test_key2"), equalTo(false));
77
78         mapper.addPairToMap(map, "test", "_key3", "myVal");
79
80         assertEquals("myVal", map.get("test_key3"));
81
82     }
83
84     @Test
85     public void test_deleteVfModuleNoHeatIdRequestMapper() throws Exception {
86         DeleteVfModuleRequest expectedDeleteVfModuleRequest = new DeleteVfModuleRequest();
87
88         CloudRegion cloudRegion = new CloudRegion();
89         cloudRegion.setLcpCloudRegionId("lcpCloudRegionId");
90         expectedDeleteVfModuleRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
91
92         cloudRegion.setTenantId("tenantId");
93         expectedDeleteVfModuleRequest.setTenantId(cloudRegion.getTenantId());
94
95         GenericVnf genericVnf = new GenericVnf();
96         VfModule vfModule = new VfModule();
97         vfModule.setHeatStackId("heatStackId");
98         expectedDeleteVfModuleRequest.setVfModuleStackId("heatStackId");
99         expectedDeleteVfModuleRequest.setSkipAAI(true);
100
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);
109
110         String messageId = "messageId";
111         String endpoint = "endpoint";
112         doNothing().when(mapper).setIdAndUrl(any());
113         expectedDeleteVfModuleRequest.setMessageId(messageId);
114         expectedDeleteVfModuleRequest.setNotificationUrl(endpoint + "/VNFAResponse/" + messageId);
115
116         DeleteVfModuleRequest actualDeleteVfModuleRequest =
117                 mapper.deleteVfModuleRequestMapper(requestContext, cloudRegion, serviceInstance, genericVnf, vfModule);
118
119         assertThat(actualDeleteVfModuleRequest,
120                 sameBeanAs(expectedDeleteVfModuleRequest).ignoring("messageId").ignoring("notificationUrl"));
121     }
122
123 }