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