Bump upstreams
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / config / AppPeerTest.java
index 91325e1a21c54e2dd148d07556f103e0f35546fc..be82ca643a9c8aeaef495e16e0745aa874c2f826 100644 (file)
@@ -5,61 +5,78 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.bgp.rib.impl.config;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.verify;
 import static org.mockito.internal.verification.VerificationModeFactory.times;
 
+import java.util.concurrent.ExecutionException;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPStateCollector;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instance.protocol.NeighborPeerGroupConfigBuilder;
 
 public class AppPeerTest extends AbstractConfig {
-    private static final AppPeer APP_PEER = new AppPeer();
+    private final AppPeer appPeer = new AppPeer(new BGPStateCollector());
 
+    private final Neighbor neighbor = new NeighborBuilder()
+        .setConfig(new ConfigBuilder()
+            .addAugmentation(new NeighborPeerGroupConfigBuilder()
+                .setPeerGroup(OpenConfigMappingUtil.APPLICATION_PEER_GROUP_NAME)
+                .build())
+            .build())
+        .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
 
+    @Override
     @Before
     public void setUp() throws Exception {
         super.setUp();
-        Mockito.doReturn(true).when(this.mappingService).isApplicationPeer(any(Neighbor.class));
     }
 
     @Test
-    public void testAppPeer() throws Exception {
-        final Neighbor neighbor = new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
-        APP_PEER.start(this.rib, neighbor, this.mappingService, this.configurationWriter);
-        Mockito.verify(this.rib).getYangRibId();
-        Mockito.verify(this.rib).getService();
-        Mockito.verify(this.rib).getRibIServiceGroupIdentifier();
-        Mockito.verify(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
+    public void testAppPeer() throws ExecutionException, InterruptedException {
+        appPeer.start(rib, neighbor, null, peerGroupLoader, tableTypeRegistry);
+        verify(rib).getYangRibId();
+        verify(rib).getService();
+        verify(rib).createPeerDOMChain();
+        verify(rib, times(1)).getLocalTablesKeys();
+
+        appPeer.instantiateServiceInstance();
+        verify(rib, times(3)).getYangRibId();
+        verify(rib, times(2)).getRibSupportContext();
+        verify(rib, times(2)).getLocalTablesKeys();
+        verify(rib, times(2)).createPeerDOMChain();
+        verify(domTx).newWriteOnlyTransaction();
 
-        this.singletonService.instantiateServiceInstance();
-        Mockito.verify(this.configurationWriter).apply();
-        Mockito.verify(this.rib, times(2)).getRibSupportContext();
-        Mockito.verify(this.rib).getLocalTablesKeys();
-        Mockito.verify(this.domTx).newWriteOnlyTransaction();
+        appPeer.closeServiceInstance();
+        verify(domTx, times(2)).close();
+        appPeer.stop().get();
 
-        APP_PEER.restart(this.rib, this.mappingService);
-        this.singletonService.instantiateServiceInstance();
-        Mockito.verify(this.rib, times(4)).getYangRibId();
-        Mockito.verify(this.rib, times(4)).getService();
-        Mockito.verify(this.rib, times(2)).getRibIServiceGroupIdentifier();
-        Mockito.verify(this.rib, times(2)).registerClusterSingletonService(any(ClusterSingletonService.class));
+        appPeer.start(rib, appPeer.getCurrentConfiguration(), null, peerGroupLoader, tableTypeRegistry);
+        appPeer.instantiateServiceInstance();
+        verify(rib, times(6)).getYangRibId();
+        verify(rib, times(4)).getService();
+        verify(rib, times(4)).createPeerDOMChain();
+        verify(listener, times(2)).close();
 
-        this.singletonService.closeServiceInstance();
-        Mockito.verify(this.listener, times(2)).close();
+        assertTrue(appPeer.containsEqualConfiguration(neighbor));
+        assertFalse(appPeer.containsEqualConfiguration(new NeighborBuilder()
+                .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2")))
+                .build()));
+        appPeer.closeServiceInstance();
+        verify(domTx, times(4)).close();
 
-        assertTrue(APP_PEER.containsEqualConfiguration(new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build()));
-        assertFalse(APP_PEER.containsEqualConfiguration(new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
-        APP_PEER.close();
-        Mockito.verify(this.singletonServiceRegistration).close();
+        appPeer.instantiateServiceInstance();
+        verify(rib, times(6)).createPeerDOMChain();
+        appPeer.closeServiceInstance();
+        verify(domTx, times(6)).close();
+        appPeer.stop().get();
     }
-}
\ No newline at end of file
+}