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