Provide Add Path support for all AFI/SAFI
[bgpcep.git] / bgp / rib-spi / src / test / java / org / opendaylight / protocol / bgp / rib / spi / IdentifierUtilsTest.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 package org.opendaylight.protocol.bgp.rib.spi;
9
10 import static org.junit.Assert.assertEquals;
11
12 import com.google.common.collect.ImmutableMap;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.LocRib;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
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.UnicastSubsequentAddressFamily;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
25
26 public class IdentifierUtilsTest {
27     private static final QName PEER_ID_QNAME = QName.create(Peer.QNAME, "peer-id").intern();
28     private static final QName TABLES_KEY_QNAME = QName.create(Tables.QNAME, "tables-key").intern();
29     private static final TablesKey TK = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
30     private static final PeerId PEER_ID = new PeerId("127.0.0.1");
31     private static final NodeIdentifierWithPredicates NIWP_PEER = new NodeIdentifierWithPredicates(Peer.QNAME,
32             ImmutableMap.of(PEER_ID_QNAME, PEER_ID.getValue()));
33     private static final NodeIdentifierWithPredicates NIWP_TABLE = new NodeIdentifierWithPredicates(Tables.QNAME,
34             ImmutableMap.of(TABLES_KEY_QNAME, TK));
35     private static final YangInstanceIdentifier YII_PEER;
36     private static final YangInstanceIdentifier YII_TABLE;
37
38     static {
39         YII_PEER = YangInstanceIdentifier.builder().node(BgpRib.QNAME).node(Peer.QNAME)
40                 .nodeWithKey(Peer.QNAME, PEER_ID_QNAME, PEER_ID.getValue()).build();
41         YII_TABLE = YangInstanceIdentifier.builder().node(LocRib.QNAME).node(Tables.QNAME)
42                 .nodeWithKey(Tables.QNAME, TABLES_KEY_QNAME, TK).build();
43     }
44
45     @Test
46     public void testPeerPath() throws Exception {
47         final YangInstanceIdentifier result = IdentifierUtils.peerPath(YII_PEER);
48         assertEquals(YII_PEER, result);
49     }
50
51     @Test
52     public void testPeerKey() throws Exception {
53         final NodeIdentifierWithPredicates result = IdentifierUtils.peerKey(YII_PEER);
54         assertEquals(NIWP_PEER, result);
55     }
56
57     @Test
58     public void testPeerId() throws Exception {
59         final PeerId result = IdentifierUtils.peerId(NIWP_PEER);
60         assertEquals(PEER_ID, result);
61     }
62
63     @Test
64     public void testPeerKeyToPeerId() throws Exception {
65         final PeerId result = IdentifierUtils.peerKeyToPeerId(YII_PEER);
66         assertEquals(PEER_ID, result);
67     }
68
69     @Test
70     public void testTableKey() throws Exception {
71         final NodeIdentifierWithPredicates result = IdentifierUtils.tableKey(YII_TABLE);
72         assertEquals(NIWP_TABLE, result);
73     }
74
75     @Test
76     public void testDomPeerId() throws Exception {
77         final NodeIdentifierWithPredicates result = IdentifierUtils.domPeerId(PEER_ID);
78         assertEquals(NIWP_PEER, result);
79     }
80
81 }