551e75c88321a3bf2b4ec1696ad1fe3632918bc0
[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.Assert.assertNull;
11 import static org.mockito.Mockito.when;
12
13 import com.google.common.util.concurrent.FluentFuture;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import java.util.Optional;
17 import java.util.concurrent.ExecutionException;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.junit.Test;
20 import org.mockito.Mockito;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.mdsal.binding.api.ReadTransaction;
23 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
24 import org.opendaylight.transportpce.common.NetworkUtils;
25 import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
26 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
27 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
28 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32
33 public class TapiTopologyImplExceptionTest {
34
35     @Test
36     public void getTopologyDetailsWithExceptionTest() throws InterruptedException, ExecutionException {
37         DataBroker dataBroker = Mockito.mock(DataBroker.class);
38         when(dataBroker.newReadOnlyTransaction())
39             .thenReturn(new ReadTransactionMock());
40
41         GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(NetworkUtils.OTN_NETWORK_ID);
42         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(dataBroker);
43         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
44         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
45         Topology topology = rpcResult.getResult().getTopology();
46         assertNull("Topology should be null", topology);
47     }
48
49     private class ReadTransactionMock implements ReadTransaction {
50
51         @Override
52         public @NonNull Object getIdentifier() {
53             // TODO Auto-generated method stub
54             return null;
55         }
56
57         @Override
58         public <T extends DataObject> @NonNull FluentFuture<Optional<T>> read(@NonNull LogicalDatastoreType store,
59             @NonNull InstanceIdentifier<T> path) {
60             return FluentFuture.from(Futures.immediateFailedFuture(new InterruptedException()));
61         }
62
63         @Override
64         public @NonNull FluentFuture<Boolean> exists(@NonNull LogicalDatastoreType store,
65             @NonNull InstanceIdentifier<?> path) {
66             // TODO Auto-generated method stub
67             return null;
68         }
69
70         @Override
71         public void close() {
72             // TODO Auto-generated method stub
73         }
74     }
75
76 }