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());
82 private VpnBondingLink getVpnBondingLink() {
83 VpnBondingLink vpnBondingLink = new VpnBondingLink();
84 Configuration vrfConfiguration = getVRFConfiguration();
85 vpnBondingLink.setVrfConfiguration(vrfConfiguration);
86 Configuration vnrConfiguration = getVNRConfiguration();
87 vpnBondingLink.setVnrConfiguration(vnrConfiguration);
88 vpnBondingLink.setTransportServiceProxy(buildServiceProxy(buildServiceInstance(buildGenericVnf())));
89 return vpnBondingLink;
92 private RequestContext getRequestContext() {
93 RequestContext requestContext = new RequestContext();
94 requestContext.setMsoRequestId("MsoRequestId");
95 Map<String, Object> userParams = getUserParams();
96 requestContext.setUserParams(userParams);
97 return requestContext;
100 private Map<String, Object> getUserParams() {
101 Map<String,Object> userParams = new HashMap<>();
102 userParams.put("lppCustomerId","lppCustomerId");
106 private ServiceProxy buildServiceProxy(ServiceInstance serviceInstance) {
107 ServiceProxy serviceProxy = new ServiceProxy();
108 serviceProxy.setServiceInstance(serviceInstance);
112 private Configuration getVRFConfiguration() {
113 Configuration vrfConfiguration = new Configuration();
114 vrfConfiguration.setConfigurationId("ConfigurationId");
115 vrfConfiguration.setConfigurationName("ConfigurationName");
116 vrfConfiguration.setConfigurationSubType("ConfigurationSubType");
117 vrfConfiguration.setConfigurationType("VRF-ENTRY");
118 return vrfConfiguration;
121 public Configuration getVNRConfiguration() {
122 Configuration vnrConfiguration = new Configuration();
123 vnrConfiguration.setConfigurationId("ConfigurationId");
124 vnrConfiguration.setConfigurationName("ConfigurationName");
125 vnrConfiguration.setConfigurationSubType("ConfigurationSubType");
126 vnrConfiguration.setConfigurationType("VNRConfiguration");
127 L3Network l3Network = getL3Network();
128 vnrConfiguration.setNetwork(l3Network);
129 return vnrConfiguration;
132 public L3Network getL3Network() {
133 L3Network l3Network = new L3Network();
134 l3Network.setNetworkId("l3NetworkId");
135 Subnet ipv4subnet = getSubnet("ipv4CidrMask", "ipv4NetworkStartAddress", "IPV4");
136 Subnet ipv6subnet = getSubnet("ipv6CidrMask", "ipv6NetworkStartAddress", "IPV6");
137 l3Network.getSubnets().add(ipv4subnet);
138 l3Network.getSubnets().add(ipv6subnet);
142 private Subnet getSubnet(String ipv4CidrMask, String ipv4NetworkStartAddress, String ipv4) {
143 Subnet ipv4subnet = new Subnet();
144 ipv4subnet.setCidrMask(ipv4CidrMask);
145 ipv4subnet.setNetworkStartAddress(ipv4NetworkStartAddress);
146 ipv4subnet.setIpVersion(ipv4);
150 private ServiceInstance buildServiceInstance(GenericVnf vnf) {
151 ServiceInstance serviceInstance = new ServiceInstance();
152 serviceInstance.setServiceInstanceId("ServiceInstanceId");
153 List<GenericVnf> vnfs = serviceInstance.getVnfs();
155 return serviceInstance;