Device Renderer to support transponder for B100G
[transportpce.git] / renderer / src / test / java / org / opendaylight / transportpce / renderer / provisiondevice / RendererServiceOperationsImplDeleteTest.java
1 /*
2  * Copyright © 2018 Orange Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.renderer.provisiondevice;
10
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.device.DeviceTransactionManager;
33 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
34 import org.opendaylight.transportpce.common.mapping.MappingUtils;
35 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
36 import org.opendaylight.transportpce.common.mapping.PortMapping;
37 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
38 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
39 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
40 import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
41 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
42 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
43 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
44 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
45 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
46 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface121;
47 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface221;
48 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface710;
49 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
50 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmOtnInterface221;
51 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
52 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
53 import org.opendaylight.transportpce.renderer.utils.ServiceDeleteDataUtils;
54 import org.opendaylight.transportpce.renderer.utils.TransactionUtils;
55 import org.opendaylight.transportpce.test.AbstractTest;
56 import org.opendaylight.transportpce.test.stub.MountPointServiceStub;
57 import org.opendaylight.transportpce.test.stub.MountPointStub;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutputBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.TransportpceOlmService;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteOutput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEnd;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEndBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
68 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.service.handler.header.ServiceHandlerHeaderBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
70 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
71 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
72 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
73 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
74 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
75 import org.opendaylight.yangtools.yang.common.Uint32;
76
77 @Ignore
78 public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
79
80     private static final int NUMBER_OF_THREADS = 4;
81     private DeviceTransactionManager deviceTransactionManager;
82     private RendererServiceOperationsImpl rendererServiceOperations;
83     private OpenRoadmInterfaces openRoadmInterfaces;
84     private DeviceRendererService deviceRenderer;
85     private PortMapping portMapping;
86     private CrossConnect crossConnect;
87     private TransportpceOlmService olmService;
88     private MappingUtils mappingUtils;
89     private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
90     private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
91     private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
92     private PortMappingVersion710 portMappingVersion710;
93     private PortMappingVersion221 portMappingVersion22;
94     private PortMappingVersion121 portMappingVersion121;
95     private CrossConnectImpl121 crossConnectImpl121;
96     private CrossConnectImpl221 crossConnectImpl221;
97     private OtnDeviceRendererService otnDeviceRendererService;
98
99     private void setMountPoint(MountPoint mountPoint) {
100         MountPointService mountPointService = new MountPointServiceStub(mountPoint);
101         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
102         this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
103         this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
104         this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager);
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 =
110             new PortMappingVersion710(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
111         this.portMappingVersion22 =
112             new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
113         this.portMappingVersion121 =
114             new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
115         this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710, this.portMappingVersion22,
116             this.portMappingVersion121);
117         this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
118         this.crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
119         this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
120             this.crossConnectImpl221);
121         this.crossConnect = Mockito.spy(crossConnect);
122         OpenRoadmInterface121 openRoadmInterface121 = new OpenRoadmInterface121(portMapping,openRoadmInterfaces);
123         OpenRoadmInterface221 openRoadmInterface221 = new OpenRoadmInterface221(portMapping,openRoadmInterfaces);
124         OpenRoadmInterface710 openRoadmInterface710 = new OpenRoadmInterface710(portMapping,openRoadmInterfaces);
125         OpenRoadmOtnInterface221 openRoadmOTNInterface = new OpenRoadmOtnInterface221(portMapping, openRoadmInterfaces);
126         OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.mappingUtils,
127              openRoadmInterface121, openRoadmInterface221, openRoadmInterface710, openRoadmOTNInterface);
128
129         this.deviceRenderer = new DeviceRendererServiceImpl(getDataBroker(),
130             this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect,
131             this.portMapping, null);
132
133         this.otnDeviceRendererService = new OtnDeviceRendererServiceImpl(openRoadmInterfaceFactory, crossConnect,
134             openRoadmInterfaces, this.deviceTransactionManager, null);
135
136     }
137
138     @Before
139     public void setUp() {
140         setMountPoint(new MountPointStub(getDataBroker()));
141         this.olmService = new OlmServiceStub();
142         this.olmService = Mockito.spy(this.olmService);
143         ListeningExecutorService executor =
144             MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
145         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
146         this.rendererServiceOperations =  new RendererServiceOperationsImpl(this.deviceRenderer,
147             this.otnDeviceRendererService, olmService, getDataBroker(), notificationPublishService);
148
149     }
150
151
152     @Test
153     public void serviceDeleteOperationPp() throws ExecutionException, InterruptedException {
154         writePathDescription();
155         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
156         serviceDeleteInputBuilder.setServiceName("service 1");
157         serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
158             .setRequestId("request1").build());
159         Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
160             Mockito.anyString(), Mockito.eq(false));
161         ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
162             .setServiceFormat(ServiceFormat.Ethernet)
163             .setServiceRate(Uint32.valueOf("100"))
164             .build();
165         Services service = new ServicesBuilder()
166             .setConnectionType(ConnectionType.Service)
167             .setServiceAEnd(serviceAEnd)
168             .build();
169         ServiceDeleteOutput serviceDeleteOutput
170                 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
171         Assert.assertEquals(ResponseCodes.RESPONSE_OK,
172             serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
173         Mockito.verify(this.crossConnect, Mockito.times(2))
174                 .deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
175     }
176
177     @Test
178     public void serviceDeleteOperationNoDescription() throws InterruptedException, ExecutionException {
179         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
180         serviceDeleteInputBuilder.setServiceName("service 1");
181         ServiceDeleteOutput serviceDeleteOutput
182                 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), null).get();
183         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
184             serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
185         Mockito.verify(this.crossConnect, Mockito.times(0))
186                 .deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
187     }
188
189     @Test
190     public void serviceDeleteOperationTearDownFailedAtoZ() throws ExecutionException, InterruptedException {
191         Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
192             Mockito.anyString(), Mockito.eq(false));
193         Mockito.doReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
194             .setResult("Failed").build()).buildFuture()).when(this.olmService).servicePowerTurndown(Mockito.any());
195
196         writePathDescription();
197         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
198         serviceDeleteInputBuilder.setServiceName("service 1");
199         serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
200                 .setRequestId("request1").build());
201         ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
202             .setServiceFormat(ServiceFormat.Ethernet)
203             .setServiceRate(Uint32.valueOf("100"))
204             .build();
205         Services service = new ServicesBuilder()
206             .setConnectionType(ConnectionType.Service)
207             .setServiceAEnd(serviceAEnd)
208             .build();
209         ListenableFuture<ServiceDeleteOutput> serviceDeleteOutput
210                 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service);
211         ServiceDeleteOutput output = serviceDeleteOutput.get();
212         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
213                 output.getConfigurationResponseCommon().getResponseCode());
214         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
215             Mockito.eq(false));
216         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
217             Mockito.eq(false));
218     }
219
220     @Test
221     public void serviceDeleteOperationTearDownFailedZtoA() throws ExecutionException, InterruptedException {
222         Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
223             Mockito.anyString(), Mockito.eq(false));
224         Mockito.when(this.olmService.servicePowerTurndown(Mockito.any()))
225             .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
226                 .setResult("Success").build()).buildFuture())
227             .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
228                 .setResult("Failed").build()).buildFuture());
229
230         writePathDescription();
231         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
232         serviceDeleteInputBuilder.setServiceName("service 1");
233         serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
234             .setRequestId("request1").build());
235         ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
236             .setServiceFormat(ServiceFormat.Ethernet)
237             .setServiceRate(Uint32.valueOf("100"))
238             .build();
239         Services service = new ServicesBuilder()
240             .setConnectionType(ConnectionType.Service)
241             .setServiceAEnd(serviceAEnd)
242             .build();
243         ServiceDeleteOutput serviceDeleteOutput =
244                 this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
245         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
246             serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
247         Mockito.verify(this.olmService, Mockito.times(2)).servicePowerTurndown(Mockito.any());
248         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
249             Mockito.eq(false));
250         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
251             Mockito.eq(false));
252     }
253
254     private void writePathDescription() throws ExecutionException, InterruptedException {
255         ServicePathsBuilder servicePathsBuilder = new ServicePathsBuilder();
256         servicePathsBuilder.setPathDescription(ServiceDeleteDataUtils
257             .createTransactionPathDescription(StringConstants.PP_TOKEN));
258         servicePathsBuilder.setServiceAEnd(ServiceDeleteDataUtils.getServiceAEndBuild().build())
259             .setServiceZEnd(ServiceDeleteDataUtils.getServiceZEndBuild().build());
260         servicePathsBuilder.withKey(new ServicePathsKey("service 1"));
261         servicePathsBuilder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("Request 1")
262             .build());
263         InstanceIdentifier<ServicePaths> servicePathsInstanceIdentifier = InstanceIdentifier.create(
264             ServicePathList.class).child(ServicePaths.class, new ServicePathsKey("service 1"));
265         TransactionUtils.writeTransaction(
266             this.deviceTransactionManager,
267             "node1" + StringConstants.PP_TOKEN,
268             LogicalDatastoreType.OPERATIONAL,
269             servicePathsInstanceIdentifier,
270             servicePathsBuilder.build());
271     }
272 }