2 * Copyright © 2018 Orange Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.renderer.provisiondevice;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import java.util.Collections;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.Executors;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.mockito.Mockito;
22 import org.opendaylight.mdsal.binding.api.MountPoint;
23 import org.opendaylight.mdsal.binding.api.MountPointService;
24 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.transportpce.common.ResponseCodes;
27 import org.opendaylight.transportpce.common.StringConstants;
28 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
29 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
30 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
31 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
32 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl710;
33 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
34 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
35 import org.opendaylight.transportpce.common.mapping.MappingUtils;
36 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
37 import org.opendaylight.transportpce.common.mapping.PortMapping;
38 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
39 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
40 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
41 import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
42 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
43 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
44 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
45 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
46 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
47 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface121;
48 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface221;
49 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface710;
50 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
51 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmOtnInterface221;
52 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmOtnInterface710;
53 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
54 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
55 import org.opendaylight.transportpce.renderer.utils.ServiceDeleteDataUtils;
56 import org.opendaylight.transportpce.renderer.utils.TransactionUtils;
57 import org.opendaylight.transportpce.test.AbstractTest;
58 import org.opendaylight.transportpce.test.stub.MountPointServiceStub;
59 import org.opendaylight.transportpce.test.stub.MountPointStub;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInputBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEnd;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEndBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.service.handler.header.ServiceHandlerHeaderBuilder;
71 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
72 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
73 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
74 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
75 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
76 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
77 import org.opendaylight.yangtools.yang.common.Uint32;
80 public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
82 private static final int NUMBER_OF_THREADS = 4;
83 private DeviceTransactionManager deviceTransactionManager;
84 private RendererServiceOperationsImpl rendererServiceOperations;
85 private OpenRoadmInterfaces openRoadmInterfaces;
86 private DeviceRendererService deviceRenderer;
87 private PortMapping portMapping;
88 private CrossConnect crossConnect;
89 private TransportpceOlmService olmService;
90 private MappingUtils mappingUtils;
91 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
92 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
93 private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
94 private PortMappingVersion710 portMappingVersion710;
95 private PortMappingVersion221 portMappingVersion22;
96 private PortMappingVersion121 portMappingVersion121;
97 private CrossConnectImpl121 crossConnectImpl121;
98 private CrossConnectImpl221 crossConnectImpl221;
99 private CrossConnectImpl710 crossConnectImpl710;
100 private OtnDeviceRendererService otnDeviceRendererService;
102 private void setMountPoint(MountPoint mountPoint) {
103 MountPointService mountPointService = new MountPointServiceStub(mountPoint);
104 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
105 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
106 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
107 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221, openRoadmInterfacesImpl710);
108 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
109 this.portMappingVersion710 = new PortMappingVersion710(getDataBroker(), deviceTransactionManager);
110 this.portMappingVersion22 = new PortMappingVersion221(getDataBroker(), deviceTransactionManager);
111 this.portMappingVersion121 = new PortMappingVersion121(getDataBroker(), deviceTransactionManager);
112 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710, this.portMappingVersion22,
113 this.portMappingVersion121);
114 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
115 this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping,
116 this.portMappingVersion22);
117 this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager);
118 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
119 this.crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
120 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
121 this.crossConnectImpl221, this.crossConnectImpl710);
122 this.crossConnect = Mockito.spy(crossConnect);
123 OpenRoadmInterface121 openRoadmInterface121 = new OpenRoadmInterface121(portMapping,openRoadmInterfaces);
124 OpenRoadmInterface221 openRoadmInterface221 = new OpenRoadmInterface221(portMapping,openRoadmInterfaces);
125 OpenRoadmInterface710 openRoadmInterface710 = new OpenRoadmInterface710(portMapping,openRoadmInterfaces);
126 OpenRoadmOtnInterface221 openRoadmOTNInterface221 = new OpenRoadmOtnInterface221(portMapping,
127 openRoadmInterfaces);
128 OpenRoadmOtnInterface710 openRoadmOtnInterface710 = new OpenRoadmOtnInterface710(portMapping,
129 openRoadmInterfaces);
130 OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.mappingUtils,
131 openRoadmInterface121, openRoadmInterface221, openRoadmInterface710, openRoadmOTNInterface221,
132 openRoadmOtnInterface710);
134 this.deviceRenderer = new DeviceRendererServiceImpl(getDataBroker(),
135 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect,
136 this.portMapping, null);
138 this.otnDeviceRendererService = new OtnDeviceRendererServiceImpl(openRoadmInterfaceFactory, crossConnect,
139 openRoadmInterfaces, this.deviceTransactionManager, null);
144 public void setUp() {
145 setMountPoint(new MountPointStub(getDataBroker()));
146 this.olmService = new OlmServiceStub();
147 this.olmService = Mockito.spy(this.olmService);
148 ListeningExecutorService executor =
149 MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
150 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
151 this.rendererServiceOperations = new RendererServiceOperationsImpl(this.deviceRenderer,
152 this.otnDeviceRendererService, olmService, getDataBroker(), notificationPublishService, null);
158 public void serviceDeleteOperationPp() throws ExecutionException, InterruptedException {
159 writePathDescription();
160 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
161 serviceDeleteInputBuilder.setServiceName("service 1");
162 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
163 .setRequestId("request1").build());
164 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
165 Mockito.anyString(), Mockito.eq(false));
166 ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
167 .setServiceFormat(ServiceFormat.Ethernet)
168 .setServiceRate(Uint32.valueOf("100"))
170 Services service = new ServicesBuilder()
171 .setConnectionType(ConnectionType.Service)
172 .setServiceAEnd(serviceAEnd)
174 ServiceDeleteOutput serviceDeleteOutput
175 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
176 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
177 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
178 Mockito.verify(this.crossConnect, Mockito.times(2))
179 .deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
183 public void serviceDeleteOperationNoDescription() throws InterruptedException, ExecutionException {
184 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
185 serviceDeleteInputBuilder.setServiceName("service 1");
186 ServiceDeleteOutput serviceDeleteOutput
187 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), null).get();
188 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
189 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
190 Mockito.verify(this.crossConnect, Mockito.times(0))
191 .deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
195 public void serviceDeleteOperationTearDownFailedAtoZ() throws ExecutionException, InterruptedException {
196 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
197 Mockito.anyString(), Mockito.eq(false));
198 Mockito.doReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
199 .setResult("Failed").build()).buildFuture()).when(this.olmService).servicePowerTurndown(Mockito.any());
201 writePathDescription();
202 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
203 serviceDeleteInputBuilder.setServiceName("service 1");
204 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
205 .setRequestId("request1").build());
206 ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
207 .setServiceFormat(ServiceFormat.Ethernet)
208 .setServiceRate(Uint32.valueOf("100"))
210 Services service = new ServicesBuilder()
211 .setConnectionType(ConnectionType.Service)
212 .setServiceAEnd(serviceAEnd)
214 ListenableFuture<ServiceDeleteOutput> serviceDeleteOutput
215 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service);
216 ServiceDeleteOutput output = serviceDeleteOutput.get();
217 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
218 output.getConfigurationResponseCommon().getResponseCode());
219 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
221 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
226 public void serviceDeleteOperationTearDownFailedZtoA() throws ExecutionException, InterruptedException {
227 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
228 Mockito.anyString(), Mockito.eq(false));
229 Mockito.when(this.olmService.servicePowerTurndown(Mockito.any()))
230 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
231 .setResult("Success").build()).buildFuture())
232 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
233 .setResult("Failed").build()).buildFuture());
235 writePathDescription();
236 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
237 serviceDeleteInputBuilder.setServiceName("service 1");
238 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
239 .setRequestId("request1").build());
240 ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
241 .setServiceFormat(ServiceFormat.Ethernet)
242 .setServiceRate(Uint32.valueOf("100"))
244 Services service = new ServicesBuilder()
245 .setConnectionType(ConnectionType.Service)
246 .setServiceAEnd(serviceAEnd)
248 ServiceDeleteOutput serviceDeleteOutput =
249 this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
250 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
251 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
252 Mockito.verify(this.olmService, Mockito.times(2)).servicePowerTurndown(Mockito.any());
253 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
255 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
259 private void writePathDescription() throws ExecutionException, InterruptedException {
260 ServicePathsBuilder servicePathsBuilder = new ServicePathsBuilder();
261 servicePathsBuilder.setPathDescription(ServiceDeleteDataUtils
262 .createTransactionPathDescription(StringConstants.PP_TOKEN));
263 servicePathsBuilder.setServiceAEnd(ServiceDeleteDataUtils.getServiceAEndBuild().build())
264 .setServiceZEnd(ServiceDeleteDataUtils.getServiceZEndBuild().build());
265 servicePathsBuilder.withKey(new ServicePathsKey("service 1"));
266 servicePathsBuilder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("Request 1")
268 InstanceIdentifier<ServicePaths> servicePathsInstanceIdentifier = InstanceIdentifier.create(
269 ServicePathList.class).child(ServicePaths.class, new ServicePathsKey("service 1"));
270 TransactionUtils.writeTransaction(
271 this.deviceTransactionManager,
272 "node1" + StringConstants.PP_TOKEN,
273 LogicalDatastoreType.OPERATIONAL,
274 servicePathsInstanceIdentifier,
275 servicePathsBuilder.build());