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