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