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.controller.md.sal.binding.api.MountPoint;
23 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
24 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
25 import org.opendaylight.controller.md.sal.common.api.data.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.stub.MountPointServiceStub;
52 import org.opendaylight.transportpce.renderer.stub.MountPointStub;
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.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.rev171017.ServiceDeleteInputBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput;
62 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.service.handler.header.ServiceHandlerHeaderBuilder;
63 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
67 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
68 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
70 public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
72 private static final int NUMBER_OF_THREADS = 4;
73 private DeviceTransactionManager deviceTransactionManager;
74 private RendererServiceOperationsImpl rendererServiceOperations;
75 private OpenRoadmInterfaces openRoadmInterfaces;
76 private DeviceRendererService deviceRenderer;
77 private PortMapping portMapping;
78 private CrossConnect crossConnect;
79 private NetworkModelWavelengthService networkModelWavelengthService;
80 private TransportpceOlmService olmService;
81 private MappingUtils mappingUtils;
82 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
83 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
84 private PortMappingVersion221 portMappingVersion22;
85 private PortMappingVersion121 portMappingVersion121;
86 private CrossConnectImpl121 crossConnectImpl121;
87 private CrossConnectImpl221 crossConnectImpl221;
89 private void setMountPoint(MountPoint mountPoint) {
90 MountPointService mountPointService = new MountPointServiceStub(mountPoint);
91 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
92 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
93 this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
94 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
95 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
96 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221);
97 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
98 this.portMappingVersion22 =
99 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
100 this.portMappingVersion121 =
101 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
102 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22,
103 this.portMappingVersion121);
104 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
105 this.crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
106 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
107 this.crossConnectImpl221);
108 this.crossConnect = Mockito.spy(crossConnect);
109 FixedFlexInterface fixedFlexInterface = new FixedFlexImpl();
110 OpenRoadmInterface121 openRoadmInterface121 = new OpenRoadmInterface121(portMapping,openRoadmInterfaces);
111 OpenRoadmInterface221 openRoadmInterface221 = new OpenRoadmInterface221(portMapping,openRoadmInterfaces,
113 OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.mappingUtils,
114 openRoadmInterface121,openRoadmInterface221);
116 this.deviceRenderer = new DeviceRendererServiceImpl(this.getDataBroker(),
117 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect,
122 public void setUp() {
123 setMountPoint(new MountPointStub(getDataBroker()));
124 this.olmService = new OlmServiceStub();
125 this.olmService = Mockito.spy(this.olmService);
126 ListeningExecutorService executor =
127 MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
128 this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
129 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
130 this.rendererServiceOperations = new RendererServiceOperationsImpl(this.deviceRenderer, olmService,
131 getDataBroker(), this.networkModelWavelengthService, notificationPublishService);
137 public void serviceDeleteOperationPp() throws ExecutionException, InterruptedException {
138 writePathDescription();
139 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
140 serviceDeleteInputBuilder.setServiceName("service 1");
141 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
142 .setRequestId("request1").build());
143 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
144 Mockito.anyString());
145 ServiceDeleteOutput serviceDeleteOutput
146 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get();
147 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
148 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
149 Mockito.verify(this.crossConnect, Mockito.times(2)).deleteCrossConnect(Mockito.any(), Mockito.any());
153 public void serviceDeleteOperationNoDescription() throws InterruptedException, ExecutionException {
154 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
155 serviceDeleteInputBuilder.setServiceName("service 1");
156 ServiceDeleteOutput serviceDeleteOutput
157 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get();
158 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
159 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
160 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.any(), Mockito.any());
164 public void serviceDeleteOperationTearDownFailedAtoZ() throws ExecutionException, InterruptedException {
165 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
166 Mockito.anyString());
167 Mockito.doReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
168 .setResult("Failed").build()).buildFuture()).when(this.olmService).servicePowerTurndown(Mockito.any());
170 writePathDescription();
171 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
172 serviceDeleteInputBuilder.setServiceName("service 1");
173 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
174 .setRequestId("request1").build());
175 ListenableFuture<ServiceDeleteOutput> serviceDeleteOutput
176 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build());
177 ServiceDeleteOutput output = serviceDeleteOutput.get();
178 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
179 output.getConfigurationResponseCommon().getResponseCode());
180 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any());
181 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any());
185 public void serviceDeleteOperationTearDownFailedZtoA() throws ExecutionException, InterruptedException {
186 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
187 Mockito.anyString());
188 Mockito.when(this.olmService.servicePowerTurndown(Mockito.any()))
189 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
190 .setResult("Success").build()).buildFuture())
191 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
192 .setResult("Failed").build()).buildFuture());
194 writePathDescription();
195 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
196 serviceDeleteInputBuilder.setServiceName("service 1");
197 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
198 .setRequestId("request1").build());
199 ServiceDeleteOutput serviceDeleteOutput =
200 this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build()).get();
201 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
202 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
203 Mockito.verify(this.olmService, Mockito.times(2)).servicePowerTurndown(Mockito.any());
204 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any());
205 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any());
208 private void writePathDescription() throws ExecutionException, InterruptedException {
209 ServicePathsBuilder servicePathsBuilder = new ServicePathsBuilder();
210 servicePathsBuilder.setPathDescription(ServiceDeleteDataUtils
211 .createTransactionPathDescription(StringConstants.PP_TOKEN));
212 servicePathsBuilder.setServiceAEnd(ServiceDeleteDataUtils.getServiceAEndBuild().build())
213 .setServiceZEnd(ServiceDeleteDataUtils.getServiceZEndBuild().build());
214 servicePathsBuilder.withKey(new ServicePathsKey("service 1"));
215 servicePathsBuilder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("Request 1")
217 InstanceIdentifier<ServicePaths> servicePathsInstanceIdentifier = InstanceIdentifier.create(
218 ServicePathList.class).child(ServicePaths.class, new ServicePathsKey("service 1"));
219 TransactionUtils.writeTransaction(
220 this.deviceTransactionManager,
221 "node1" + StringConstants.PP_TOKEN,
222 LogicalDatastoreType.OPERATIONAL,
223 servicePathsInstanceIdentifier,
224 servicePathsBuilder.build());