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