Rework CheckUtil Test 33/53433/8
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Wed, 15 Mar 2017 06:59:58 +0000 (07:59 +0100)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Sat, 15 Apr 2017 11:23:25 +0000 (13:23 +0200)
Change-Id: Icada2980901bea076b061b933d8ba42876d0e5f5
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
23 files changed:
bgp/benchmark-app/pom.xml
bgp/benchmark-app/src/main/java/org/opendaylight/protocol/bgp/benchmark/app/AppPeerBenchmark.java
bgp/benchmark-app/src/test/java/org/opendaylight/protocol/bgp/benchmark/app/AppPeerBenchmarkTest.java
bgp/bmp-impl/src/test/java/org/opendaylight/protocol/bmp/impl/app/BmpMonitorImplTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/AbstractAddPathTest.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/ParserToSalTest.java
bgp/topology-provider/pom.xml
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/AbstractTopologyBuilderTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/Ipv4ReachabilityTopologyBuilderTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/Ipv6ReachabilityTopologyBuilderTest.java
bgp/topology-provider/src/test/java/org/opendaylight/bgpcep/bgp/topology/provider/LinkstateTopologyBuilderTest.java
data-change-counter/src/test/java/org/opendaylight/protocol/data/change/counter/TopologyDataChangeCounterTest.java
pcep/segment-routing/src/test/java/org/opendaylight/protocol/pcep/segment/routing/TopologyProviderTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/IncrementalSynchronizationProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTriggeredReSynchronizationProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/PCETriggeredInitialSyncProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/StateSynchronizationAvoidanceProcedureTest.java
pcep/topology-provider/src/test/java/org/opendaylight/bgpcep/pcep/topology/provider/Stateful07TopologySessionListenerTest.java
pcep/tunnel-provider/pom.xml
pcep/tunnel-provider/src/test/java/org/opendaylight/bgpcep/pcep/tunnel/provider/NodeChangedListenerTest.java
programming/impl/src/test/java/org/opendaylight/bgpcep/programming/impl/ProgrammingServiceImplTest.java
testtool-util/src/main/java/org/opendaylight/protocol/util/CheckUtil.java
testtool-util/src/test/java/org/opendaylight/protocol/util/CheckUtilTest.java

index cfd320dd7048f08e1c7b9bb4833f196333503cfd..45ccbac534a4c7b5dc294a61296bd7de7a75c2a0 100644 (file)
             <artifactId>sal-binding-config</artifactId>
         </dependency>
         <!-- test dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
index 17593c08418352a9d43954e5dee1adbc2faca3e7..04fb31b575311a460ca4e629e54fad915f55cc86 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.protocol.bgp.benchmark.app;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Stopwatch;
 import com.google.common.net.InetAddresses;
 import java.util.Collections;
@@ -170,6 +171,11 @@ public class AppPeerBenchmark implements OdlBgpAppPeerBenchmarkService, Transact
         LOG.info("BGP Application Peer Benchmark Application closed.");
     }
 
+    @VisibleForTesting
+    InstanceIdentifier<Ipv4Routes> getIpv4RoutesIID() {
+        return this.routesIId;
+    }
+
     private long addRoute(final Ipv4Prefix ipv4Prefix, final Ipv4Address nextHop, final long count, final long batch) {
         final AttributesBuilder attributesBuilder = new AttributesBuilder();
         attributesBuilder.setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(
index 620d6cfe6709a92f827b1fddf8f8e4a90a04dd16..9d1eeceb6f04db25847a65486f523059fd687bf5 100644 (file)
@@ -8,39 +8,36 @@
 
 package org.opendaylight.protocol.bgp.benchmark.app;
 
-import java.util.concurrent.ExecutionException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
+import static org.opendaylight.protocol.util.CheckUtil.readDataConfiguration;
+
 import javax.management.MalformedObjectNameException;
-import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.Ipv4Routes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.OdlBgpAppPeerBenchmarkService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.output.Result;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public class AppPeerBenchmarkTest extends AbstractDataBrokerTest {
@@ -49,60 +46,51 @@ public class AppPeerBenchmarkTest extends AbstractDataBrokerTest {
     private static final String NH = "127.0.0.1";
     private static final String PEER_RIB_ID = "app-peer";
 
-    private static final InstanceIdentifier<ApplicationRib> BASE_IID = KeyedInstanceIdentifier.builder(ApplicationRib.class,
-            new ApplicationRibKey(new ApplicationRibId(PEER_RIB_ID))).build();
-    private static final InstanceIdentifier tablesIId = BASE_IID
-            .child(Tables.class, new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-    private static final InstanceIdentifier<Ipv4Routes> ROUTES = tablesIId.child(Ipv4Routes.class);
-
     @Mock
     private RpcProviderRegistry rpcRegistry;
     @Mock
     private RoutedRpcRegistration<OdlBgpAppPeerBenchmarkService> registration;
 
-    private AppPeerBenchmark appPeerBenchmark;
-
     @Before
-    public void setUp() throws MalformedObjectNameException {
+    public void setUp() throws MalformedObjectNameException, TransactionCommitFailedException {
         MockitoAnnotations.initMocks(this);
-        Mockito.doReturn(this.registration).when(this.rpcRegistry).addRpcImplementation(Mockito.<Class<OdlBgpAppPeerBenchmarkService>>any(),
+        doReturn(this.registration).when(this.rpcRegistry).addRpcImplementation(Mockito.any(),
                 Mockito.any(OdlBgpAppPeerBenchmarkService.class));
-        Mockito.doNothing().when(this.registration).close();
-        this.appPeerBenchmark = new AppPeerBenchmark(getDataBroker(), this.rpcRegistry, PEER_RIB_ID);
+        doNothing().when(this.registration).close();
     }
 
     @Test
-    public void testRpcs() throws InterruptedException, ExecutionException, ReadFailedException {
-        final RpcResult<AddPrefixOutput> addRpcResult = this.appPeerBenchmark.addPrefix(new AddPrefixInputBuilder()
-            .setBatchsize(1L)
-            .setCount(1L)
-            .setNexthop(new Ipv4Address(NH))
-            .setPrefix(new Ipv4Prefix(PREFIX)).build()).get();
+    public void testRpcs() throws Exception {
+        final AppPeerBenchmark appPeerBenchmark = new AppPeerBenchmark(getDataBroker(), this.rpcRegistry, PEER_RIB_ID);
+        final InstanceIdentifier<Ipv4Routes> routesIID = appPeerBenchmark.getIpv4RoutesIID();
+
+        final AddPrefixInput addPrefix = new AddPrefixInputBuilder().setBatchsize(1L).setCount(1L)
+            .setNexthop(new Ipv4Address(NH)).setPrefix(new Ipv4Prefix(PREFIX)).build();
+
+        final RpcResult<AddPrefixOutput> addRpcResult = appPeerBenchmark.addPrefix(addPrefix).get();
         final Result addResult = addRpcResult.getResult().getResult();
-        Assert.assertEquals(1, addResult.getCount().intValue());
-        Assert.assertEquals(1, addResult.getRate().intValue());
-        final Ipv4Routes routesAfterAdd = getRoutes();
-        Assert.assertEquals(1, routesAfterAdd.getIpv4Route().size());
+        checkEquals(()-> assertEquals(1, addResult.getCount().intValue()));
+        checkEquals(()-> assertEquals(1, addResult.getRate().intValue()));
 
-        final RpcResult<DeletePrefixOutput> deleteRpcResult = this.appPeerBenchmark.deletePrefix(new DeletePrefixInputBuilder()
-            .setBatchsize(1L)
-            .setCount(1L)
-            .setPrefix(new Ipv4Prefix(PREFIX)).build()).get();
-        final Result deleteResult = deleteRpcResult.getResult().getResult();
-        Assert.assertEquals(1, deleteResult.getCount().intValue());
-        Assert.assertEquals(1, deleteResult.getRate().intValue());
-        final Ipv4Routes routesAfterDelete = getRoutes();
-        Assert.assertTrue(routesAfterDelete.getIpv4Route().isEmpty());
-    }
+        readDataConfiguration(getDataBroker(), routesIID, routes -> {
+            assertNotNull(routes.getIpv4Route());
+            assertEquals(1, routes.getIpv4Route().size());
+            return routes;
+        });
 
-    @After
-    public void tearDown() {
-        this.appPeerBenchmark.close();
-    }
+        final DeletePrefixInput deletePrefix = new DeletePrefixInputBuilder().setBatchsize(1L).setCount(1L)
+            .setPrefix(new Ipv4Prefix(PREFIX)).build();
+        final RpcResult<DeletePrefixOutput> deleteRpcResult = appPeerBenchmark
+            .deletePrefix(deletePrefix).get();
+        final Result deleteResult = deleteRpcResult.getResult().getResult();
+        checkEquals(()-> assertEquals(1, deleteResult.getCount().intValue()));
+        checkEquals(()-> assertEquals(1, deleteResult.getRate().intValue()));
+        readDataConfiguration(getDataBroker(), routesIID, routes -> {
+            assertNotNull(routes.getIpv4Route());
+            assertTrue(routes.getIpv4Route().isEmpty());
+            return routes;
+        });
 
-    private Ipv4Routes getRoutes() throws ReadFailedException {
-        final ReadOnlyTransaction rTx = getDataBroker().newReadOnlyTransaction();
-        return rTx.read(LogicalDatastoreType.CONFIGURATION, ROUTES).checkedGet().get();
+        appPeerBenchmark.close();
     }
-
 }
index cbc1d74b82c43d61d266ed57b7e3864f9c01c816..35fa0908cf1df32cfbd9b9f741ec6b56df475ab7 100644 (file)
@@ -14,7 +14,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.base.Optional;
@@ -162,7 +162,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
                 MONITOR_ID, new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS), MONITOR_LOCAL_PORT), Optional.of(keys),
                 this.mappingService.getCodecFactory(), this.moduleInfoBackedContext.getSchemaContext(), null);
 
-        readData(getDataBroker(), BMP_II, monitor -> {
+        readDataOperational(getDataBroker(), BMP_II, monitor -> {
             Assert.assertEquals(1, monitor.getMonitor().size());
             final Monitor bmpMonitor = monitor.getMonitor().get(0);
             Assert.assertEquals(MONITOR_ID, bmpMonitor.getMonitorId());
@@ -182,7 +182,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
         this.bmpApp.close();
         this.mappingService.close();
 
-        readData(getDataBroker(), BMP_II, monitor -> {
+        readDataOperational(getDataBroker(), BMP_II, monitor -> {
             assertTrue(monitor.getMonitor().isEmpty());
             return monitor;
         });
@@ -192,13 +192,13 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
     public void testRouterMonitoring() throws Exception {
         // first test if a single router monitoring is working
         final Channel channel1 = testMonitoringStation(REMOTE_ROUTER_ADDRESS_1);
-        readData(getDataBroker(), MONITOR_IID, monitor -> {
+        readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
             assertEquals(1, monitor.getRouter().size());
             return monitor;
         });
 
         final Channel channel2 = testMonitoringStation(REMOTE_ROUTER_ADDRESS_2);
-        readData(getDataBroker(), MONITOR_IID, monitor -> {
+        readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
             assertEquals(2, monitor.getRouter().size());
             return monitor;
         });
@@ -216,13 +216,13 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
         waitFutureSuccess(channel1.close());
 
         // channel 2 is still open
-        readData(getDataBroker(), MONITOR_IID, monitor -> {
+        readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
             assertEquals(1, monitor.getRouter().size());
             return monitor;
         });
 
         final Channel channel4 = testMonitoringStation(REMOTE_ROUTER_ADDRESS_1);
-        readData(getDataBroker(), MONITOR_IID, monitor -> {
+        readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
             assertEquals(2, monitor.getRouter().size());
             return monitor;
         });
@@ -234,7 +234,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
         // sleep for a while to avoid intermittent InMemoryDataTree modification conflict
         waitFutureSuccess(channel4.close());
 
-        readData(getDataBroker(), MONITOR_IID, monitor -> {
+        readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
             assertEquals(0, monitor.getRouter().size());
             return monitor;
         });
@@ -248,7 +248,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
         final Channel channel = connectTestClient(remoteRouterIpAddr, this.msgRegistry);
         final RouterId routerId = getRouterId(remoteRouterIpAddr);
         try {
-            readData(getDataBroker(), MONITOR_IID, monitor -> {
+            readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
                 assertFalse(monitor.getRouter().isEmpty());
                 // now find the current router instance
                 Router router = null;
@@ -266,7 +266,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
 
             waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createInitMsg("description", "name", "some info")));
 
-            readData(getDataBroker(), MONITOR_IID, monitor -> {
+            readDataOperational(getDataBroker(), MONITOR_IID, monitor -> {
                 assertFalse(monitor.getRouter().isEmpty());
                 Router retRouter = null;
                 for (final Router r : monitor.getRouter()) {
@@ -288,7 +288,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
             waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createPeerUpNotification(PEER1, true)));
             final KeyedInstanceIdentifier<Router, RouterKey> routerIId = MONITOR_IID.child(Router.class, new RouterKey(routerId));
 
-            readData(getDataBroker(), routerIId, router -> {
+            readDataOperational(getDataBroker(), routerIId, router -> {
                 final List<Peer> peers = router.getPeer();
                 assertEquals(1, peers.size());
                 final Peer peer = peers.get(0);
@@ -332,7 +332,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
             waitWriteAndFlushSuccess(channel.writeAndFlush(statsMsg));
             final KeyedInstanceIdentifier<Peer, PeerKey> peerIId = routerIId.child(Peer.class, new PeerKey(PEER_ID));
 
-            readData(getDataBroker(), peerIId.child(Stats.class), peerStats -> {
+            readDataOperational(getDataBroker(), peerIId.child(Stats.class), peerStats -> {
                 assertNotNull(peerStats.getTimestampSec());
                 final Tlvs tlvs = statsMsg.getTlvs();
                 assertEquals(tlvs.getAdjRibsInRoutesTlv().getCount(), peerStats.getAdjRibsInRoutes());
@@ -353,7 +353,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
             final RouteMirroringMessage routeMirrorMsg = TestUtil.createRouteMirrorMsg(PEER1);
             waitWriteAndFlushSuccess(channel.writeAndFlush(routeMirrorMsg));
 
-            readData(getDataBroker(), peerIId.child(Mirrors.class), routeMirrors -> {
+            readDataOperational(getDataBroker(), peerIId.child(Mirrors.class), routeMirrors -> {
                 assertNotNull(routeMirrors.getTimestampSec());
                 return routeMirrors;
             });
@@ -361,7 +361,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
             waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createRouteMonitMsg(false, PEER1, AdjRibInType.PrePolicy)));
             waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createRouteMonMsgWithEndOfRibMarker(PEER1, AdjRibInType.PrePolicy)));
 
-            readData(getDataBroker(), peerIId.child(PrePolicyRib.class), prePolicyRib -> {
+            readDataOperational(getDataBroker(), peerIId.child(PrePolicyRib.class), prePolicyRib -> {
                 assertTrue(!prePolicyRib.getTables().isEmpty());
                 final Tables tables = prePolicyRib.getTables().get(0);
                 assertTrue(tables.getAttributes().isUptodate());
@@ -372,7 +372,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
             waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createRouteMonitMsg(false, PEER1, AdjRibInType.PostPolicy)));
             waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createRouteMonMsgWithEndOfRibMarker(PEER1, AdjRibInType.PostPolicy)));
 
-            readData(getDataBroker(), peerIId.child(PostPolicyRib.class), postPolicyRib -> {
+            readDataOperational(getDataBroker(), peerIId.child(PostPolicyRib.class), postPolicyRib -> {
                 assertTrue(!postPolicyRib.getTables().isEmpty());
                 final Tables tables = postPolicyRib.getTables().get(0);
                 assertTrue(tables.getAttributes().isUptodate());
@@ -383,7 +383,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
 
             waitWriteAndFlushSuccess(channel.writeAndFlush(TestUtil.createPeerDownNotification(PEER1)));
 
-            readData(getDataBroker(), routerIId, router -> {
+            readDataOperational(getDataBroker(), routerIId, router -> {
                 final List<Peer> peersAfterDown = router.getPeer();
                 assertTrue(peersAfterDown.isEmpty());
                 return router;
@@ -405,7 +405,7 @@ public class BmpMonitorImplTest extends AbstractDataBrokerTest {
                 new MonitorId("monitor2"), new InetSocketAddress(InetAddresses.forString(MONITOR_LOCAL_ADDRESS_2), MONITOR_LOCAL_PORT), Optional.of(KeyMapping.getKeyMapping()),
                 this.mappingService.getCodecFactory(), this.moduleInfoBackedContext.getSchemaContext(), null);
 
-        readData(getDataBroker(), BMP_II, monitor -> {
+        readDataOperational(getDataBroker(), BMP_II, monitor -> {
             Assert.assertEquals(2, monitor.getMonitor().size());
             return monitor;
         });
index 575ed50e0544f040a61fff8a3cb52f69a1eb90e8..6655d79e6fedda26572e9201fc4f8040d2ef825d 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.base.Optional;
@@ -219,7 +219,7 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
 
     private void checkLocRib(final int expectedRoutesOnDS) throws Exception {
         Thread.sleep(100);
-        readData(getDataBroker(), BGP_IID, bgpRib -> {
+        readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
             final Ipv4RoutesCase routes = ((Ipv4RoutesCase) bgpRib.getRib().get(0).getLocRib().getTables().get(0)
                 .getRoutes());
             final List<Ipv4Route> routeList = routes.getIpv4Routes().getIpv4Route();
@@ -229,7 +229,7 @@ class AbstractAddPathTest extends AbstractDataBrokerTest {
     }
 
     void checkPeersPresentOnDataStore(final int numberOfPeers) throws Exception {
-        readData(getDataBroker(), BGP_IID, bgpRib -> {
+        readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
             Assert.assertEquals(numberOfPeers, bgpRib.getRib().get(0).getPeer().size());
             return bgpRib;
         });
index cc3de9c9a03d68a67a116047f3b6f2a48d27ef38..1cff2ae9e0c89b30917895b2b5077410a2310328 100755 (executable)
@@ -11,6 +11,9 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
+import static org.opendaylight.protocol.bgp.rib.impl.AbstractAddPathTest.AS_NUMBER;
+import static org.opendaylight.protocol.bgp.rib.impl.AbstractAddPathTest.BGP_ID;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Throwables;
@@ -24,7 +27,6 @@ import java.net.InetSocketAddress;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -34,12 +36,12 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
 import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestCustomizer;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.protocol.bgp.inet.RIBActivator;
 import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
@@ -51,7 +53,6 @@ import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivat
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
 import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6Route;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
@@ -61,12 +62,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.LocRib;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
@@ -77,12 +74,14 @@ import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 public class ParserToSalTest extends AbstractDataBrokerTest {
 
     private static final String TEST_RIB_ID = "testRib";
+    private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+    private static final InstanceIdentifier<BgpRib> BGP_IID = InstanceIdentifier.create(BgpRib.class);
     private BGPMock mock;
     private AbstractRIBExtensionProviderActivator baseact, lsact;
     private RIBExtensionProviderContext ext1, ext2;
-    private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+
     @Mock
-    BGPDispatcher dispatcher;
+    private BGPDispatcher dispatcher;
     @Mock
     private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
     private BindingCodecTreeFactory codecFactory;
@@ -119,10 +118,12 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
         } catch (final IOException e) {
             throw Throwables.propagate(e);
         }
-        this.mock = new BGPMock(new EventBus("test"), ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(), Lists.newArrayList(fixMessages(bgpMessages)));
+        this.mock = new BGPMock(new EventBus("test"), ServiceLoaderBGPExtensionProviderContext
+            .getSingletonInstance().getMessageRegistry(), Lists.newArrayList(fixMessages(bgpMessages)));
 
-        Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher).createReconnectingClient(
-                Mockito.any(InetSocketAddress.class), Mockito.any(BGPPeerRegistry.class), Mockito.anyInt(), Mockito.any(Optional.class));
+        Mockito.doReturn(GlobalEventExecutor.INSTANCE.newSucceededFuture(null)).when(this.dispatcher)
+            .createReconnectingClient(Mockito.any(InetSocketAddress.class), Mockito.any(BGPPeerRegistry.class),
+                Mockito.anyInt(), Mockito.any(Optional.class));
 
         this.ext1 = new SimpleRIBExtensionProviderContext();
         this.ext2 = new SimpleRIBExtensionProviderContext();
@@ -140,14 +141,16 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
     }
 
     @Test
-    public void testWithLinkstate() throws InterruptedException, ExecutionException {
-        final List<BgpTableType> tables = ImmutableList.of(
-                new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
-        final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), new AsNumber(72L), new BgpId("127.0.0.1"),
-            null, this.ext2, this.dispatcher, this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
-            BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+    public void testWithLinkstate() throws ReadFailedException {
+        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(LinkstateAddressFamily.class,
+            LinkstateSubsequentAddressFamily.class));
+        final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID),
+            AS_NUMBER, BGP_ID, null, this.ext2, this.dispatcher,
+            this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
+            BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
+            GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
         rib.instantiateServiceInstance();
-        assertTablesExists(tables, true);
+        assertTablesExists(tables);
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
         final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib, PeerRole.Ibgp, null);
         peer.instantiateServiceInstance();
@@ -156,14 +159,16 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
     }
 
     @Test
-    public void testWithoutLinkstate() throws InterruptedException, ExecutionException {
-        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
-        final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), new AsNumber(72L), new BgpId("127.0.0.1"), null,
-            this.ext1, this.dispatcher, this.codecFactory, getDomBroker(), tables, Collections.singletonMap(TABLE_KEY,
-            BasePathSelectionModeFactory.createBestPathSelectionStrategy()), GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
+    public void testWithoutLinkstate() throws ReadFailedException {
+        final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class,
+            UnicastSubsequentAddressFamily.class));
+        final RIBImpl rib = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(TEST_RIB_ID), AS_NUMBER, BGP_ID, null,
+            this.ext1, this.dispatcher, this.codecFactory, getDomBroker(), tables,
+            Collections.singletonMap(TABLE_KEY, BasePathSelectionModeFactory.createBestPathSelectionStrategy()),
+            GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), null);
         rib.instantiateServiceInstance();
         rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
-        assertTablesExists(tables, true);
+        assertTablesExists(tables);
         final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib, PeerRole.Ibgp, null);
         peer.instantiateServiceInstance();
         final ListenerRegistration<?> reg = this.mock.registerUpdateListener(peer);
@@ -180,24 +185,23 @@ public class ParserToSalTest extends AbstractDataBrokerTest {
         });
     }
 
-    private void assertTablesExists(final List<BgpTableType> expectedTables, final boolean uptodate) throws InterruptedException, ExecutionException {
-        final Optional<LocRib> lockRib = getLocRibTable();
-        assertTrue(lockRib.isPresent());
-        final List<Tables> tables = lockRib.get().getTables();
-        assertFalse(tables.isEmpty());
-        for (final BgpTableType tableType : expectedTables) {
-            boolean found = false;
-            for (final Tables table : tables) {
-                if(table.getAfi().equals(tableType.getAfi()) && table.getSafi().equals(tableType.getSafi())) {
-                    found = true;
-                    assertTrue(Boolean.valueOf(uptodate).equals(table.getAttributes().isUptodate()));
+    private void assertTablesExists(final List<BgpTableType> expectedTables)
+        throws ReadFailedException {
+        readDataOperational(getDataBroker(), BGP_IID, bgpRib -> {
+            final List<Tables> tables = bgpRib.getRib().get(0).getLocRib().getTables();
+            assertFalse(tables.isEmpty());
+
+            for (final BgpTableType tableType : expectedTables) {
+                boolean found = false;
+                for (final Tables table : tables) {
+                    if (table.getAfi().equals(tableType.getAfi()) && table.getSafi().equals(tableType.getSafi())) {
+                        found = true;
+                        assertTrue(Boolean.valueOf(true).equals(table.getAttributes().isUptodate()));
+                    }
                 }
+                assertTrue(found);
             }
-            assertTrue(found);
-        }
-    }
-
-    private Optional<LocRib> getLocRibTable() throws InterruptedException, ExecutionException {
-        return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId(TEST_RIB_ID))).child(LocRib.class).build()).get();
+            return bgpRib;
+        });
     }
 }
index 9132f2cbcf4fc8a238438c94cd9ffa96740bb923..8bd28a21f74f4ff776e24319ea8335061a5f6e51 100644 (file)
         </dependency>
 
         <!-- Test dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-core</artifactId>
index 9700e25182f575cb99046cdf2ff4ef843c403ca8..0909ad1ab45c795072f490ed66b18317d1f3fca0 100644 (file)
@@ -33,8 +33,9 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public abstract class AbstractTopologyBuilderTest extends AbstractDataBrokerTest {
 
-    protected static final TopologyId TEST_TOPOLOGY_ID = new TopologyId("test-topo");
-    protected static final RibReference LOC_RIB_REF = new DefaultRibReference(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(new RibId("test-rib")))));
+    static final TopologyId TEST_TOPOLOGY_ID = new TopologyId("test-topo");
+    static final RibReference LOC_RIB_REF = new DefaultRibReference(InstanceIdentifier.create(BgpRib.class)
+        .child(Rib.class, new RibKey(Preconditions.checkNotNull(new RibId("test-rib")))));
 
     @Override
     protected void setupWithDataBroker(final DataBroker dataBroker) {
index 5e718a533b768891fb7b8181bbdbb6722c4d2f64..05d1a76f037ce01398762b3ba99cd068c67edfae 100755 (executable)
@@ -9,15 +9,15 @@
 package org.opendaylight.bgpcep.bgp.topology.provider;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
-import com.google.common.base.Optional;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
@@ -35,7 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -53,44 +53,54 @@ public class Ipv4ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
     @Override
     protected void setupWithDataBroker(final DataBroker dataBroker) {
         super.setupWithDataBroker(dataBroker);
-        this.ipv4TopoBuilder = new Ipv4ReachabilityTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID);
+        this.ipv4TopoBuilder = new Ipv4ReachabilityTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID);
         this.ipv4TopoBuilder.start();
-        final InstanceIdentifier<Tables> path = this.ipv4TopoBuilder.tableInstanceIdentifier(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
-        this.ipv4RouteIID = path.builder().child((Class) Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(new PathId(PATH_ID),
-            new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
+        final InstanceIdentifier<Tables> path = this.ipv4TopoBuilder.tableInstanceIdentifier(Ipv4AddressFamily.class,
+            UnicastSubsequentAddressFamily.class);
+        this.ipv4RouteIID = path.builder().child((Class) Ipv4Routes.class)
+            .child(Ipv4Route.class, new Ipv4RouteKey(new PathId(PATH_ID),
+                new Ipv4Prefix(ROUTE_IP4PREFIX))).build();
     }
 
     @Test
-    public void testIpv4ReachabilityTopologyBuilder() throws TransactionCommitFailedException {
+    public void testIpv4ReachabilityTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
         // create route
         updateIpv4Route(createIpv4Route(NEXT_HOP));
-        final Optional<Topology> topologyMaybe = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology = topologyMaybe.get();
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpIpv4ReachabilityTopology());
-        assertEquals(1, topology.getNode().size());
-        final Node node = topology.getNode().get(0);
-        assertEquals(NEXT_HOP, node.getNodeId().getValue());
-        assertEquals(ROUTE_IP4PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+
+        readDataOperational(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+            final TopologyTypes1 topologyTypes = topology.getTopologyTypes().getAugmentation(TopologyTypes1.class);
+            assertNotNull(topologyTypes);
+            assertNotNull(topologyTypes.getBgpIpv4ReachabilityTopology());
+            assertEquals(1, topology.getNode().size());
+            final Node node = topology.getNode().get(0);
+            assertEquals(NEXT_HOP, node.getNodeId().getValue());
+            assertEquals(ROUTE_IP4PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0)
+                .getPrefix().getIpv4Prefix().getValue());
+            return topology;
+        });
 
         // update route
         updateIpv4Route(createIpv4Route(NEW_NEXT_HOP));
-        final Topology topologyUpdated = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(1, topologyUpdated.getNode().size());
-        final Node nodeUpdated = topologyUpdated.getNode().get(0);
-        assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
-        assertEquals(ROUTE_IP4PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+        readDataOperational(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final Node nodeUpdated = topology.getNode().get(0);
+            assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
+            assertEquals(ROUTE_IP4PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes()
+                .getPrefix().get(0).getPrefix().getIpv4Prefix().getValue());
+            return topology;
+        });
 
         // delete route
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
         wTx.delete(LogicalDatastoreType.OPERATIONAL, this.ipv4RouteIID);
         wTx.submit();
-        final Topology topologyDeleted = getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(0, topologyDeleted.getNode().size());
+        readDataOperational(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(0, topology.getNode().size());
+            return topology;
+        });
 
         this.ipv4TopoBuilder.close();
-        assertFalse(getTopology(this.ipv4TopoBuilder.getInstanceIdentifier()).isPresent());
+        checkNotPresentOperational(getDataBroker(), this.ipv4TopoBuilder.getInstanceIdentifier());
     }
 
     private void updateIpv4Route(final Ipv4Route data) {
index 0adab78f3ab55c7248c461066f8a1efe4dd3df12..40b78c6e88d9b51b1eaa881d22162bf1080235c1 100755 (executable)
@@ -9,16 +9,16 @@
 package org.opendaylight.bgpcep.bgp.topology.provider;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.opendaylight.bgpcep.bgp.topology.provider.Ipv4ReachabilityTopologyBuilderTest.PATH_ID;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
-import com.google.common.base.Optional;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
@@ -36,7 +36,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv6NextHopCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv6.next.hop._case.Ipv6NextHopBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Node1;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -53,44 +53,55 @@ public class Ipv6ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
     @Override
     protected void setupWithDataBroker(final DataBroker dataBroker) {
         super.setupWithDataBroker(dataBroker);
-        this.ipv6TopoBuilder = new Ipv6ReachabilityTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID);
+        this.ipv6TopoBuilder = new Ipv6ReachabilityTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID);
         this.ipv6TopoBuilder.start();
-        final InstanceIdentifier<Tables> path = this.ipv6TopoBuilder.tableInstanceIdentifier(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
-        this.ipv6RouteIID = path.builder().child((Class) Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(new PathId(PATH_ID),
-            new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
+        final InstanceIdentifier<Tables> path = this.ipv6TopoBuilder
+            .tableInstanceIdentifier(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
+        this.ipv6RouteIID = path.builder().child((Class) Ipv6Routes.class)
+            .child(Ipv6Route.class, new Ipv6RouteKey(new PathId(PATH_ID),
+                new Ipv6Prefix(ROUTE_IP6PREFIX))).build();
     }
 
     @Test
-    public void testIpv6ReachabilityTopologyBuilder() throws TransactionCommitFailedException {
+    public void testIpv6ReachabilityTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
         // create route
         updateIpv6Route(createIpv6Route(NEXT_HOP));
-        final Optional<Topology> topologyMaybe = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology = topologyMaybe.get();
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpIpv6ReachabilityTopology());
-        assertEquals(1, topology.getNode().size());
-        final Node node = topology.getNode().get(0);
-        assertEquals(NEXT_HOP, node.getNodeId().getValue());
-        assertEquals(ROUTE_IP6PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv6Prefix().getValue());
+
+        readDataOperational(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+            final TopologyTypes1 topologyType = topology.getTopologyTypes().getAugmentation(TopologyTypes1.class);
+            assertNotNull(topologyType);
+            assertNotNull(topologyType.getBgpIpv6ReachabilityTopology());
+            assertEquals(1, topology.getNode().size());
+            final Node node = topology.getNode().get(0);
+            assertEquals(NEXT_HOP, node.getNodeId().getValue());
+            assertEquals(ROUTE_IP6PREFIX, node.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix()
+                .get(0).getPrefix().getIpv6Prefix().getValue());
+            return topology;
+        });
 
         // update route
         updateIpv6Route(createIpv6Route(NEW_NEXT_HOP));
-        final Topology topologyUpdated = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(1, topologyUpdated.getNode().size());
-        final Node nodeUpdated = topologyUpdated.getNode().get(0);
-        assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
-        assertEquals(ROUTE_IP6PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix().get(0).getPrefix().getIpv6Prefix().getValue());
+
+        readDataOperational(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final Node nodeUpdated = topology.getNode().get(0);
+            assertEquals(NEW_NEXT_HOP, nodeUpdated.getNodeId().getValue());
+            assertEquals(ROUTE_IP6PREFIX, nodeUpdated.getAugmentation(Node1.class).getIgpNodeAttributes().getPrefix()
+                .get(0).getPrefix().getIpv6Prefix().getValue());
+            return topology;
+        });
 
         // delete route
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
         wTx.delete(LogicalDatastoreType.OPERATIONAL, this.ipv6RouteIID);
         wTx.submit();
-        final Topology topologyDeleted = getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(0, topologyDeleted.getNode().size());
+        readDataOperational(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(0, topology.getNode().size());
+            return topology;
+        });
 
         this.ipv6TopoBuilder.close();
-        assertFalse(getTopology(this.ipv6TopoBuilder.getInstanceIdentifier()).isPresent());
+        checkNotPresentOperational(getDataBroker(), this.ipv6TopoBuilder.getInstanceIdentifier());
     }
 
     private void updateIpv6Route(final Ipv6Route data) {
@@ -99,7 +110,7 @@ public class Ipv6ReachabilityTopologyBuilderTest extends AbstractTopologyBuilder
         wTx.submit();
     }
 
-    public Ipv6Route createIpv6Route(final String netxHop) {
+    private Ipv6Route createIpv6Route(final String netxHop) {
         final Attributes attribute = new AttributesBuilder()
             .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
             .setCNextHop(new Ipv6NextHopCaseBuilder().setIpv6NextHop(
index ec7a54abb7946316fb156fdd71d97cad18274aea..39f467c2d4f5b4758aa44ebeb1db3766f7c62762 100755 (executable)
@@ -9,7 +9,6 @@
 package org.opendaylight.bgpcep.bgp.topology.provider;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -24,8 +23,9 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import io.netty.buffer.Unpooled;
 import java.math.BigInteger;
@@ -34,11 +34,13 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -86,7 +88,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpLinkAttributes1;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.isis.topology.rev131021.IgpNodeAttributes1;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.Link1;
@@ -118,119 +119,136 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
     @Override
     protected void setupWithDataBroker(final DataBroker dataBroker) {
         super.setupWithDataBroker(dataBroker);
-        this.linkstateTopoBuilder = new LinkstateTopologyBuilder(dataBroker, LOC_RIB_REF, TEST_TOPOLOGY_ID, LISTENER_RESTART_TIME, LISTENER_ENFORCE_COUNTER);
+        this.linkstateTopoBuilder = new LinkstateTopologyBuilder(getDataBroker(), LOC_RIB_REF, TEST_TOPOLOGY_ID, LISTENER_RESTART_TIME, LISTENER_ENFORCE_COUNTER);
         this.linkstateTopoBuilder.start();
         final InstanceIdentifier<Tables> path = this.linkstateTopoBuilder.tableInstanceIdentifier(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
-        this.linkstateRouteIID = path.builder().child((Class)LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
+        this.linkstateRouteIID = path.builder().child((Class) LinkstateRoutes.class).child(LinkstateRoute.class, new LinkstateRouteKey(LINKSTATE_ROUTE_KEY)).build();
+
     }
 
     @After
     public void tearDown() throws Exception {
         this.linkstateTopoBuilder.close();
-        assertFalse(getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).isPresent());
+        checkNotPresentOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier());
     }
 
     @Test
-    public void testLinkstateTopologyBuilderTopologyTypes() {
-        final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology = topologyMaybe.get();
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
-        assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpLinkstateTopology());
+    public void testLinkstateTopologyBuilderTopologyTypes() throws ReadFailedException {
+        readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
+            assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class).getBgpLinkstateTopology());
+            return topology;
+        });
     }
 
     @Test
-    public void testIsisLinkstateTopologyBuilder() throws TransactionCommitFailedException {
+    public void testIsisLinkstateTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
         // create node
         updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "node1", NODE_1_AS, ROUTER_1_ID));
-        final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology1 = topologyMaybe.get();
-        assertEquals(1, topology1.getNode().size());
-        final Node node1 = topology1.getNode().get(0);
-        assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
-        final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
-        assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
-        assertEquals("node1", igpNode1.getName().getValue());
-        final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.getAugmentation(IgpNodeAttributes1.class);
-        assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());
-        assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
-        assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getNet().get(0).getValue());
-        assertNull(igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class));
+        readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final Node node1 = topology.getNode().get(0);
+            assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
+            final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
+            assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
+            assertEquals("node1", igpNode1.getName().getValue());
+            final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.getAugmentation(IgpNodeAttributes1.class);
+            assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId().getValue());
+            assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+            assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getNet().get(0).getValue());
+            assertNull(igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class));
+            return topology;
+        });
+
 
         // create link
         updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.IsisLevel2, NODE_1_AS, NODE_2_AS, "link1"));
-        final Topology topology2 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(1, topology2.getLink().size());
-        final Link link1 = topology2.getLink().get(0);
-        assertEquals(2, topology2.getNode().size());
-        assertEquals(1, topology2.getNode().get(0).getTerminationPoint().size());
-        assertEquals(1, topology2.getNode().get(1).getTerminationPoint().size());
-        assertEquals("bgpls://IsisLevel2:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
-        assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
-        assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
-        final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
-        assertEquals("link1", igpLink1.getName());
-        assertEquals((short) 1, igpLink1.getAugmentation(IgpLinkAttributes1.class).getIsisLinkAttributes().getMultiTopologyId().shortValue());
-        assertNull(igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class));
+        readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getLink().size());
+            final Link link1 = topology.getLink().get(0);
+            assertEquals(2, topology.getNode().size());
+            assertEquals(1, topology.getNode().get(0).getTerminationPoint().size());
+            assertEquals(1, topology.getNode().get(1).getTerminationPoint().size());
+            assertEquals("bgpls://IsisLevel2:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
+            assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
+            assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
+            final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
+            assertEquals("link1", igpLink1.getName());
+            assertEquals((short) 1, igpLink1.getAugmentation(IgpLinkAttributes1.class).getIsisLinkAttributes().getMultiTopologyId().shortValue());
+            assertNull(igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class));
+            return topology;
+        });
+
 
         // update node
         updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "updated-node", NODE_1_AS, ROUTER_2_ID));
-        final Topology topology3 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        final IgpNodeAttributes igpNode2 = topology3.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
-        assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
-        assertEquals("updated-node", igpNode2.getName().getValue());
+        readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final IgpNodeAttributes igpNode2 = topology.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
+            assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
+            assertEquals("updated-node", igpNode2.getName().getValue());
+            return topology;
+        });
 
         // remove
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
         wTx.delete(LogicalDatastoreType.OPERATIONAL, this.linkstateRouteIID);
         wTx.submit();
-        final Topology topology4 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(0, topology4.getNode().size());
-        assertEquals(0, topology4.getLink().size());
+        readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(0, topology.getNode().size());
+            assertEquals(0, topology.getLink().size());
+            return topology;
+        });
     }
 
     @Test
-    public void testOspfLinkstateTopologyBuilder() throws TransactionCommitFailedException {
+    public void testOspfLinkstateTopologyBuilder() throws TransactionCommitFailedException, ReadFailedException {
         // create node
         updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.Ospf, "node1", NODE_1_AS, ROUTER_1_ID));
-        final Optional<Topology> topologyMaybe = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier());
-        assertTrue(topologyMaybe.isPresent());
-        final Topology topology1 = topologyMaybe.get();
-        assertEquals(1, topology1.getNode().size());
-        final Node node1 = topology1.getNode().get(0);
-        assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
-        final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
-        assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
-        assertEquals("node1", igpNode1.getName().getValue());
-        assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
-        assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+        readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getNode().size());
+            final Node node1 = topology.getNode().get(0);
+            assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
+            final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
+            assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
+            assertEquals("node1", igpNode1.getName().getValue());
+            assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
+            assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed().getTeRouterIdIpv4().getValue());
+            return topology;
+        });
 
         // update node with prefix
         updateLinkstateRoute(createLinkstatePrefixRoute(ProtocolId.Ospf, NODE_1_AS, NODE_1_PREFIX, 500L, ROUTER_1_ID));
-        final Topology topology3 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        final IgpNodeAttributes igpNode2 = topology3.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
-        assertEquals(1, igpNode2.getPrefix().size());
-        final Prefix prefix = igpNode2.getPrefix().get(0);
-        assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
-        assertEquals(500L, prefix.getMetric().longValue());
+        readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            final IgpNodeAttributes igpNode2 = topology.getNode().get(0).getAugmentation(Node1.class).getIgpNodeAttributes();
+            assertEquals(1, igpNode2.getPrefix().size());
+            final Prefix prefix = igpNode2.getPrefix().get(0);
+            assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
+            assertEquals(500L, prefix.getMetric().longValue());
+            return topology;
+        });
+
 
         // create link
         updateLinkstateRoute(createLinkstateLinkRoute(ProtocolId.Ospf, NODE_1_AS, NODE_2_AS, "link1"));
-        final Topology topology2 = getTopology(this.linkstateTopoBuilder.getInstanceIdentifier()).get();
-        assertEquals(1, topology2.getLink().size());
-        final Link link1 = topology2.getLink().get(0);
-        assertEquals(2, topology2.getNode().size());
-        assertEquals(1, topology2.getNode().get(0).getTerminationPoint().size());
-        assertEquals(1, topology2.getNode().get(1).getTerminationPoint().size());
-        assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
-        assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
-        assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
-        final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
-        assertEquals("link1", igpLink1.getName());
-        assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
-        assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId().shortValue());
-        assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg().getSrlgValues().size());
+        readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
+            assertEquals(1, topology.getLink().size());
+            final Link link1 = topology.getLink().get(0);
+            assertEquals(2, topology.getNode().size());
+            assertEquals(1, topology.getNode().get(0).getTerminationPoint().size());
+            assertEquals(1, topology.getNode().get(1).getTerminationPoint().size());
+            assertEquals("bgpls://Ospf:1/type=link&local-as=1&local-router=0000.0102.0304&remote-as=2&mt=1", link1.getLinkId().getValue());
+            assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
+            assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
+            final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
+            assertEquals("link1", igpLink1.getName());
+            assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
+            assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId().shortValue());
+            assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg().getSrlgValues().size());
+            return topology;
+        });
+
+
     }
 
     /**
@@ -316,7 +334,7 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
 
     private LinkstateRoute createLinkstateNodeRoute(final ProtocolId protocolId, final String nodeName, final AsNumber asNumber, final String ipv4RouterId) {
         return createBaseBuilder(protocolId)
-            .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder().setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{ 0, 0, 1, 2, 3, 4 })).build()).build()).setAsNumber(asNumber).build()).build())
+            .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder().setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4})).build()).build()).setAsNumber(asNumber).build()).build())
             .setAttributes(new AttributesBuilder()
                 .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
                 .addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new NodeAttributesCaseBuilder().setNodeAttributes(new NodeAttributesBuilder()
@@ -334,13 +352,13 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
             .setAttributes(new AttributesBuilder()
                 .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
                 .addAugmentation(Attributes1.class, new Attributes1Builder().setLinkStateAttribute(new PrefixAttributesCaseBuilder().setPrefixAttributes(new PrefixAttributesBuilder().setOspfForwardingAddress(new IpAddress(new Ipv4Address(ospfFwdAddress))).setPrefixMetric(new IgpMetric(igpMetric)).build()).build()).build()).build())
-             .build();
+            .build();
     }
 
     private LinkstateRoute createLinkstateLinkRoute(final ProtocolId protocolId, final AsNumber localAs, final AsNumber remoteAs, final String linkName) {
         return createBaseBuilder(protocolId)
             .setObjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder()
-                .setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(localAs).setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{ 0, 0, 1, 2, 3, 4 })).build()).build()).build())
+                .setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(localAs).setCRouterIdentifier(new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[]{0, 0, 1, 2, 3, 4})).build()).build()).build())
                 .setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setAsNumber(remoteAs).build())
                 .setLinkDescriptors(new LinkDescriptorsBuilder().setMultiTopologyId(new TopologyIdentifier(1)).build())
                 .build())
index 44c3bc832009e2343118094a0969459d4dff2332..d153a444244eba91dc18af2c4f7b998a45473032 100755 (executable)
@@ -9,9 +9,9 @@
 package org.opendaylight.protocol.data.change.counter;
 
 import static org.junit.Assert.assertEquals;
-import static org.opendaylight.protocol.util.CheckUtil.checkNull;
-import static org.opendaylight.protocol.util.CheckUtil.checkPresent;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.checkPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
@@ -32,51 +32,51 @@ public class TopologyDataChangeCounterTest extends AbstractDataBrokerTest {
     @Test
     public void testDataChangeCounter() throws Exception {
         final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID1);
-        readData(getDataBroker(), this.counterInstanceId_1, count -> {
+        readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
             assertEquals(0, count.getCount().longValue());
             return count;
         });
 
         counter.onDataTreeChanged(null);
-        readData(getDataBroker(), this.counterInstanceId_1, count -> {
+        readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
             assertEquals(1, count.getCount().longValue());
             return count;
         });
 
         counter.close();
-        checkNull(getDataBroker(), this.counterInstanceId_1);
+        checkNotPresentOperational(getDataBroker(), this.counterInstanceId_1);
     }
 
     @Test
     public void testDataChangeCounterTwoInstances() throws Exception {
         final TopologyDataChangeCounter counter1 = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID1);
-        readData(getDataBroker(), this.counterInstanceId_1, count -> {
+        readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
             assertEquals(0, count.getCount().longValue());
             return count;
         });
 
         final TopologyDataChangeCounter counter2 = new TopologyDataChangeCounter(getDataBroker(), COUNTER_ID2);
-        readData(getDataBroker(), this.counterInstanceId_2, count -> {
+        readDataOperational(getDataBroker(), this.counterInstanceId_2, count -> {
             assertEquals(0, count.getCount().longValue());
             return count;
         });
 
         counter1.onDataTreeChanged(null);
-        readData(getDataBroker(), this.counterInstanceId_1, count -> {
+        readDataOperational(getDataBroker(), this.counterInstanceId_1, count -> {
             assertEquals(1, count.getCount().longValue());
             return count;
         });
-        readData(getDataBroker(), this.counterInstanceId_2, count -> {
+        readDataOperational(getDataBroker(), this.counterInstanceId_2, count -> {
             assertEquals(0, count.getCount().longValue());
             return count;
         });
 
         counter1.close();
-        checkNull(getDataBroker(), this.counterInstanceId_1);
+        checkNotPresentOperational(getDataBroker(), this.counterInstanceId_1);
         // Check that counter2 does not get deleted
-        checkPresent(getDataBroker(), this.counterInstanceId_2);
+        checkPresentOperational(getDataBroker(), this.counterInstanceId_2);
 
         counter2.close();
-        checkNull(getDataBroker(), this.counterInstanceId_2);
+        checkNotPresentOperational(getDataBroker(), this.counterInstanceId_2);
     }
 }
index 3f16b5a8b7d8170631620bbfc881165fe62be101..8da8d5b5ec47956e222e63c1aa229ce23546ea1a 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.protocol.pcep.segment.routing;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import com.google.common.collect.Lists;
 import java.nio.charset.StandardCharsets;
@@ -71,7 +71,7 @@ public class TopologyProviderTest extends AbstractPCEPSessionTest<Stateful07Topo
 
         Pcrpt pcRptMsg = createSrPcRpt("1.1.1.1", "sr-path1", 1L, true);
         this.listener.onMessage(this.session, pcRptMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check sr-path
             final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
             assertNotNull(reportedLsps);
@@ -89,7 +89,7 @@ public class TopologyProviderTest extends AbstractPCEPSessionTest<Stateful07Topo
 
         pcRptMsg = createSrPcRpt("1.1.1.3", "sr-path2", 2L, false);
         this.listener.onMessage(this.session, pcRptMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check second lsp sr-path
             final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
             assertNotNull(reportedLsps);
@@ -100,7 +100,7 @@ public class TopologyProviderTest extends AbstractPCEPSessionTest<Stateful07Topo
 
         pcRptMsg = createSrPcRpt("1.1.1.2", "sr-path1", 1L, true);
         this.listener.onMessage(this.session, pcRptMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check updated sr-path
             final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
             assertNotNull(reportedLsps);
index ab46aa9bba757f6660d94c7683b5185a7508835c..8a43de60ed231695ac551744e73296414436c2ea 100644 (file)
@@ -13,7 +13,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
@@ -62,7 +62,7 @@ public class IncrementalSynchronizationProcedureTest extends AbstractPCEPSession
         //report LSP + LSP-DB version number
         final Pcrpt pcRpt = getPcrpt(1L, "test");
         this.listener.onMessage(session, pcRpt);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertFalse(pcc.getReportedLsp().isEmpty());
             return pcc;
         });
@@ -74,7 +74,7 @@ public class IncrementalSynchronizationProcedureTest extends AbstractPCEPSession
         final LspDbVersion localDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.valueOf(2L)).build();
         session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
         this.listener.onSessionUp(session);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - IncrementalSync state
             assertEquals(PccSyncState.IncrementalSync, pcc.getStateSync());
             //check reported LSP - persisted from previous session
@@ -85,7 +85,7 @@ public class IncrementalSynchronizationProcedureTest extends AbstractPCEPSession
         //report LSP2 + LSP-DB version number 2
         final Pcrpt pcRpt2 = getPcrpt(2L,"testsecond");
         this.listener.onMessage(session, pcRpt2);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.IncrementalSync, pcc.getStateSync());
             //check reported LSP is not empty
@@ -96,7 +96,7 @@ public class IncrementalSynchronizationProcedureTest extends AbstractPCEPSession
         //sync rpt + LSP-DB
         final Pcrpt syncMsg = getSyncPcrt();
         this.listener.onMessage(session, syncMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             //check reported LSP is empty, LSP state from previous session was purged
@@ -107,7 +107,7 @@ public class IncrementalSynchronizationProcedureTest extends AbstractPCEPSession
         //report LSP3 + LSP-DB version number 4
         final Pcrpt pcRpt3 = getPcrpt(3L,"testthird");
         this.listener.onMessage(session, pcRpt3);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             assertEquals(3,pcc.getReportedLsp().size());
index 542416e71ec01554d7d425f9bea574971e453c82..e4060ea870b346171c7f30aeeb57d062f3460174 100644 (file)
@@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
@@ -70,7 +70,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         final Pcrpt pcRpt = getPcrt();
         this.listener.onMessage(this.session, pcRpt);
 
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             assertFalse(pcc.getReportedLsp().isEmpty());
             return pcc;
@@ -78,7 +78,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
 
         //PCEP Trigger Full Resync
         this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).build());
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
             return pcc;
         });
@@ -86,14 +86,14 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         //end of sync
         final Pcrpt syncMsg = getSyncMsg();
         this.listener.onMessage(this.session, syncMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             return pcc;
         });
 
         this.listener.onMessage(this.session, pcRpt);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(1, pcc.getReportedLsp().size());
             return pcc;
         });
@@ -103,7 +103,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         this.listener.onMessage(this.session, pcRpt);
         //end of sync
         this.listener.onMessage(this.session, syncMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             //check reported LSP is not empty, Stale LSP state were purged
@@ -122,7 +122,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         //report LSP + LSP-DB version number
         final Pcrpt pcRpt = getPcrt();
         this.listener.onMessage(this.session, pcRpt);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             final List<ReportedLsp> reportedLspPcc = pcc.getReportedLsp();
             assertFalse(reportedLspPcc.isEmpty());
@@ -131,14 +131,14 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
 
         //Trigger Full Resync
         this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
             assertFalse(pcc.getReportedLsp().isEmpty());
             return pcc;
         });
 
         this.listener.onMessage(this.session, pcRpt);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertFalse(pcc.getReportedLsp().isEmpty());
             return pcc;
         });
@@ -146,7 +146,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         //sync rpt + LSP-DB
         final Pcrpt syncMsg = getSyncMsg();
         this.listener.onMessage(this.session, syncMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             //check reported LSP
@@ -157,7 +157,7 @@ public class PCEPTriggeredReSynchronizationProcedureTest extends AbstractPCEPSes
         //Trigger Full Resync
         this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
         this.listener.onMessage(this.session, syncMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             //check reported LSP
index 7c177a6928462d78cd7ac013d33912076952ef63..dbeb9f01ea8537647b40488d9d0449f11d249ed2 100644 (file)
@@ -13,7 +13,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
@@ -67,7 +67,7 @@ public class PCETriggeredInitialSyncProcedureTest extends AbstractPCEPSessionTes
         final PCEPSession session = getPCEPSession(getOpen(localDbVersion, Boolean.FALSE), getOpen(localDbVersion2, Boolean.FALSE));
         this.listener.onSessionUp(session);
 
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - not synchronized and TriggeredInitialSync state
             assertEquals(PccSyncState.TriggeredInitialSync, pcc.getStateSync());
             return pcc;
@@ -76,7 +76,7 @@ public class PCETriggeredInitialSyncProcedureTest extends AbstractPCEPSessionTes
         //sync rpt + LSP-DB
         final Pcrpt syncMsg = getsyncMsg();
         this.listener.onMessage(session, syncMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             //check reported LSP is empty, LSP state from previous session was purged
@@ -88,7 +88,7 @@ public class PCETriggeredInitialSyncProcedureTest extends AbstractPCEPSessionTes
         final Pcrpt pcRpt = getPcrpt();
         this.listener.onMessage(session, pcRpt);
 
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertFalse(pcc.getReportedLsp().isEmpty());
             return pcc;
         });
index 8a8e8f2ab5f8528bc2da16cf072dbf5289fdf9ad..6d26b01936069c50715800e6169b9dafcba056f7 100644 (file)
@@ -13,7 +13,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import com.google.common.base.Optional;
 import java.math.BigInteger;
@@ -69,7 +69,7 @@ public class StateSynchronizationAvoidanceProcedureTest extends
                             new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(BigInteger.ONE).build()).build()).build()).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(1L)), null);
         this.listener.onMessage(session, pcRpt);
         //check topology
-        readData(getDataBroker(), this.pathComputationClientIId.builder().augmentation(PathComputationClient1.class)
+        readDataOperational(getDataBroker(), this.pathComputationClientIId.builder().augmentation(PathComputationClient1.class)
             .child(LspDbVersion.class).build(), dbVersion -> {
             assertEquals(1L, dbVersion.getLspDbVersionValue().longValue());
             return dbVersion;
@@ -77,11 +77,11 @@ public class StateSynchronizationAvoidanceProcedureTest extends
 
         //drop session
         this.listener.onSessionDown(session, new IllegalStateException());
-        //check topology - node is persisted
-        readData(getDataBroker(), TOPO_IID, topology -> {
+        readDataOperational(getDataBroker(), TOPO_IID, topology -> {
             assertFalse(topology.getNode().isEmpty());
             return topology;
         });
+        //check topology - node is persisted
     }
 
     @Test
@@ -91,7 +91,7 @@ public class StateSynchronizationAvoidanceProcedureTest extends
         final PCEPSession session = getPCEPSession(getOpen(lspDbVersion), getOpen(lspDbVersion));
         this.listener.onSessionUp(session);
         //check node - synchronized
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             return pcc;
         });
@@ -114,7 +114,7 @@ public class StateSynchronizationAvoidanceProcedureTest extends
             .setPlspId(new PlspId(1L)).setSync(true).setRemove(false).setOperational(OperationalStatus.Active)
             .build(), Optional.absent(), createPath(Collections.emptyList()));
         this.listener.onMessage(session, pcRpt);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertFalse(pcc.getReportedLsp().isEmpty());
             return pcc;
         });
@@ -128,7 +128,7 @@ public class StateSynchronizationAvoidanceProcedureTest extends
         session = getPCEPSession(getOpen(localDbVersion), getOpen(null));
         this.listener.onSessionUp(session);
 
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - not synchronized
             assertEquals(PccSyncState.InitialResync, pcc.getStateSync());
             //check reported LSP - persisted from previous session
@@ -147,7 +147,7 @@ public class StateSynchronizationAvoidanceProcedureTest extends
             true, false), Optional.absent(),
                 createPath(Collections.emptyList()));
         this.listener.onMessage(session, syncMsg);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             //check node - synchronized
             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
             //check reported LSP is empty, LSP state from previous session was purged
index 46e194e3be39f2f22ec2a2c65c2090349943df47..06dc9425cdb1fabc8a06443e5df95345617d664d 100755 (executable)
@@ -17,8 +17,8 @@ import static org.junit.Assert.fail;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs;
-import static org.opendaylight.protocol.util.CheckUtil.checkNull;
-import static org.opendaylight.protocol.util.CheckUtil.readData;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
@@ -146,7 +146,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(),
             Optional.of(MsgBuilderUtil.createSrp(0L)), null);
         this.listener.onMessage(this.session, esm);
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(this.testAddress, pcc.getIpAddress().getIpv4Address().getValue());
             // reported lsp so far empty, has not received response (PcRpt) yet
             assertTrue(pcc.getReportedLsp().isEmpty());
@@ -155,7 +155,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
 
         this.listener.onMessage(this.session, pcRpt);
         // check created lsp
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(1, pcc.getReportedLsp().size());
             final ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
             assertEquals(this.TUNNEL_NAME, reportedLsp.getName());
@@ -200,7 +200,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         this.listener.onMessage(this.session, pcRpt2);
 
         //check updated lsp
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(1, pcc.getReportedLsp().size());
             final ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
             assertEquals(this.TUNNEL_NAME, reportedLsp.getName());
@@ -254,7 +254,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         this.listener.onMessage(this.session, pcRpt3);
 
         // check if lsp was removed
-        readData(getDataBroker(), this.pathComputationClientIId, pcc -> {
+        readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
             assertEquals(0, pcc.getReportedLsp().size());
             return pcc;
         });
@@ -345,7 +345,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         verify(this.listenerReg, times(0)).close();
         this.listener.onSessionUp(this.session);
         // verify the session was NOT added to topology
-        checkNull(getDataBroker(), TOPO_IID);
+        checkNotPresentOperational(getDataBroker(), TOPO_IID);
         // still, the session should not be registered and thus close() is never called
         verify(this.listenerReg, times(0)).close();
         // send request
@@ -371,7 +371,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
             .setRemove(false).setOperational(OperationalStatus.Active).build(),
             Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
         this.listener.onMessage(this.session, pcRpt);
-        readData(getDataBroker(), TOPO_IID, topology -> {
+        readDataOperational(getDataBroker(), TOPO_IID, topology -> {
             assertEquals(1, topology.getNode().size());
             return topology;
         });
@@ -379,7 +379,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
         // node should be removed after termination
         this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.UNKNOWN));
         verify(this.listenerReg, times(1)).close();
-        checkNull(getDataBroker(), this.pathComputationClientIId);
+        checkNotPresentOperational(getDataBroker(), this.pathComputationClientIId);
     }
 
     @Test
@@ -395,7 +395,7 @@ public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTe
             .build();
         this.listener.onSessionUp(this.session);
         this.listener.onMessage(this.session, rptmsg);
-        readData(getDataBroker(), TOPO_IID, node -> {
+        readDataOperational(getDataBroker(), TOPO_IID, node -> {
             assertFalse(node.getNode().isEmpty());
             return node;
         });
index 8ead786bcdfea7387afc4d12e9ffdc1ddc645dd2..acbd2cccefbe7415244aa0d2a1590f919befd4c0 100644 (file)
         </dependency>
 
         <!-- Testing dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>testtool-util</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
index 6611261790882c50c875988c57fe6603cff0f14c..600e44a505d4f33ce113ee79b7e8469a38ff0124 100644 (file)
@@ -8,14 +8,17 @@
 
 package org.opendaylight.bgpcep.pcep.tunnel.provider;
 
-import com.google.common.base.Optional;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
+
 import com.google.common.collect.Lists;
+import java.util.Collections;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -74,40 +77,50 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
     private static final String LSP2_NAME = "lsp2";
     private static final long LSP2_ID = 2;
 
-    private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
-    private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
+    private static final InstanceIdentifier<Topology> PCEP_TOPO_IID = InstanceIdentifier.builder(NetworkTopology.class)
+        .child(Topology.class, new TopologyKey(PCEP_TOPOLOGY_ID)).build();
+    private static final InstanceIdentifier<Topology> TUNNEL_TOPO_IID = InstanceIdentifier.
+        builder(NetworkTopology.class).child(Topology.class, new TopologyKey(TUNNEL_TOPOLOGY_ID)).build();
 
     private ListenerRegistration<NodeChangedListener> listenerRegistration;
 
     @Before
     public void setUp() throws TransactionCommitFailedException {
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID, new TopologyBuilder().setKey(new TopologyKey(PCEP_TOPOLOGY_ID)).setNode(Lists.<Node>newArrayList()).setTopologyId(PCEP_TOPOLOGY_ID).build(), true);
-        wTx.put(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID, new TopologyBuilder().setKey(new TopologyKey(TUNNEL_TOPOLOGY_ID)).setTopologyId(TUNNEL_TOPOLOGY_ID).build(), true);
+        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID, new TopologyBuilder()
+            .setKey(new TopologyKey(PCEP_TOPOLOGY_ID)).setNode(Lists.newArrayList())
+            .setTopologyId(PCEP_TOPOLOGY_ID).build(), true);
+        wTx.put(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID, new TopologyBuilder()
+            .setKey(new TopologyKey(TUNNEL_TOPOLOGY_ID)).setTopologyId(TUNNEL_TOPOLOGY_ID).build(), true);
         wTx.submit().checkedGet();
-        final NodeChangedListener nodeListener = new NodeChangedListener(getDataBroker(), PCEP_TOPOLOGY_ID, TUNNEL_TOPO_IID);
-        this.listenerRegistration = getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.child(Node.class)), nodeListener);
+        final NodeChangedListener nodeListener = new NodeChangedListener(getDataBroker(),
+            PCEP_TOPOLOGY_ID, TUNNEL_TOPO_IID);
+        this.listenerRegistration = getDataBroker().registerDataTreeChangeListener(new DataTreeIdentifier<>(
+            LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.child(Node.class)), nodeListener);
     }
 
     @Test
     public void testNodeChangedListener() throws ReadFailedException, TransactionCommitFailedException {
         // add node -> create two nodes with TPs and link
         createNode(NODE1_ID, NODE1_IPV4, LSP1_NAME, LSP1_ID, NODE2_IPV4);
-        final Topology tunnelTopo = readTunnelTopology().get();
-        Assert.assertEquals(2, tunnelTopo.getNode().size());
+        final Topology tunnelTopo = readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, tunnelTopo1 -> {
+            assertNotNull(tunnelTopo1.getNode());
+            assertEquals(2, tunnelTopo1.getNode().size());
+            return tunnelTopo1;
+        });
 
         final NodeId srcId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE1_IPV4)));
         final NodeId dstId = new NodeId("ip://" + new IpAddress(new Ipv4Address(NODE2_IPV4)));
 
-        Node dst;
-        Node src;
+        final Node dst;
+        final Node src;
 
         if (tunnelTopo.getNode().get(0).getNodeId().equals(srcId)) {
             src = tunnelTopo.getNode().get(0);
-            dst =  tunnelTopo.getNode().get(1);
+            dst = tunnelTopo.getNode().get(1);
         } else {
             src = tunnelTopo.getNode().get(1);
-            dst =  tunnelTopo.getNode().get(0);
+            dst = tunnelTopo.getNode().get(0);
         }
 
         Assert.assertEquals(srcId, src.getNodeId());
@@ -136,41 +149,47 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
 
         // update second node -> adds supporting node and second link
         createNode(NODE2_ID, NODE2_IPV4, LSP2_NAME, LSP2_ID, NODE1_IPV4);
-        final Topology updatedNodeTopo = readTunnelTopology().get();
-        Assert.assertEquals(2, updatedNodeTopo.getNode().size());
-
-        Node updatedNode;
-
-        if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
-            updatedNode = updatedNodeTopo.getNode().get(1);
-        } else {
-            updatedNode = updatedNodeTopo.getNode().get(0);
-        }
-
-        Assert.assertEquals(1, updatedNode.getSupportingNode().size());
-        final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
-        Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
-
-        Assert.assertEquals(2, updatedNodeTopo.getLink().size());
-
-        Link link2;
-        if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
-            link2 = updatedNodeTopo.getLink().get(1);
-        } else {
-            link2 = updatedNodeTopo.getLink().get(0);
-        }
-
-        Assert.assertEquals(dstId, link2.getSource().getSourceNode());
-        Assert.assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
-        Assert.assertEquals(srcId, link2.getDestination().getDestNode());
-        Assert.assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
+        readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
+            assertNotNull(updatedNodeTopo.getNode());
+            Assert.assertEquals(2, updatedNodeTopo.getNode().size());
+            final Node updatedNode;
+            if (updatedNodeTopo.getNode().get(0).getNodeId().equals(srcId)) {
+                updatedNode = updatedNodeTopo.getNode().get(1);
+            } else {
+                updatedNode = updatedNodeTopo.getNode().get(0);
+            }
+
+            assertNotNull(updatedNode.getSupportingNode());
+            Assert.assertEquals(1, updatedNode.getSupportingNode().size());
+            final SupportingNode sNode2 = updatedNode.getSupportingNode().get(0);
+            Assert.assertEquals(NODE2_ID, sNode2.getNodeRef());
+            Assert.assertEquals(2, updatedNodeTopo.getLink().size());
+            return updatedNodeTopo;
+
+        });
+
+        readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, updatedNodeTopo -> {
+            final Link link2;
+            if (updatedNodeTopo.getLink().get(0).getSource().getSourceNode().equals(srcId)) {
+                link2 = updatedNodeTopo.getLink().get(1);
+            } else {
+                link2 = updatedNodeTopo.getLink().get(0);
+            }
+            assertEquals(dstId, link2.getSource().getSourceNode());
+            assertEquals(dstNodeTpId, link2.getSource().getSourceTp());
+            assertEquals(srcId, link2.getDestination().getDestNode());
+            assertEquals(srcNodeTpId, link2.getDestination().getDestTp());
+            return updatedNodeTopo;
+        });
 
         // remove nodes -> remove link
         removeNode(NODE1_ID);
         removeNode(NODE2_ID);
-        final Topology removedNodeTopo = readTunnelTopology().get();
-        Assert.assertEquals(0, removedNodeTopo.getNode().size());
-        Assert.assertEquals(0, removedNodeTopo.getLink().size());
+        readDataOperational(getDataBroker(), TUNNEL_TOPO_IID, removedNodeTopo -> {
+            assertEquals(0, removedNodeTopo.getNode().size());
+            assertEquals(0, removedNodeTopo.getLink().size());
+            return removedNodeTopo;
+        });
     }
 
     @After
@@ -178,20 +197,30 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
         this.listenerRegistration.close();
     }
 
-    private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId, final String dstIpv4Address) throws TransactionCommitFailedException {
+    private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId,
+        final String dstIpv4Address) throws TransactionCommitFailedException {
         final NodeBuilder nodeBuilder = new NodeBuilder();
         nodeBuilder.setKey(new NodeKey(nodeId));
         nodeBuilder.setNodeId(nodeId);
         final PathBuilder pathBuilder = new PathBuilder();
         pathBuilder.setKey(new PathKey(new LspId(lspId)));
-        pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(new Bandwidth(new byte[] {0x00, 0x00, (byte) 0xff, (byte) 0xff})).build());
-        pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address)).build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
-        final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(Lists.newArrayList(pathBuilder.build())).build();
+        pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(
+            new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff})).build());
+        pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder()
+            .setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(
+                new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(
+                    new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address))
+                    .build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
+        final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(
+            Collections.singletonList(pathBuilder.build())).build();
         final Node1Builder node1Builder = new Node1Builder();
-        node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address))).build());
+        node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized)
+            .setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address)))
+            .build());
         nodeBuilder.addAugmentation(Node1.class, node1Builder.build());
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
+        wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class,
+            new NodeKey(nodeId)).build(), nodeBuilder.build());
         wTx.submit().checkedGet();
     }
 
@@ -200,9 +229,4 @@ public class NodeChangedListenerTest extends AbstractDataBrokerTest {
         wTx.delete(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build());
         wTx.submit().checkedGet();
     }
-
-    private Optional<Topology> readTunnelTopology() throws ReadFailedException {
-        final ReadTransaction rTx = getDataBroker().newReadOnlyTransaction();
-        return rTx.read(LogicalDatastoreType.OPERATIONAL, TUNNEL_TOPO_IID).checkedGet();
-    }
 }
index 1bec9ff540778ca8aea7a96f289219bdede5cc79..0fc0d821c9d464b1d2aef93017ea9eb1f22bab2a 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.bgpcep.programming.impl;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -18,7 +17,8 @@ import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
-import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.checkPresentOperational;
 
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -27,7 +27,6 @@ import io.netty.util.Timer;
 import java.math.BigInteger;
 import java.util.List;
 import java.util.Optional;
-import java.util.concurrent.ExecutionException;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -37,13 +36,12 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.bgpcep.programming.NanotimeUtil;
 import org.opendaylight.bgpcep.programming.spi.Instruction;
 import org.opendaylight.bgpcep.programming.spi.SchedulerException;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CancelInstructionInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.CleanInstructionsInput;
@@ -61,6 +59,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programm
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.DetailsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepUpdateTunnelInput;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
@@ -117,20 +116,22 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         final SubmitInstructionInput mockedSubmit = getMockedSubmitInstructionInput("mockedSubmit");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit);
 
-        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit.getId())));
+        checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
 
         // assert Schedule to executor
         this.mockedExecutorWrapper.assertSubmittedTasksSize(1);
 
         // assert Notification
         this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit.getId(), InstructionStatus.Scheduled);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit.getId(),
+            InstructionStatus.Scheduled);
     }
 
     @Test
     public void testScheduleDependingInstruction() throws Exception {
         this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit1"));
-        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+            "mockedSubmit1");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
 
         this.mockedExecutorWrapper.assertSubmittedTasksSize(2);
@@ -142,7 +143,8 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
     @Test
     public void testScheduleDependingInstructionToFail() throws Exception {
         try {
-            this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit", "dep1"));
+            this.testedProgrammingService.scheduleInstruction(getMockedSubmitInstructionInput("mockedSubmit",
+                "dep1"));
         } catch (final SchedulerException e) {
             assertThat(e.getMessage(), containsString("Unknown dependency ID"));
             this.mockedNotificationServiceWrapper.assertNotificationsCount(0);
@@ -155,54 +157,61 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
     public void testCancelInstruction() throws Exception {
         final SubmitInstructionInput mockedSubmit = getMockedSubmitInstructionInput("mockedSubmit");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit);
-
-        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit.getId())));
+        checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
 
         final CancelInstructionInput mockedCancel = getCancelInstruction("mockedSubmit");
         this.testedProgrammingService.cancelInstruction(mockedCancel);
 
-        assertTrue(assertInstructionExists(mockedSubmit.getId()));
-
+        checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit.getId()));
         this.mockedExecutorWrapper.assertSubmittedTasksSize(2);
 
         this.mockedNotificationServiceWrapper.assertNotificationsCount(2);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit.getId(), InstructionStatus.Cancelled);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit.getId(),
+            InstructionStatus.Cancelled);
     }
 
     @Test
     public void testCancelDependantInstruction() throws Exception {
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
-        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+            "mockedSubmit1");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
-        final SubmitInstructionInput mockedSubmit3 = getMockedSubmitInstructionInput("mockedSubmit3", "mockedSubmit1", "mockedSubmit2");
+        final SubmitInstructionInput mockedSubmit3 = getMockedSubmitInstructionInput("mockedSubmit3",
+            "mockedSubmit1", "mockedSubmit2");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit3);
 
         this.testedProgrammingService.cancelInstruction(getCancelInstruction("mockedSubmit1"));
 
         this.mockedNotificationServiceWrapper.assertNotificationsCount(1 /*First Scheduled*/+ 3 /*First and all dependencies cancelled*/);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit1.getId(), InstructionStatus.Scheduled);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Cancelled);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit2.getId(), InstructionStatus.Cancelled);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit3.getId(), InstructionStatus.Cancelled);
-
-        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit1.getId())));
-        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit2.getId())));
-        checkEquals(()-> assertTrue(assertInstructionExists(mockedSubmit3.getId())));
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(0, mockedSubmit1.getId(),
+            InstructionStatus.Scheduled);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+            InstructionStatus.Cancelled);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit2.getId(),
+            InstructionStatus.Cancelled);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit3.getId(),
+            InstructionStatus.Cancelled);
+
+        checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit1.getId()));
+        checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit2.getId()));
+        checkPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit3.getId()));
     }
 
     @Test
     public void testCleanInstructions() throws Exception {
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
-        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+            "mockedSubmit1");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
 
         final CleanInstructionsInputBuilder cleanInstructionsInputBuilder = new CleanInstructionsInputBuilder();
         final CleanInstructionsInput cleanInstructionsInput = cleanInstructionsInputBuilder.setId(
                 Lists.newArrayList(mockedSubmit1.getId(), mockedSubmit2.getId())).build();
 
-        ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput = this.testedProgrammingService.cleanInstructions(cleanInstructionsInput);
+        ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput = this.testedProgrammingService
+            .cleanInstructions(cleanInstructionsInput);
 
         assertCleanInstructionOutput(cleanedInstructionOutput, 2);
 
@@ -211,12 +220,13 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         cleanedInstructionOutput = this.testedProgrammingService.cleanInstructions(cleanInstructionsInput);
         assertCleanInstructionOutput(cleanedInstructionOutput, 0);
 
-        checkEquals(()-> assertFalse(assertInstructionExists(mockedSubmit1.getId())));
-        checkEquals(()-> assertFalse(assertInstructionExists(mockedSubmit2.getId())));
+        checkNotPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit1.getId()));
+        checkNotPresentOperational(getDataBroker(), buildInstructionIID(mockedSubmit2.getId()));
     }
 
-    private void assertCleanInstructionOutput(final ListenableFuture<RpcResult<CleanInstructionsOutput>> cleanedInstructionOutput,
-            final int unflushedCount) throws InterruptedException, java.util.concurrent.ExecutionException {
+    private void assertCleanInstructionOutput(final ListenableFuture<RpcResult<CleanInstructionsOutput>>
+        cleanedInstructionOutput, final int unflushedCount) throws InterruptedException,
+        java.util.concurrent.ExecutionException {
         if (unflushedCount == 0) {
             final List<InstructionId> unflushed = cleanedInstructionOutput.get().getResult().getUnflushed();
             assertTrue(unflushed == null || unflushed.isEmpty());
@@ -230,17 +240,20 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
     public void testCloseProgrammingService() throws Exception {
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
-        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+            "mockedSubmit1");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
 
         this.testedProgrammingService.close();
 
-        this.mockedNotificationServiceWrapper.assertNotificationsCount(1/* First scheduled */+ 2/* Both cancelled at close */);
+        this.mockedNotificationServiceWrapper
+            .assertNotificationsCount(1/* First scheduled */+ 2/* Both cancelled at close */);
     }
 
     @Test(timeout = 30 * 1000)
     public void testTimeoutWhileScheduledTransaction() throws Exception {
-        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
+            INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
         final Nanotime current = NanotimeUtil.currentTime();
         final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
 
@@ -252,15 +265,15 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
 
         future.get();
 
-        Thread.sleep(2 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS * 1000);
-
         this.mockedNotificationServiceWrapper.assertNotificationsCount(2);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Cancelled);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+            InstructionStatus.Cancelled);
     }
 
     @Test(timeout = 30 * 1000)
     public void testTimeoutWhileSuccessfulTransaction() throws Exception {
-        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
+            INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
         final Nanotime current = NanotimeUtil.currentTime();
         final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
 
@@ -274,17 +287,18 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         i.checkedExecutionStart();
         i.executionCompleted(InstructionStatus.Successful, getDetails());
 
-        Thread.sleep(2 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS * 1000);
-
         this.mockedNotificationServiceWrapper.assertNotificationsCount(3);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Executing);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(), InstructionStatus.Successful);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+            InstructionStatus.Executing);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+            InstructionStatus.Successful);
         // Timeout in success should not do anything
     }
 
     @Test(timeout = 30 * 1000)
     public void testTimeoutWhileExecutingWithDependenciesTransaction() throws Exception {
-        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
+        final BigInteger deadlineOffset = BigInteger.valueOf(1000L * 1000 * 1000 *
+            INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS /* seconds */);
         final Nanotime current = NanotimeUtil.currentTime();
         final Nanotime deadlineNano = new Nanotime(current.getValue().add(deadlineOffset));
 
@@ -292,7 +306,8 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         final SubmitInstructionInput mockedSubmit1 = getMockedSubmitInstructionInput("mockedSubmit1", deadline);
         final ListenableFuture<Instruction> future = this.testedProgrammingService.scheduleInstruction(mockedSubmit1);
 
-        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2", "mockedSubmit1");
+        final SubmitInstructionInput mockedSubmit2 = getMockedSubmitInstructionInput("mockedSubmit2",
+            "mockedSubmit1");
         this.testedProgrammingService.scheduleInstruction(mockedSubmit2);
 
         this.mockedNotificationServiceWrapper.assertNotificationsCount(1);
@@ -300,12 +315,13 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         final Instruction i = future.get();
         i.checkedExecutionStart();
 
-        Thread.sleep(2 * INSTRUCTION_DEADLINE_OFFSET_IN_SECONDS * 1000);
-
         this.mockedNotificationServiceWrapper.assertNotificationsCount(4);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Executing);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(), InstructionStatus.Unknown);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(), InstructionStatus.Cancelled);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+            InstructionStatus.Executing);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+            InstructionStatus.Unknown);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(),
+            InstructionStatus.Cancelled);
     }
 
     // TODO test deadline with state Queued
@@ -325,17 +341,22 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         i.executionCompleted(InstructionStatus.Successful, getDetails());
 
         this.mockedNotificationServiceWrapper.assertNotificationsCount(4);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(), InstructionStatus.Executing);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(), InstructionStatus.Successful);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(), InstructionStatus.Scheduled);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(1, mockedSubmit1.getId(),
+            InstructionStatus.Executing);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(2, mockedSubmit1.getId(),
+            InstructionStatus.Successful);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(3, mockedSubmit2.getId(),
+            InstructionStatus.Scheduled);
 
         i = future2.get();
         i.checkedExecutionStart();
         i.executionCompleted(InstructionStatus.Successful, getDetails());
 
         this.mockedNotificationServiceWrapper.assertNotificationsCount(6);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(4, mockedSubmit2.getId(), InstructionStatus.Executing);
-        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(5, mockedSubmit2.getId(), InstructionStatus.Successful);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(4, mockedSubmit2.getId(),
+            InstructionStatus.Executing);
+        this.mockedNotificationServiceWrapper.assertInstructionStatusChangedNotification(5, mockedSubmit2.getId(),
+            InstructionStatus.Successful);
     }
 
     private Details getDetails() {
@@ -346,7 +367,8 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         return getMockedSubmitInstructionInput(id, Optional.empty(), dependencyIds);
     }
 
-    private SubmitInstructionInput getMockedSubmitInstructionInput(final String id, final Optional<Nanotime> deadline, final String... dependencyIds) {
+    private SubmitInstructionInput getMockedSubmitInstructionInput(final String id, final Optional<Nanotime> deadline,
+        final String... dependencyIds) {
         final SubmitInstructionInput mockedSubmitInstruction = mock(SubmitInstructionInput.class);
 
         doReturn(PcepUpdateTunnelInput.class).when(mockedSubmitInstruction).getImplementedInterface();
@@ -357,7 +379,8 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
 
         doReturn(dependencies).when(mockedSubmitInstruction).getPreconditions();
         doReturn(getInstructionId(id)).when(mockedSubmitInstruction).getId();
-        doReturn(deadline.isPresent() ? deadline.get() : new Nanotime(BigInteger.valueOf(Long.MAX_VALUE))).when(mockedSubmitInstruction).getDeadline();
+        doReturn(deadline.isPresent() ? deadline.get() : new Nanotime(BigInteger.valueOf(Long.MAX_VALUE)))
+            .when(mockedSubmitInstruction).getDeadline();
         return mockedSubmitInstruction;
     }
 
@@ -371,14 +394,10 @@ public class ProgrammingServiceImplTest extends AbstractDataBrokerTest {
         return new InstructionId(id);
     }
 
-    private boolean assertInstructionExists(final InstructionId id) {
-        try {
-            return getDataBroker().newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL,
-                InstanceIdentifier.builder(InstructionsQueue.class, new InstructionsQueueKey(INSTRUCTIONS_QUEUE_KEY))
-                    .build().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.queue.Instruction.class,
-                    new InstructionKey(id))).get().isPresent();
-        } catch (InterruptedException | ExecutionException e) {
-            return false;
-        }
+    private KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.
+        rev150720.instruction.queue.Instruction, InstructionKey> buildInstructionIID(final InstructionId id) {
+        return InstanceIdentifier.builder(InstructionsQueue.class, new InstructionsQueueKey(INSTRUCTIONS_QUEUE_KEY))
+            .build().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720
+                .instruction.queue.Instruction.class, new InstructionKey(id));
     }
 }
index bd87f704790587835259cf4c9c00d13b0788cb44..2bc17aa99dddc3f5cbe3b374da0c8cdae1b5ec6f 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.protocol.util;
 
+import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
+import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
+
 import com.google.common.base.Optional;
 import com.google.common.base.Stopwatch;
 import com.google.common.base.Verify;
@@ -40,13 +43,23 @@ public final class CheckUtil {
         Verify.verify(future.isSuccess());
     }
 
-    public static <R, T extends DataObject> R readData(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
+    public static <R, T extends DataObject> R readDataOperational(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
+        final Function<T, R> function) throws ReadFailedException {
+        return readData(dataBroker, OPERATIONAL, iid, function);
+    }
+
+    public static <R, T extends DataObject> R readDataConfiguration(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
         final Function<T, R> function) throws ReadFailedException {
+        return readData(dataBroker, CONFIGURATION, iid, function);
+    }
+
+    private static <R, T extends DataObject> R readData(final DataBroker dataBroker, final LogicalDatastoreType ldt,
+        final InstanceIdentifier<T> iid, final Function<T, R> function) throws ReadFailedException {
         AssertionError lastError = null;
         final Stopwatch sw = Stopwatch.createStarted();
         while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) {
             try (final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
-                final Optional<T> data = tx.read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet();
+                final Optional<T> data = tx.read(ldt, iid).checkedGet();
                 if (data.isPresent()) {
                     try {
                         return function.apply(data.get());
@@ -60,18 +73,33 @@ public final class CheckUtil {
         throw lastError;
     }
 
-    public static <T extends DataObject> T checkPresent(final DataBroker dataBroker, final InstanceIdentifier<T> iid)
+    public static <T extends DataObject> T checkPresentOperational(final DataBroker dataBroker, final InstanceIdentifier<T> iid)
         throws ReadFailedException {
-        return readData(dataBroker, iid, bgpRib -> bgpRib);
+        return readData(dataBroker, OPERATIONAL, iid, bgpRib -> bgpRib);
     }
 
-    public static <T extends DataObject> void checkNull(final DataBroker dataBroker, final InstanceIdentifier<T> iid)
-        throws ReadFailedException {
+    public static <T extends DataObject> T checkPresentConfiguration(final DataBroker dataBroker,
+        final InstanceIdentifier<T> iid) throws ReadFailedException {
+        return readData(dataBroker, CONFIGURATION, iid, bgpRib -> bgpRib);
+    }
+
+    public static <T extends DataObject> void checkNotPresentOperational(final DataBroker dataBroker,
+        final InstanceIdentifier<T> iid) throws ReadFailedException {
+        checkNotPresent(dataBroker, OPERATIONAL, iid);
+    }
+
+    public static <T extends DataObject> void checkNotPresentConfiguration(final DataBroker dataBroker,
+        final InstanceIdentifier<T> iid) throws ReadFailedException {
+        checkNotPresent(dataBroker, CONFIGURATION, iid);
+    }
+
+    private static <T extends DataObject> void checkNotPresent(final DataBroker dataBroker,
+        final LogicalDatastoreType ldt, final InstanceIdentifier<T> iid) throws ReadFailedException {
         AssertionError lastError = null;
         final Stopwatch sw = Stopwatch.createStarted();
         while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
             try (final ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
-                final com.google.common.base.Optional<T> data = tx.read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet();
+                final com.google.common.base.Optional<T> data = tx.read(ldt, iid).checkedGet();
                 try {
                     assert !data.isPresent();
                     return;
index 14aa473c6896a34c1af60585c6013e8d62761960..33c74e7a9de86a22176ce784fa17169c143ef0a2 100644 (file)
@@ -12,6 +12,11 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.when;
+import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
+import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentOperational;
+import static org.opendaylight.protocol.util.CheckUtil.checkReceivedMessages;
+import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
+import static org.opendaylight.protocol.util.CheckUtil.waitFutureSuccess;
 
 import com.google.common.base.Optional;
 import com.google.common.base.VerifyException;
@@ -68,60 +73,60 @@ public class CheckUtilTest {
     }
 
     @Test(expected = VerifyException.class)
-    public void waitFutureSuccessFail() throws Exception {
+    public void testWaitFutureSuccessFail() throws Exception {
         when(this.future.isDone()).thenReturn(false);
         doReturn(this.future).when(this.future).addListener(any());
-        CheckUtil.waitFutureSuccess(this.future);
+        waitFutureSuccess(this.future);
     }
 
     @Test
-    public void waitFutureSuccess() throws Exception {
+    public void testWaitFutureSuccess() throws Exception {
         when(this.future.isSuccess()).thenReturn(true);
         doAnswer(invocation -> {
             invocation.getArgumentAt(0, GenericFutureListener.class).operationComplete(CheckUtilTest.this.future);
             return CheckUtilTest.this.future;
         }).when(this.future).addListener(any());
-        CheckUtil.waitFutureSuccess(this.future);
+        waitFutureSuccess(this.future);
     }
 
     @Test(expected = NullPointerException.class)
-    public void readDataNull() throws Exception {
+    public void testReadDataNull() throws Exception {
         doReturn(false).when(this.opt).isPresent();
         final InstanceIdentifier instanceIdentifier = null;
-        CheckUtil.readData(this.dataBroker, instanceIdentifier, test -> false);
+        readDataOperational(this.dataBroker, instanceIdentifier, test -> false);
     }
 
     @Test(expected = AssertionError.class)
-    public void readDataNotEquall() throws Exception {
+    public void testReadDataNotEquall() throws Exception {
         doReturn(true).when(this.opt).isPresent();
         doReturn(false).when(this.mockInterface).getResult();
-        CheckUtil.readData(this.dataBroker, this.instanceIdentifier, test -> {
+        readDataOperational(this.dataBroker, this.instanceIdentifier, test -> {
             assertTrue(test.getResult());
             return test;
         });
     }
 
     @Test(expected = AssertionError.class)
-    public void checkNull() throws Exception {
+    public void testCheckNotPresent() throws Exception {
         doReturn(true).when(this.opt).isPresent();
-        CheckUtil.checkNull(this.dataBroker, this.instanceIdentifier);
+        checkNotPresentOperational(this.dataBroker, this.instanceIdentifier);
     }
 
     @Test(expected = AssertionError.class)
-    public void checkEquals() throws Exception {
-        CheckUtil.checkEquals(()-> assertTrue(false));
+    public void testCheckEquals() throws Exception {
+        checkEquals(()-> assertTrue(false));
     }
 
     @Test(expected = AssertionError.class)
-    public void checkReceivedMessagesNotEqual() throws Exception {
+    public void testCheckReceivedMessagesNotEqual() throws Exception {
         doReturn(0).when(this.listenerCheck).getListMessageSize();
-        CheckUtil.checkReceivedMessages(this.listenerCheck, 1);
+        checkReceivedMessages(this.listenerCheck, 1);
     }
 
     @Test
-    public void checkReceivedMessagesEqual() throws Exception {
+    public void testCheckReceivedMessagesEqual() throws Exception {
         doReturn(1).when(this.listenerCheck).getListMessageSize();
-        CheckUtil.checkReceivedMessages(this.listenerCheck, 1);
+        checkReceivedMessages(this.listenerCheck, 1);
     }
 
     private interface MockInterface extends DataObject {