2 * Copyright © 2019 Orange , 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
8 package org.opendaylight.transportpce.renderer.rpcs;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.jupiter.api.Assertions.assertEquals;
13 import static org.junit.jupiter.api.Assertions.assertNull;
14 import static org.mockito.ArgumentMatchers.any;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
17 import static org.mockito.Mockito.when;
19 import com.google.common.util.concurrent.ListenableFuture;
20 import java.util.concurrent.ExecutionException;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 import org.junit.jupiter.api.extension.ExtendWith;
24 import org.mockito.Mock;
25 import org.mockito.Spy;
26 import org.mockito.junit.jupiter.MockitoExtension;
27 import org.opendaylight.mdsal.binding.api.RpcProviderService;
28 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
29 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
30 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.Action;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOms;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOmsInput;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOmsOutput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollback;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackInput;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackOutputBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePath;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
40 import org.opendaylight.yangtools.yang.common.RpcResult;
42 @ExtendWith(MockitoExtension.class)
43 public class DeviceRendererRPCImplTest {
45 private DeviceRendererService deviceRendererService;
47 private RpcProviderService rpcProviderService;
49 private DeviceRendererService deviceRenderer;
51 private OtnDeviceRendererService otnDeviceRendererService;
53 private ServicePathInput servicePathInput;
55 private CreateOtsOmsInput createOtsOmsInput;
57 private RendererRollbackInput rendererRollbackInput;
58 private ServicePath servicePath;
59 private RendererRollback rendererRollback;
60 private CreateOtsOms createOtsOms;
64 servicePath = new ServicePathImpl(deviceRenderer);
65 rendererRollback = new RendererRollbackImpl(deviceRenderer);
66 createOtsOms = new CreateOtsOmsImpl(deviceRenderer);
70 void testRpcRegistration() {
71 new DeviceRendererRPCImpl(rpcProviderService, deviceRenderer, otnDeviceRendererService);
72 verify(rpcProviderService, times(1)).registerRpcImplementations(any());
76 void testServicePathCreateOption() {
77 when(servicePathInput.getOperation()).thenReturn(Action.Create);
78 servicePath.invoke(servicePathInput);
79 verify(deviceRenderer, times(1)).setupServicePath(servicePathInput, null);
83 void testServicePathDeleteOption() {
84 when(servicePathInput.getOperation()).thenReturn(Action.Delete);
85 servicePath.invoke(servicePathInput);
86 verify(deviceRenderer, times(1)).deleteServicePath(servicePathInput);
90 void testRendererRollback() {
91 when(deviceRenderer.rendererRollback(rendererRollbackInput))
92 .thenReturn(new RendererRollbackOutputBuilder().build());
93 rendererRollback.invoke(rendererRollbackInput);
94 verify(deviceRenderer, times(1)).rendererRollback(rendererRollbackInput);
98 void testCreateOtsOms() throws OpenRoadmInterfaceException {
99 when(createOtsOmsInput.getNodeId()).thenReturn("nodeId");
100 when(createOtsOmsInput.getLogicalConnectionPoint()).thenReturn("logicalConnectionPoint");
101 when(deviceRenderer.createOtsOms(createOtsOmsInput)).thenReturn(null);
102 createOtsOms.invoke(createOtsOmsInput);
103 verify(deviceRenderer, times(1)).createOtsOms(createOtsOmsInput);
107 void testCreateOtsOmsReturnException()
108 throws OpenRoadmInterfaceException, InterruptedException, ExecutionException {
109 when(createOtsOmsInput.getNodeId()).thenReturn("nodeId");
110 when(createOtsOmsInput.getLogicalConnectionPoint()).thenReturn("logicalConnectionPoint");
111 when(deviceRenderer.createOtsOms(createOtsOmsInput)).thenThrow(OpenRoadmInterfaceException.class);
112 ListenableFuture<RpcResult<CreateOtsOmsOutput>> result = createOtsOms.invoke(createOtsOmsInput);
113 assertTrue(result.isDone());
114 assertFalse(result.get().isSuccessful());
115 assertNull(result.get().getResult());
116 assertEquals("to create oms and ots interfaces", result.get().getErrors().get(0).getMessage());