Bump upstreams
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / config / AppPeerTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl.config;
9
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;
14
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;
25
26 public class AppPeerTest extends AbstractConfig {
27     private final AppPeer appPeer = new AppPeer(new BGPStateCollector());
28
29     private final Neighbor neighbor = new NeighborBuilder()
30         .setConfig(new ConfigBuilder()
31             .addAugmentation(new NeighborPeerGroupConfigBuilder()
32                 .setPeerGroup(OpenConfigMappingUtil.APPLICATION_PEER_GROUP_NAME)
33                 .build())
34             .build())
35         .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
36
37     @Override
38     @Before
39     public void setUp() throws Exception {
40         super.setUp();
41     }
42
43     @Test
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();
50
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();
57
58         appPeer.closeServiceInstance();
59         verify(domTx, times(2)).close();
60         appPeer.stop().get();
61
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();
68
69         assertTrue(appPeer.containsEqualConfiguration(neighbor));
70         assertFalse(appPeer.containsEqualConfiguration(new NeighborBuilder()
71                 .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2")))
72                 .build()));
73         appPeer.closeServiceInstance();
74         verify(domTx, times(4)).close();
75
76         appPeer.instantiateServiceInstance();
77         verify(rib, times(6)).createPeerDOMChain();
78         appPeer.closeServiceInstance();
79         verify(domTx, times(6)).close();
80         appPeer.stop().get();
81     }
82 }