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