Merge "removed qualifiers that no longer exist"
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdnc / mapper / GCTopologyOperationRequestMapperTest.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.sdnc.mapper;
22
23 import java.net.URI;
24 import java.net.URISyntaxException;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Spy;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.sdnc.northbound.client.model.GenericResourceApiGcTopologyOperationInformation;
36 import org.onap.so.bpmn.common.data.TestDataSetup;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink;
44 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
45 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
46
47 @RunWith(MockitoJUnitRunner.Silent.class)
48 public class GCTopologyOperationRequestMapperTest extends TestDataSetup {
49
50         
51         @Spy
52         private GeneralTopologyObjectMapper generalTopologyObjectMapper;
53         
54         @InjectMocks
55     private GCTopologyOperationRequestMapper genObjMapper = new GCTopologyOperationRequestMapper();
56
57     @Test
58     public void deactivateOrUnassignVnrReqMapperTest() throws URISyntaxException {
59         RequestContext requestContext = new RequestContext();
60         requestContext.setMsoRequestId("MsoRequestId");
61         ServiceInstance serviceInstance = new ServiceInstance();
62         serviceInstance.setServiceInstanceId("ServiceInstanceId");
63         Configuration Configuration = new Configuration();
64         Configuration.setConfigurationId("ConfigurationId");
65         GenericResourceApiGcTopologyOperationInformation genericInfo = genObjMapper.deactivateOrUnassignVnrReqMapper
66                 (SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, Configuration,"uuid",new URI("http://localhost"));
67
68         Assert.assertNotNull(genericInfo);
69         Assert.assertNotNull(genericInfo.getRequestInformation());
70         Assert.assertNotNull(genericInfo.getSdncRequestHeader());
71         Assert.assertNotNull(genericInfo.getClass());
72         Assert.assertNotNull(genericInfo.getServiceInformation());
73         Assert.assertEquals("uuid",genericInfo.getSdncRequestHeader().getSvcRequestId()); 
74         Assert.assertEquals("http://localhost",genericInfo.getSdncRequestHeader().getSvcNotificationUrl());
75     }
76
77
78
79     private VpnBondingLink getVpnBondingLink() {
80         VpnBondingLink vpnBondingLink = new VpnBondingLink();
81         Configuration vrfConfiguration = getVRFConfiguration();
82         vpnBondingLink.setVrfConfiguration(vrfConfiguration);
83         Configuration vnrConfiguration = getVNRConfiguration();
84         vpnBondingLink.setVnrConfiguration(vnrConfiguration);
85         vpnBondingLink.setTransportServiceProxy(buildServiceProxy(buildServiceInstance(buildGenericVnf())));
86         return vpnBondingLink;
87     }
88
89     private RequestContext getRequestContext() {
90         RequestContext requestContext = new RequestContext();
91         requestContext.setMsoRequestId("MsoRequestId");
92         Map<String, Object> userParams = getUserParams();
93         requestContext.setUserParams(userParams);
94         return requestContext;
95     }
96
97     private Map<String, Object> getUserParams() {
98         Map<String,Object> userParams = new HashMap<>();
99         userParams.put("lppCustomerId","lppCustomerId");
100         return userParams;
101     }
102
103     private ServiceProxy buildServiceProxy(ServiceInstance serviceInstance) {
104         ServiceProxy serviceProxy = new ServiceProxy();
105         serviceProxy.setServiceInstance(serviceInstance);
106         return serviceProxy;
107     }
108
109     private Configuration getVRFConfiguration() {
110         Configuration vrfConfiguration = new Configuration();
111         vrfConfiguration.setConfigurationId("ConfigurationId");
112         vrfConfiguration.setConfigurationName("ConfigurationName");
113         vrfConfiguration.setConfigurationSubType("ConfigurationSubType");
114         vrfConfiguration.setConfigurationType("VRF-ENTRY");
115         return vrfConfiguration;
116     }
117
118     public Configuration getVNRConfiguration() {
119         Configuration vnrConfiguration = new Configuration();
120         vnrConfiguration.setConfigurationId("ConfigurationId");
121         vnrConfiguration.setConfigurationName("ConfigurationName");
122         vnrConfiguration.setConfigurationSubType("ConfigurationSubType");
123         vnrConfiguration.setConfigurationType("VNRConfiguration");
124         L3Network l3Network = getL3Network();
125         vnrConfiguration.setNetwork(l3Network);
126         return vnrConfiguration;
127     }
128
129     public L3Network getL3Network() {
130         L3Network l3Network = new L3Network();
131         l3Network.setNetworkId("l3NetworkId");
132         Subnet ipv4subnet = getSubnet("ipv4CidrMask", "ipv4NetworkStartAddress", "IPV4");
133         Subnet ipv6subnet = getSubnet("ipv6CidrMask", "ipv6NetworkStartAddress", "IPV6");
134         l3Network.getSubnets().add(ipv4subnet);
135         l3Network.getSubnets().add(ipv6subnet);
136         return l3Network;
137     }
138
139     private Subnet getSubnet(String ipv4CidrMask, String ipv4NetworkStartAddress, String ipv4) {
140         Subnet ipv4subnet = new Subnet();
141         ipv4subnet.setCidrMask(ipv4CidrMask);
142         ipv4subnet.setNetworkStartAddress(ipv4NetworkStartAddress);
143         ipv4subnet.setIpVersion(ipv4);
144         return ipv4subnet;
145     }
146
147     private ServiceInstance  buildServiceInstance(GenericVnf vnf) {
148         ServiceInstance serviceInstance = new ServiceInstance();
149         serviceInstance.setServiceInstanceId("ServiceInstanceId");
150         List<GenericVnf> vnfs = serviceInstance.getVnfs();
151         vnfs.add(vnf);
152         return serviceInstance;
153     }
154 }