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
8 package org.opendaylight.protocol.bgp.rib.impl.config;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.internal.verification.VerificationModeFactory.times;
15 import java.util.concurrent.ExecutionException;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.protocol.bgp.rib.impl.state.BGPStateCollector;
19 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
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;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instance.protocol.NeighborPeerGroupConfigBuilder;
26 public class AppPeerTest extends AbstractConfig {
27 private final AppPeer appPeer = new AppPeer(new BGPStateCollector());
29 private final Neighbor neighbor = new NeighborBuilder()
30 .setConfig(new ConfigBuilder()
31 .addAugmentation(new NeighborPeerGroupConfigBuilder()
32 .setPeerGroup(OpenConfigMappingUtil.APPLICATION_PEER_GROUP_NAME)
35 .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
39 public void setUp() throws Exception {
44 public void testAppPeer() throws ExecutionException, InterruptedException {
45 appPeer.start(rib, neighbor, null, peerGroupLoader, tableTypeRegistry);
46 verify(rib).getYangRibId();
47 verify(rib).getService();
48 verify(rib).createPeerDOMChain();
49 verify(rib, times(1)).getLocalTablesKeys();
51 appPeer.instantiateServiceInstance();
52 verify(rib, times(3)).getYangRibId();
53 verify(rib, times(2)).getRibSupportContext();
54 verify(rib, times(2)).getLocalTablesKeys();
55 verify(rib, times(2)).createPeerDOMChain();
56 verify(domTx).newWriteOnlyTransaction();
58 appPeer.closeServiceInstance();
59 verify(domTx, times(2)).close();
62 appPeer.start(rib, appPeer.getCurrentConfiguration(), null, peerGroupLoader, tableTypeRegistry);
63 appPeer.instantiateServiceInstance();
64 verify(rib, times(6)).getYangRibId();
65 verify(rib, times(4)).getService();
66 verify(rib, times(4)).createPeerDOMChain();
67 verify(listener, times(2)).close();
69 assertTrue(appPeer.containsEqualConfiguration(neighbor));
70 assertFalse(appPeer.containsEqualConfiguration(new NeighborBuilder()
71 .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2")))
73 appPeer.closeServiceInstance();
74 verify(domTx, times(4)).close();
76 appPeer.instantiateServiceInstance();
77 verify(rib, times(6)).createPeerDOMChain();
78 appPeer.closeServiceInstance();
79 verify(domTx, times(6)).close();