2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bgp.rib.impl.config;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Matchers.any;
14 import static org.mockito.internal.verification.VerificationModeFactory.times;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mockito;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
20 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
25 public class AppPeerTest extends AbstractConfig {
26 private static final AppPeer APP_PEER = new AppPeer();
30 public void setUp() throws Exception {
32 Mockito.doReturn(true).when(this.mappingService).isApplicationPeer(any(Neighbor.class));
36 public void testAppPeer() throws Exception {
37 final Neighbor neighbor = new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
38 APP_PEER.start(this.rib, neighbor, this.mappingService, this.configurationWriter);
39 Mockito.verify(this.rib).getYangRibId();
40 Mockito.verify(this.rib).getService();
41 Mockito.verify(this.rib).getRibIServiceGroupIdentifier();
42 Mockito.verify(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
44 this.singletonService.instantiateServiceInstance();
45 Mockito.verify(this.configurationWriter).apply();
46 Mockito.verify(this.rib).getRibSupportContext();
47 Mockito.verify(this.rib).getLocalTablesKeys();
48 Mockito.verify(this.domTx).newWriteOnlyTransaction();
50 APP_PEER.restart(this.rib, this.mappingService);
51 this.singletonService.instantiateServiceInstance();
52 Mockito.verify(this.rib, times(4)).getYangRibId();
53 Mockito.verify(this.rib, times(4)).getService();
54 Mockito.verify(this.rib, times(2)).getRibIServiceGroupIdentifier();
55 Mockito.verify(this.rib, times(2)).registerClusterSingletonService(any(ClusterSingletonService.class));
57 this.singletonService.closeServiceInstance();
58 Mockito.verify(this.listener, times(2)).close();
60 assertTrue(APP_PEER.containsEqualConfiguration(new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build()));
61 assertFalse(APP_PEER.containsEqualConfiguration(new NeighborBuilder().setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
63 Mockito.verify(this.singletonServiceRegistration).close();