Fix tapi execution
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / topology / TapiTopologyImplTest.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.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.ListeningExecutorService;
15 import com.google.common.util.concurrent.MoreExecutors;
16 import java.util.concurrent.CountDownLatch;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.Executors;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.transportpce.common.DataStoreContext;
23 import org.opendaylight.transportpce.common.DataStoreContextImpl;
24 import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
25 import org.opendaylight.transportpce.test.AbstractTest;
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.common.RpcResult;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33
34 public class TapiTopologyImplTest extends AbstractTest {
35     private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImplTest.class);
36
37     private ListeningExecutorService executorService;
38     private CountDownLatch endSignal;
39     private static final int NUM_THREADS = 3;
40     private DataStoreContext dataStoreContextUtil;
41
42     @Before
43     public void setUp() throws InterruptedException {
44         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
45         endSignal = new CountDownLatch(1);
46         dataStoreContextUtil = new DataStoreContextImpl();
47         TopologyDataUtils.writeTopologyFromFileToDatastore(dataStoreContextUtil);
48         TopologyDataUtils.writePortmappingFromFileToDatastore(dataStoreContextUtil);
49         LOG.info("setup done");
50     }
51
52     @Test
53     public void getTopologyDetailsWhenSuccessful() throws ExecutionException, InterruptedException {
54         GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput();
55         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(dataStoreContextUtil.getDataBroker());
56         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
57         result.addListener(new Runnable() {
58             @Override
59             public void run() {
60                 endSignal.countDown();
61             }
62         }, executorService);
63         endSignal.await();
64         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
65         @Nullable
66         Topology topology = rpcResult.getResult().getTopology();
67         LOG.info("topo TAPI returned = {}", topology);
68
69         assertNotNull("Topology should not be null", topology);
70         assertEquals("Nodes list size should be 1",
71                 1, topology.getNode().size());
72         assertEquals("Node name should be TapiNode1",
73                 "TapiNode1", topology.getNode().get(0).getName().get(0).getValue());
74     }
75
76 }