BUG-7215: Fix App Peer ModifiedNodeDoesNotExistException
[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
9 package org.opendaylight.protocol.bgp.rib.impl.config;
10
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;
15
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.neighbor.group.ConfigBuilder;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config2Builder;
27
28 public class AppPeerTest extends AbstractConfig {
29     private static final AppPeer APP_PEER = new AppPeer();
30     private final Neighbor neighbor = new NeighborBuilder().setConfig(new ConfigBuilder().addAugmentation(Config2.class,
31         new Config2Builder().setPeerGroup(OpenConfigMappingUtil.APPLICATION_PEER_GROUP_NAME).build()).build())
32         .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build();
33
34     @Override
35     @Before
36     public void setUp() throws Exception {
37         super.setUp();
38     }
39
40     @Test
41     public void testAppPeer() throws Exception {
42         APP_PEER.start(this.rib, this.neighbor, this.tableTypeRegistry, this.configurationWriter);
43         Mockito.verify(this.rib).getYangRibId();
44         Mockito.verify(this.rib).getService();
45         Mockito.verify(this.rib).getRibIServiceGroupIdentifier();
46         Mockito.verify(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
47
48         this.singletonService.instantiateServiceInstance();
49         Mockito.verify(this.rib, times(2)).getYangRibId();
50         Mockito.verify(this.configurationWriter).apply();
51         Mockito.verify(this.rib).getRibSupportContext();
52         Mockito.verify(this.rib).getLocalTablesKeys();
53         Mockito.verify(this.domTx).newWriteOnlyTransaction();
54
55         APP_PEER.close();
56         Mockito.verify(this.singletonServiceRegistration).close();
57
58         APP_PEER.restart(this.rib, this.tableTypeRegistry);
59         this.singletonService.instantiateServiceInstance();
60         Mockito.verify(this.rib, times(4)).getYangRibId();
61         Mockito.verify(this.rib, times(4)).getService();
62         Mockito.verify(this.rib, times(2)).getRibIServiceGroupIdentifier();
63         Mockito.verify(this.rib, times(2)).registerClusterSingletonService(any(ClusterSingletonService.class));
64
65         this.singletonService.closeServiceInstance();
66         Mockito.verify(this.listener, times(2)).close();
67
68         assertTrue(APP_PEER.containsEqualConfiguration(this.neighbor));
69         assertFalse(APP_PEER.containsEqualConfiguration(new NeighborBuilder()
70             .setNeighborAddress(new IpAddress(new Ipv4Address("127.0.0.2"))).build()));
71         APP_PEER.close();
72         Mockito.verify(this.singletonServiceRegistration, times(2)).close();
73     }
74 }