fix import extra separations
[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 com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.util.concurrent.CountDownLatch;
14 import java.util.concurrent.ExecutionException;
15 import java.util.concurrent.Executors;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.transportpce.common.DataStoreContext;
19 import org.opendaylight.transportpce.common.DataStoreContextImpl;
20 import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
21 import org.opendaylight.transportpce.test.AbstractTest;
22 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
23 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class TapiTopologyImplTest extends AbstractTest {
29     private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImplTest.class);
30
31     private ListeningExecutorService executorService;
32     private CountDownLatch endSignal;
33     private static final int NUM_THREADS = 3;
34     private boolean callbackRan;
35     private DataStoreContext dataStoreContextUtil;
36
37     @Before
38     public void setUp() throws InterruptedException {
39         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
40         endSignal = new CountDownLatch(1);
41         callbackRan = false;
42         dataStoreContextUtil = new DataStoreContextImpl();
43         TopologyDataUtils.writeTopologyFromFileToDatastore(dataStoreContextUtil);
44         TopologyDataUtils.writePortmappingFromFileToDatastore(dataStoreContextUtil);
45         LOG.info("setup done");
46         Thread.sleep(1000);
47     }
48
49     @Test
50     public void getTopologyDetailsWhenSuccessful() throws ExecutionException, InterruptedException {
51         GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput();
52         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(dataStoreContextUtil.getDataBroker());
53
54         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
55
56         result.addListener(new Runnable() {
57             @Override
58             public void run() {
59                 callbackRan = true;
60                 endSignal.countDown();
61             }
62         }, executorService);
63
64         endSignal.await();
65
66         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
67         LOG.info("topo TAPI returned = {}", rpcResult.getResult().getTopology());
68     }
69
70 }