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;
15 import java.util.Collections;
16 import java.util.concurrent.ExecutionException;
17 import java.util.concurrent.Executors;
18 import org.junit.Assert;
19 import org.junit.Before;
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.device.DeviceTransactionManager;
33 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
34 import org.opendaylight.transportpce.common.fixedflex.FixedFlexImpl;
35 import org.opendaylight.transportpce.common.fixedflex.FixedFlexInterface;
36 import org.opendaylight.transportpce.common.mapping.MappingUtils;
37 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
38 import org.opendaylight.transportpce.common.mapping.PortMapping;
39 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
40 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
41 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
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.renderer.NetworkModelWavelengthService;
47 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthServiceImpl;
48 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface121;
49 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface221;
50 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
51 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmOtnInterface221;
52 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
53 import org.opendaylight.transportpce.renderer.stub.MountPointStub;
54 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
55 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
56 import org.opendaylight.transportpce.renderer.utils.ServiceDeleteDataUtils;
57 import org.opendaylight.transportpce.renderer.utils.TransactionUtils;
58 import org.opendaylight.transportpce.test.AbstractTest;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutputBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.TransportpceOlmService;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteInputBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.service.handler.header.ServiceHandlerHeaderBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
68 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
69 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
71 public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
73 private static final int NUMBER_OF_THREADS = 4;
74 private DeviceTransactionManager deviceTransactionManager;
75 private RendererServiceOperationsImpl rendererServiceOperations;
76 private OpenRoadmInterfaces openRoadmInterfaces;
77 private DeviceRendererService deviceRenderer;
78 private PortMapping portMapping;
79 private CrossConnect crossConnect;
80 private NetworkModelWavelengthService networkModelWavelengthService;
81 private TransportpceOlmService olmService;
82 private MappingUtils mappingUtils;
83 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
84 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
85 private PortMappingVersion221 portMappingVersion22;
86 private PortMappingVersion121 portMappingVersion121;
87 private CrossConnectImpl121 crossConnectImpl121;
88 private CrossConnectImpl221 crossConnectImpl221;
90 private void setMountPoint(MountPoint mountPoint) {
91 MountPointService mountPointService = new MountPointServiceStub(mountPoint);
92 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
93 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
94 this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
95 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
96 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
97 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221);
98 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
99 this.portMappingVersion22 =
100 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
101 this.portMappingVersion121 =
102 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
103 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22,
104 this.portMappingVersion121);
105 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
106 this.crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
107 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
108 this.crossConnectImpl221);
109 this.crossConnect = Mockito.spy(crossConnect);
110 FixedFlexInterface fixedFlexInterface = new FixedFlexImpl();
111 OpenRoadmInterface121 openRoadmInterface121 = new OpenRoadmInterface121(portMapping,openRoadmInterfaces);
112 OpenRoadmInterface221 openRoadmInterface221 = new OpenRoadmInterface221(portMapping,openRoadmInterfaces,
114 OpenRoadmOtnInterface221 openRoadmOTNInterface = new OpenRoadmOtnInterface221(portMapping, openRoadmInterfaces);
115 OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.mappingUtils,
116 openRoadmInterface121, openRoadmInterface221, openRoadmOTNInterface);
118 this.deviceRenderer = new DeviceRendererServiceImpl(this.getDataBroker(),
119 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect,
124 public void setUp() {
125 setMountPoint(new MountPointStub(getDataBroker()));
126 this.olmService = new OlmServiceStub();
127 this.olmService = Mockito.spy(this.olmService);
128 ListeningExecutorService executor =
129 MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
130 this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
131 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
132 this.rendererServiceOperations = new RendererServiceOperationsImpl(this.deviceRenderer, olmService,
133 getDataBroker(), this.networkModelWavelengthService, notificationPublishService);
139 public void serviceDeleteOperationPp() throws ExecutionException, InterruptedException {
140 writePathDescription();
141 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
142 serviceDeleteInputBuilder.setServiceName("service 1");
143 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
144 .setRequestId("request1").build());
145 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
146 Mockito.anyString(), Mockito.eq(false));
147 ServiceDeleteOutput serviceDeleteOutput
148 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get();
149 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
150 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
151 Mockito.verify(this.crossConnect, Mockito.times(2)).deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
155 public void serviceDeleteOperationNoDescription() throws InterruptedException, ExecutionException {
156 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
157 serviceDeleteInputBuilder.setServiceName("service 1");
158 ServiceDeleteOutput serviceDeleteOutput
159 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get();
160 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
161 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
162 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
166 public void serviceDeleteOperationTearDownFailedAtoZ() throws ExecutionException, InterruptedException {
167 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
168 Mockito.anyString(), Mockito.eq(false));
169 Mockito.doReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
170 .setResult("Failed").build()).buildFuture()).when(this.olmService).servicePowerTurndown(Mockito.any());
172 writePathDescription();
173 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
174 serviceDeleteInputBuilder.setServiceName("service 1");
175 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
176 .setRequestId("request1").build());
177 ListenableFuture<ServiceDeleteOutput> serviceDeleteOutput
178 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build());
179 ServiceDeleteOutput output = serviceDeleteOutput.get();
180 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
181 output.getConfigurationResponseCommon().getResponseCode());
182 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
184 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
189 public void serviceDeleteOperationTearDownFailedZtoA() throws ExecutionException, InterruptedException {
190 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
191 Mockito.anyString(), Mockito.eq(false));
192 Mockito.when(this.olmService.servicePowerTurndown(Mockito.any()))
193 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
194 .setResult("Success").build()).buildFuture())
195 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
196 .setResult("Failed").build()).buildFuture());
198 writePathDescription();
199 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
200 serviceDeleteInputBuilder.setServiceName("service 1");
201 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
202 .setRequestId("request1").build());
203 ServiceDeleteOutput serviceDeleteOutput =
204 this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get();
205 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
206 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
207 Mockito.verify(this.olmService, Mockito.times(2)).servicePowerTurndown(Mockito.any());
208 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
210 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
214 private void writePathDescription() throws ExecutionException, InterruptedException {
215 ServicePathsBuilder servicePathsBuilder = new ServicePathsBuilder();
216 servicePathsBuilder.setPathDescription(ServiceDeleteDataUtils
217 .createTransactionPathDescription(StringConstants.PP_TOKEN));
218 servicePathsBuilder.setServiceAEnd(ServiceDeleteDataUtils.getServiceAEndBuild().build())
219 .setServiceZEnd(ServiceDeleteDataUtils.getServiceZEndBuild().build());
220 servicePathsBuilder.withKey(new ServicePathsKey("service 1"));
221 servicePathsBuilder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("Request 1")
223 InstanceIdentifier<ServicePaths> servicePathsInstanceIdentifier = InstanceIdentifier.create(
224 ServicePathList.class).child(ServicePaths.class, new ServicePathsKey("service 1"));
225 TransactionUtils.writeTransaction(
226 this.deviceTransactionManager,
227 "node1" + StringConstants.PP_TOKEN,
228 LogicalDatastoreType.OPERATIONAL,
229 servicePathsInstanceIdentifier,
230 servicePathsBuilder.build());