YANG revision dates mass-update
[bgpcep.git] / bgp / openconfig-spi / src / test / java / org / opendaylight / protocol / bgp / openconfig / spi / SimpleBGPTableTypeRegistryProviderTest.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.openconfig.spi;
10
11 import java.util.Optional;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
16 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.AfiSafiType;
17 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
18 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv4AddressFamily;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.Ipv6AddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily;
23 import org.opendaylight.yangtools.concepts.AbstractRegistration;
24
25 public class SimpleBGPTableTypeRegistryProviderTest {
26
27     private BGPTableTypeRegistryProvider provider;
28     private AbstractRegistration registration;
29
30     @Before
31     public void setUp() {
32         this.provider = new SimpleBGPTableTypeRegistryProvider();
33         this.registration = this.provider.registerBGPTableType(Ipv4AddressFamily.class,
34                 UnicastSubsequentAddressFamily.class, IPV4UNICAST.class);
35     }
36
37     @Test
38     public void testBGPTableTypeRegistryProvider() {
39
40         final Optional<Class<? extends AfiSafiType>> afiSafiType = this.provider.getAfiSafiType(
41                 new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
42         Assert.assertTrue(afiSafiType.isPresent());
43         final Optional<Class<? extends AfiSafiType>> afiSafiType2 = this.provider.getAfiSafiType(
44                 new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
45         Assert.assertFalse(afiSafiType2.isPresent());
46
47         final Optional<BgpTableType> tableType = this.provider.getTableType(IPV4UNICAST.class);
48         Assert.assertTrue(tableType.isPresent());
49         final Optional<BgpTableType> tableType2 = this.provider.getTableType(IPV6UNICAST.class);
50         Assert.assertFalse(tableType2.isPresent());
51
52         this.registration.close();
53         final Optional<BgpTableType> tableType3 = this.provider.getTableType(IPV4UNICAST.class);
54         Assert.assertFalse(tableType3.isPresent());
55     }
56
57     @Test(expected = IllegalStateException.class)
58     public void testDuplicatedRegistration() {
59         this.provider.registerBGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class,
60                 IPV4UNICAST.class);
61     }
62
63 }