Bump upstream dependencies to Ca
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / topology / TapiTopologyImplExceptionTest.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.tapi.topology;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
12 import static org.junit.jupiter.api.Assertions.assertNull;
13 import static org.mockito.ArgumentMatchers.any;
14 import static org.mockito.Mockito.when;
15
16 import com.google.common.util.concurrent.FluentFuture;
17 import com.google.common.util.concurrent.Futures;
18 import com.google.common.util.concurrent.ListenableFuture;
19 import java.nio.charset.Charset;
20 import java.util.UUID;
21 import java.util.concurrent.ExecutionException;
22 import org.junit.jupiter.api.Test;
23 import org.junit.jupiter.api.extension.ExtendWith;
24 import org.mockito.Mock;
25 import org.mockito.junit.jupiter.MockitoExtension;
26 import org.opendaylight.mdsal.binding.api.RpcService;
27 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
28 import org.opendaylight.transportpce.tapi.TapiStringConstants;
29 import org.opendaylight.transportpce.tapi.impl.rpc.GetTopologyDetailsImpl;
30 import org.opendaylight.transportpce.tapi.utils.TapiContext;
31 import org.opendaylight.transportpce.tapi.utils.TapiLink;
32 import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetails;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsInput;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsOutput;
37 import org.opendaylight.yangtools.yang.common.ErrorType;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39
40 @ExtendWith(MockitoExtension.class)
41 public class TapiTopologyImplExceptionTest {
42     @Mock
43     private RpcService rpcService;
44     @Mock
45     private NetworkTransactionService networkTransactionService;
46     @Mock
47     private TapiContext tapiContext;
48     @Mock
49     private TopologyUtils topologyUtils;
50     @Mock
51     private TapiLink tapiLink;
52
53     @Test
54     void getTopologyDetailsWithExceptionTest() throws InterruptedException, ExecutionException {
55         when(networkTransactionService.read(any(), any()))
56             .thenReturn(FluentFuture.from(Futures.immediateFailedFuture(new InterruptedException())));
57         when(rpcService.getRpc(GetTopologyDetails.class))
58             .thenReturn(new GetTopologyDetailsImpl(tapiContext, topologyUtils, tapiLink, networkTransactionService));
59         Uuid topologyUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_MULTILAYER.getBytes(
60             Charset.forName("UTF-8"))).toString());
61         GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(topologyUuid);
62         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = rpcService
63                 .getRpc(GetTopologyDetails.class).invoke(input);
64         assertFalse(result.get().isSuccessful(), "RpcResult is not successful");
65         assertNull(result.get().getResult(), "RpcResult result should be null");
66         assertEquals(ErrorType.RPC, result.get().getErrors().get(0).getErrorType());
67         assertEquals("Error building topology", result.get().getErrors().get(0).getMessage());
68     }
69 }