BUG-4633: Use ietf-inet-type rev. 20130715 on bgp-openconfig
[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.controller.bgp.rib.impl.rev130409.BgpApplicationPeer;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleKey;
31
32 public class BGPAppNeighborProviderImplTest {
33
34     private BGPAppNeighborProviderImpl neighborProvider;
35
36     @SuppressWarnings("unchecked")
37     @Before
38     public void setUp() throws Exception {
39         final BindingTransactionChain txChain = Mockito.mock(BindingTransactionChain.class);
40         final BGPConfigStateStore stateHolders = Mockito.mock(BGPConfigStateStore.class);
41         final BGPConfigHolder<Neighbor> configHolder = Mockito.mock(BGPConfigHolder.class);
42         Mockito.doReturn(configHolder).when(stateHolders).getBGPConfigHolder(Mockito.any(Class.class));
43         neighborProvider = new BGPAppNeighborProviderImpl(txChain, stateHolders);
44     }
45
46     @Test
47     public void testCreateModuleKey() {
48         assertEquals(new ModuleKey("instanceName", BgpApplicationPeer.class), neighborProvider.createModuleKey("instanceName"));
49     }
50
51     @Test
52     public void testGetInstanceConfigurationType() {
53         assertEquals(BGPAppPeerInstanceConfiguration.class, neighborProvider.getInstanceConfigurationType());
54     }
55
56     @Test
57     public void testApply() {
58         final Neighbor neighbor = neighborProvider.apply(new BGPAppPeerInstanceConfiguration(new InstanceConfigurationIdentifier("instanceName"), "app-rib", new Ipv4Address("1.2.3.4")));
59         final Neighbor expectedNeighbor = new NeighborBuilder()
60             .setNeighborAddress(new IpAddress(new Ipv4Address("1.2.3.4")))
61             .setKey(new NeighborKey(new IpAddress(new Ipv4Address("1.2.3.4"))))
62             .setConfig(new ConfigBuilder().addAugmentation(Config1.class, new Config1Builder().setPeerGroup("application-peers").build()).build())
63             .build();
64         assertEquals(expectedNeighbor, neighbor);
65     }
66
67 }