Device renderer for muxponder
[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.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.rev170418.ServicePowerTurndownOutputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.TransportpceOlmService;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInputBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.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;
78
79 @Ignore
80 public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
81
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;
101
102     private void setMountPoint(MountPoint mountPoint) {
103         MountPointService mountPointService = new MountPointServiceStub(mountPoint);
104         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
105         this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
106         this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
107         this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager);
108         this.mappingUtils = new MappingUtilsImpl(getDataBroker());
109         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
110             openRoadmInterfacesImpl121, openRoadmInterfacesImpl221, openRoadmInterfacesImpl710);
111         this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
112         this.portMappingVersion710 =
113             new PortMappingVersion710(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
114         this.portMappingVersion22 =
115             new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
116         this.portMappingVersion121 =
117             new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
118         this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710, this.portMappingVersion22,
119             this.portMappingVersion121);
120         this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
121         this.crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
122         this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
123             this.crossConnectImpl221, this.crossConnectImpl710);
124         this.crossConnect = Mockito.spy(crossConnect);
125         OpenRoadmInterface121 openRoadmInterface121 = new OpenRoadmInterface121(portMapping,openRoadmInterfaces);
126         OpenRoadmInterface221 openRoadmInterface221 = new OpenRoadmInterface221(portMapping,openRoadmInterfaces);
127         OpenRoadmInterface710 openRoadmInterface710 = new OpenRoadmInterface710(portMapping,openRoadmInterfaces);
128         OpenRoadmOtnInterface221 openRoadmOTNInterface221 = new OpenRoadmOtnInterface221(portMapping,
129             openRoadmInterfaces);
130         OpenRoadmOtnInterface710 openRoadmOtnInterface710 = new OpenRoadmOtnInterface710(portMapping,
131             openRoadmInterfaces);
132         OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.mappingUtils,
133             openRoadmInterface121, openRoadmInterface221, openRoadmInterface710, openRoadmOTNInterface221,
134             openRoadmOtnInterface710);
135
136         this.deviceRenderer = new DeviceRendererServiceImpl(getDataBroker(),
137             this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect,
138             this.portMapping, null);
139
140         this.otnDeviceRendererService = new OtnDeviceRendererServiceImpl(openRoadmInterfaceFactory, crossConnect,
141             openRoadmInterfaces, this.deviceTransactionManager, null);
142
143     }
144
145     @Before
146     public void setUp() {
147         setMountPoint(new MountPointStub(getDataBroker()));
148         this.olmService = new OlmServiceStub();
149         this.olmService = Mockito.spy(this.olmService);
150         ListeningExecutorService executor =
151             MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
152         NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
153         this.rendererServiceOperations =  new RendererServiceOperationsImpl(this.deviceRenderer,
154             this.otnDeviceRendererService, olmService, getDataBroker(), notificationPublishService);
155
156     }
157
158
159     @Test
160     public void serviceDeleteOperationPp() throws ExecutionException, InterruptedException {
161         writePathDescription();
162         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
163         serviceDeleteInputBuilder.setServiceName("service 1");
164         serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
165             .setRequestId("request1").build());
166         Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
167             Mockito.anyString(), Mockito.eq(false));
168         ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
169             .setServiceFormat(ServiceFormat.Ethernet)
170             .setServiceRate(Uint32.valueOf("100"))
171             .build();
172         Services service = new ServicesBuilder()
173             .setConnectionType(ConnectionType.Service)
174             .setServiceAEnd(serviceAEnd)
175             .build();
176         ServiceDeleteOutput serviceDeleteOutput
177                 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
178         Assert.assertEquals(ResponseCodes.RESPONSE_OK,
179             serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
180         Mockito.verify(this.crossConnect, Mockito.times(2))
181                 .deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
182     }
183
184     @Test
185     public void serviceDeleteOperationNoDescription() throws InterruptedException, ExecutionException {
186         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
187         serviceDeleteInputBuilder.setServiceName("service 1");
188         ServiceDeleteOutput serviceDeleteOutput
189                 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), null).get();
190         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
191             serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
192         Mockito.verify(this.crossConnect, Mockito.times(0))
193                 .deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
194     }
195
196     @Test
197     public void serviceDeleteOperationTearDownFailedAtoZ() throws ExecutionException, InterruptedException {
198         Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
199             Mockito.anyString(), Mockito.eq(false));
200         Mockito.doReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
201             .setResult("Failed").build()).buildFuture()).when(this.olmService).servicePowerTurndown(Mockito.any());
202
203         writePathDescription();
204         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
205         serviceDeleteInputBuilder.setServiceName("service 1");
206         serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
207                 .setRequestId("request1").build());
208         ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
209             .setServiceFormat(ServiceFormat.Ethernet)
210             .setServiceRate(Uint32.valueOf("100"))
211             .build();
212         Services service = new ServicesBuilder()
213             .setConnectionType(ConnectionType.Service)
214             .setServiceAEnd(serviceAEnd)
215             .build();
216         ListenableFuture<ServiceDeleteOutput> serviceDeleteOutput
217                 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service);
218         ServiceDeleteOutput output = serviceDeleteOutput.get();
219         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
220                 output.getConfigurationResponseCommon().getResponseCode());
221         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
222             Mockito.eq(false));
223         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
224             Mockito.eq(false));
225     }
226
227     @Test
228     public void serviceDeleteOperationTearDownFailedZtoA() throws ExecutionException, InterruptedException {
229         Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
230             Mockito.anyString(), Mockito.eq(false));
231         Mockito.when(this.olmService.servicePowerTurndown(Mockito.any()))
232             .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
233                 .setResult("Success").build()).buildFuture())
234             .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
235                 .setResult("Failed").build()).buildFuture());
236
237         writePathDescription();
238         ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
239         serviceDeleteInputBuilder.setServiceName("service 1");
240         serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
241             .setRequestId("request1").build());
242         ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
243             .setServiceFormat(ServiceFormat.Ethernet)
244             .setServiceRate(Uint32.valueOf("100"))
245             .build();
246         Services service = new ServicesBuilder()
247             .setConnectionType(ConnectionType.Service)
248             .setServiceAEnd(serviceAEnd)
249             .build();
250         ServiceDeleteOutput serviceDeleteOutput =
251                 this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
252         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
253             serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
254         Mockito.verify(this.olmService, Mockito.times(2)).servicePowerTurndown(Mockito.any());
255         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
256             Mockito.eq(false));
257         Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
258             Mockito.eq(false));
259     }
260
261     private void writePathDescription() throws ExecutionException, InterruptedException {
262         ServicePathsBuilder servicePathsBuilder = new ServicePathsBuilder();
263         servicePathsBuilder.setPathDescription(ServiceDeleteDataUtils
264             .createTransactionPathDescription(StringConstants.PP_TOKEN));
265         servicePathsBuilder.setServiceAEnd(ServiceDeleteDataUtils.getServiceAEndBuild().build())
266             .setServiceZEnd(ServiceDeleteDataUtils.getServiceZEndBuild().build());
267         servicePathsBuilder.withKey(new ServicePathsKey("service 1"));
268         servicePathsBuilder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("Request 1")
269             .build());
270         InstanceIdentifier<ServicePaths> servicePathsInstanceIdentifier = InstanceIdentifier.create(
271             ServicePathList.class).child(ServicePaths.class, new ServicePathsKey("service 1"));
272         TransactionUtils.writeTransaction(
273             this.deviceTransactionManager,
274             "node1" + StringConstants.PP_TOKEN,
275             LogicalDatastoreType.OPERATIONAL,
276             servicePathsInstanceIdentifier,
277             servicePathsBuilder.build());
278     }
279 }