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.tapi.topology;
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;
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.transportpce.common.network.NetworkTransactionService;
27 import org.opendaylight.transportpce.tapi.TapiStringConstants;
28 import org.opendaylight.transportpce.tapi.utils.TapiContext;
29 import org.opendaylight.transportpce.tapi.utils.TapiLink;
30 import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
31 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsInput;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsOutput;
34 import org.opendaylight.yangtools.yang.common.ErrorType;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
37 @ExtendWith(MockitoExtension.class)
38 public class TapiTopologyImplExceptionTest {
40 private NetworkTransactionService networkTransactionService;
42 private TapiContext tapiContext;
44 private TopologyUtils topologyUtils;
46 private TapiLink tapiLink;
49 void getTopologyDetailsWithExceptionTest() throws InterruptedException, ExecutionException {
50 when(networkTransactionService.read(any(), any()))
51 .thenReturn(FluentFuture.from(Futures.immediateFailedFuture(new InterruptedException())));
52 Uuid topologyUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_MULTILAYER.getBytes(
53 Charset.forName("UTF-8"))).toString());
54 GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(topologyUuid);
55 TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(networkTransactionService, tapiContext, topologyUtils,
57 ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
58 assertFalse(result.get().isSuccessful(), "RpcResult is not successful");
59 assertNull(result.get().getResult(), "RpcResult result should be null");
60 assertEquals(ErrorType.RPC, result.get().getErrors().get(0).getErrorType());
61 assertEquals("Error building topology", result.get().getErrors().get(0).getMessage());