Fix tapi execution
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / topology / TapiTopologyImplTest.java
index 517f34e71e8a0035ea450d5d707402521da3c692..eec94e321a5f9a7ed8b654a330cb8474990c2f6d 100644 (file)
@@ -7,12 +7,16 @@
  */
 package org.opendaylight.transportpce.tapi.topology;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
+import org.eclipse.jdt.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.transportpce.common.DataStoreContext;
@@ -21,50 +25,52 @@ import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
 import org.opendaylight.transportpce.test.AbstractTest;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
+import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 public class TapiTopologyImplTest extends AbstractTest {
     private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImplTest.class);
 
     private ListeningExecutorService executorService;
     private CountDownLatch endSignal;
     private static final int NUM_THREADS = 3;
-    private boolean callbackRan;
     private DataStoreContext dataStoreContextUtil;
 
     @Before
     public void setUp() throws InterruptedException {
         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
         endSignal = new CountDownLatch(1);
-        callbackRan = false;
         dataStoreContextUtil = new DataStoreContextImpl();
         TopologyDataUtils.writeTopologyFromFileToDatastore(dataStoreContextUtil);
         TopologyDataUtils.writePortmappingFromFileToDatastore(dataStoreContextUtil);
         LOG.info("setup done");
-        Thread.sleep(1000);
     }
 
     @Test
     public void getTopologyDetailsWhenSuccessful() throws ExecutionException, InterruptedException {
         GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput();
         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(dataStoreContextUtil.getDataBroker());
-
         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
-
         result.addListener(new Runnable() {
             @Override
             public void run() {
-                callbackRan = true;
                 endSignal.countDown();
             }
         }, executorService);
-
         endSignal.await();
-
         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
-        LOG.info("topo TAPI returned = {}", rpcResult.getResult().getTopology());
+        @Nullable
+        Topology topology = rpcResult.getResult().getTopology();
+        LOG.info("topo TAPI returned = {}", topology);
+
+        assertNotNull("Topology should not be null", topology);
+        assertEquals("Nodes list size should be 1",
+                1, topology.getNode().size());
+        assertEquals("Node name should be TapiNode1",
+                "TapiNode1", topology.getNode().get(0).getName().get(0).getValue());
     }
 
 }