2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.protocol.bgp.openconfig.spi;
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.rev171207.BgpTableType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
23 import org.opendaylight.yangtools.concepts.AbstractRegistration;
25 public class SimpleBGPTableTypeRegistryProviderTest {
27 private BGPTableTypeRegistryProvider provider;
28 private AbstractRegistration registration;
32 this.provider = new SimpleBGPTableTypeRegistryProvider();
33 this.registration = this.provider.registerBGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, IPV4UNICAST.class);
37 public void testBGPTableTypeRegistryProvider() {
39 final Optional<Class<? extends AfiSafiType>> afiSafiType = this.provider.getAfiSafiType(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
40 Assert.assertTrue(afiSafiType.isPresent());
41 final Optional<Class<? extends AfiSafiType>> afiSafiType2 = this.provider.getAfiSafiType(new BgpTableTypeImpl(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class));
42 Assert.assertFalse(afiSafiType2.isPresent());
44 final Optional<BgpTableType> tableType = this.provider.getTableType(IPV4UNICAST.class);
45 Assert.assertTrue(tableType.isPresent());
46 final Optional<BgpTableType> tableType2 = this.provider.getTableType(IPV6UNICAST.class);
47 Assert.assertFalse(tableType2.isPresent());
49 this.registration.close();
50 final Optional<BgpTableType> tableType3 = this.provider.getTableType(IPV4UNICAST.class);
51 Assert.assertFalse(tableType3.isPresent());
54 @Test(expected=IllegalStateException.class)
55 public void testDuplicatedRegistration() {
56 this.provider.registerBGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, IPV4UNICAST.class);