2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.sdnc.mapper;
24 import java.net.URISyntaxException;
25 import java.util.HashMap;
26 import java.util.List;
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;
47 @RunWith(MockitoJUnitRunner.Silent.class)
48 public class GCTopologyOperationRequestMapperTest extends TestDataSetup {
52 private GeneralTopologyObjectMapper generalTopologyObjectMapper;
55 private GCTopologyOperationRequestMapper genObjMapper = new GCTopologyOperationRequestMapper();
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 Configuration.setConfigurationType("VLAN-NETWORK-RECEPTOR");
66 GenericResourceApiGcTopologyOperationInformation genericInfo = genObjMapper.deactivateOrUnassignVnrReqMapper
67 (SDNCSvcAction.UNASSIGN, serviceInstance, requestContext, Configuration,"uuid",new URI("http://localhost"));
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());
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;
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;
101 private Map<String, Object> getUserParams() {
102 Map<String,Object> userParams = new HashMap<>();
103 userParams.put("lppCustomerId","lppCustomerId");
107 private ServiceProxy buildServiceProxy(ServiceInstance serviceInstance) {
108 ServiceProxy serviceProxy = new ServiceProxy();
109 serviceProxy.setServiceInstance(serviceInstance);
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;
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;
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);
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);
151 private ServiceInstance buildServiceInstance(GenericVnf vnf) {
152 ServiceInstance serviceInstance = new ServiceInstance();
153 serviceInstance.setServiceInstanceId("ServiceInstanceId");
154 List<GenericVnf> vnfs = serviceInstance.getVnfs();
156 return serviceInstance;