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.ArgumentMatchers.any;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.internal.verification.VerificationModeFactory.times;
16 import java.util.concurrent.ExecutionException;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
20 import org.opendaylight.protocol.bgp.rib.impl.state.BGPStateCollector;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.network.instance.protocol.NeighborPeerGroupConfigBuilder;
28 public class AppPeerTest extends AbstractConfig {
29 private final AppPeer appPeer = new AppPeer(new BGPStateCollector());
31 private final Neighbor neighbor = new NeighborBuilder()
32 .setConfig(new ConfigBuilder()
33 .addAugmentation(new NeighborPeerGroupConfigBuilder()
34 .setPeerGroup(OpenConfigMappingUtil.APPLICATION_PEER_GROUP_NAME)
37 .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
41 public void setUp() throws Exception {
46 public void testAppPeer() throws ExecutionException, InterruptedException {
47 appPeer.start(rib, neighbor, null, peerGroupLoader, tableTypeRegistry);
48 verify(rib).getYangRibId();
49 verify(rib).getService();
50 verify(rib).createPeerDOMChain(any(DOMTransactionChainListener.class));
51 verify(rib, times(1)).getLocalTablesKeys();
53 appPeer.instantiateServiceInstance();
54 verify(rib, times(3)).getYangRibId();
55 verify(rib, times(2)).getRibSupportContext();
56 verify(rib, times(2)).getLocalTablesKeys();
57 verify(rib, times(2)).createPeerDOMChain(any(DOMTransactionChainListener.class));
58 verify(domTx).newWriteOnlyTransaction();
60 appPeer.closeServiceInstance();
61 verify(domTx, times(2)).close();
64 appPeer.start(rib, appPeer.getCurrentConfiguration(), null, peerGroupLoader, tableTypeRegistry);
65 appPeer.instantiateServiceInstance();
66 verify(rib, times(6)).getYangRibId();
67 verify(rib, times(4)).getService();
68 verify(rib, times(4)).createPeerDOMChain(any(DOMTransactionChainListener.class));
69 verify(listener, times(2)).close();
71 assertTrue(appPeer.containsEqualConfiguration(neighbor));
72 assertFalse(appPeer.containsEqualConfiguration(new NeighborBuilder()
73 .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2")))
75 appPeer.closeServiceInstance();
76 verify(domTx, times(4)).close();
78 appPeer.instantiateServiceInstance();
79 verify(rib, times(6)).createPeerDOMChain(any(DOMTransactionChainListener.class));
80 appPeer.closeServiceInstance();
81 verify(domTx, times(6)).close();