Bump upstream dependencies to latest Ca versions
[transportpce.git] / renderer / src / test / java / org / opendaylight / transportpce / renderer / rpcs / DeviceRendererRPCImplTest.java
1 /*
2  * Copyright © 2019 Orange , 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 package org.opendaylight.transportpce.renderer.rpcs;
9
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;
18
19 import com.google.common.collect.ClassToInstanceMap;
20 import com.google.common.util.concurrent.ListenableFuture;
21 import java.util.concurrent.ExecutionException;
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.Test;
24 import org.junit.jupiter.api.extension.ExtendWith;
25 import org.mockito.Mock;
26 import org.mockito.Spy;
27 import org.mockito.junit.jupiter.MockitoExtension;
28 import org.opendaylight.mdsal.binding.api.RpcProviderService;
29 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
30 import org.opendaylight.transportpce.renderer.provisiondevice.DeviceRendererService;
31 import org.opendaylight.transportpce.renderer.provisiondevice.OtnDeviceRendererService;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.Action;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOms;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOmsInput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.CreateOtsOmsOutput;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollback;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackInput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackOutputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePath;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathInput;
41 import org.opendaylight.yangtools.yang.common.RpcResult;
42
43 @ExtendWith(MockitoExtension.class)
44 public class DeviceRendererRPCImplTest {
45     @Mock
46     private DeviceRendererService deviceRendererService;
47     @Mock
48     private RpcProviderService rpcProviderService;
49     @Mock
50     private DeviceRendererService deviceRenderer;
51     @Mock
52     private OtnDeviceRendererService otnDeviceRendererService;
53     @Spy
54     private ServicePathInput servicePathInput;
55     @Mock
56     private CreateOtsOmsInput createOtsOmsInput;
57     @Mock
58     private RendererRollbackInput rendererRollbackInput;
59     private ServicePath servicePath;
60     private RendererRollback rendererRollback;
61     private CreateOtsOms createOtsOms;
62
63     @BeforeEach
64     void setup() {
65         servicePath = new ServicePathImpl(deviceRenderer);
66         rendererRollback = new RendererRollbackImpl(deviceRenderer);
67         createOtsOms = new CreateOtsOmsImpl(deviceRenderer);
68     }
69
70     @Test
71     void testRpcRegistration() {
72         new DeviceRendererRPCImpl(rpcProviderService, deviceRenderer, otnDeviceRendererService);
73         verify(rpcProviderService, times(1)).registerRpcImplementations(any(ClassToInstanceMap.class));
74     }
75
76     @Test
77     void testServicePathCreateOption() {
78         when(servicePathInput.getOperation()).thenReturn(Action.Create);
79         servicePath.invoke(servicePathInput);
80         verify(deviceRenderer, times(1)).setupServicePath(servicePathInput, null);
81     }
82
83     @Test
84     void testServicePathDeleteOption() {
85         when(servicePathInput.getOperation()).thenReturn(Action.Delete);
86         servicePath.invoke(servicePathInput);
87         verify(deviceRenderer, times(1)).deleteServicePath(servicePathInput);
88     }
89
90     @Test
91     void testRendererRollback() {
92         when(deviceRenderer.rendererRollback(rendererRollbackInput))
93             .thenReturn(new RendererRollbackOutputBuilder().build());
94         rendererRollback.invoke(rendererRollbackInput);
95         verify(deviceRenderer, times(1)).rendererRollback(rendererRollbackInput);
96     }
97
98     @Test
99     void testCreateOtsOms() throws OpenRoadmInterfaceException {
100         when(createOtsOmsInput.getNodeId()).thenReturn("nodeId");
101         when(createOtsOmsInput.getLogicalConnectionPoint()).thenReturn("logicalConnectionPoint");
102         when(deviceRenderer.createOtsOms(createOtsOmsInput)).thenReturn(null);
103         createOtsOms.invoke(createOtsOmsInput);
104         verify(deviceRenderer, times(1)).createOtsOms(createOtsOmsInput);
105     }
106
107     @Test
108     void testCreateOtsOmsReturnException()
109             throws OpenRoadmInterfaceException, InterruptedException, ExecutionException {
110         when(createOtsOmsInput.getNodeId()).thenReturn("nodeId");
111         when(createOtsOmsInput.getLogicalConnectionPoint()).thenReturn("logicalConnectionPoint");
112         when(deviceRenderer.createOtsOms(createOtsOmsInput)).thenThrow(OpenRoadmInterfaceException.class);
113         ListenableFuture<RpcResult<CreateOtsOmsOutput>> result = createOtsOms.invoke(createOtsOmsInput);
114         assertTrue(result.isDone());
115         assertFalse(result.get().isSuccessful());
116         assertNull(result.get().getResult());
117         assertEquals("to create oms and ots interfaces", result.get().getErrors().get(0).getMessage());
118     }
119 }