Change BGP to use bgp-id type and as-number type
[bgpcep.git] / bgp / openconfig-impl / src / test / java / org / opendaylight / protocol / bgp / openconfig / impl / openconfig / BGPAppNeighborProviderImplTest.java
1 /*
2  * Copyright (c) 2015 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.openconfig.impl.openconfig;
10
11 import static org.junit.Assert.assertEquals;
12
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
17 import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigHolder;
18 import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigStateStore;
19 import org.opendaylight.protocol.bgp.openconfig.spi.InstanceConfigurationIdentifier;
20 import org.opendaylight.protocol.bgp.openconfig.spi.pojo.BGPAppPeerInstanceConfiguration;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.Config1;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.Config1Builder;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
24 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
25 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborBuilder;
26 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.NeighborKey;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.bgp.rib.impl.rev160330.BgpApplicationPeer;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleKey;
32
33 public class BGPAppNeighborProviderImplTest {
34
35     private BGPAppNeighborProviderImpl neighborProvider;
36
37     @SuppressWarnings("unchecked")
38     @Before
39     public void setUp() throws Exception {
40         final BindingTransactionChain txChain = Mockito.mock(BindingTransactionChain.class);
41         final BGPConfigStateStore stateHolders = Mockito.mock(BGPConfigStateStore.class);
42         final BGPConfigHolder<Neighbor> configHolder = Mockito.mock(BGPConfigHolder.class);
43         Mockito.doReturn(configHolder).when(stateHolders).getBGPConfigHolder(Mockito.any(Class.class));
44         neighborProvider = new BGPAppNeighborProviderImpl(txChain, stateHolders);
45     }
46
47     @Test
48     public void testCreateModuleKey() {
49         assertEquals(new ModuleKey("instanceName", BgpApplicationPeer.class), neighborProvider.createModuleKey("instanceName"));
50     }
51
52     @Test
53     public void testGetInstanceConfigurationType() {
54         assertEquals(BGPAppPeerInstanceConfiguration.class, neighborProvider.getInstanceConfigurationType());
55     }
56
57     @Test
58     public void testApply() {
59         final Neighbor neighbor = neighborProvider.apply(new BGPAppPeerInstanceConfiguration(new InstanceConfigurationIdentifier("instanceName"), "app-rib", new BgpId("1.2.3.4")));
60         final Neighbor expectedNeighbor = new NeighborBuilder()
61             .setNeighborAddress(new IpAddress(new Ipv4Address("1.2.3.4")))
62             .setKey(new NeighborKey(new IpAddress(new Ipv4Address("1.2.3.4"))))
63             .setConfig(new ConfigBuilder().addAugmentation(Config1.class, new Config1Builder().setPeerGroup("application-peers").build()).build())
64             .build();
65         assertEquals(expectedNeighbor, neighbor);
66     }
67
68 }