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
8 package org.opendaylight.protocol.bgp.rib.spi;
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.protocol.bgp.rib.spi.RIBNodeIdentifiers.BGPRIB_NID;
12 import static org.opendaylight.protocol.bgp.rib.spi.RIBNodeIdentifiers.LOCRIB_NID;
13 import static org.opendaylight.protocol.bgp.rib.spi.RIBNodeIdentifiers.PEER_NID;
14 import static org.opendaylight.protocol.bgp.rib.spi.RIBQNames.PEER_ID_QNAME;
16 import org.junit.Test;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
27 public class IdentifierUtilsTest {
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 = NodeIdentifierWithPredicates.of(Peer.QNAME,
32 PEER_ID_QNAME, PEER_ID.getValue());
33 private static final NodeIdentifierWithPredicates NIWP_TABLE = NodeIdentifierWithPredicates.of(Tables.QNAME,
34 TABLES_KEY_QNAME, TK);
35 private static final YangInstanceIdentifier YII_PEER;
36 private static final YangInstanceIdentifier YII_TABLE;
39 YII_PEER = YangInstanceIdentifier.builder().node(BGPRIB_NID).node(PEER_NID)
40 .nodeWithKey(Peer.QNAME, PEER_ID_QNAME, PEER_ID.getValue()).build();
41 YII_TABLE = YangInstanceIdentifier.builder().node(LOCRIB_NID).node(Tables.QNAME)
42 .nodeWithKey(Tables.QNAME, TABLES_KEY_QNAME, TK).build();
46 public void testPeerPath() throws Exception {
47 final YangInstanceIdentifier result = IdentifierUtils.peerPath(YII_PEER);
48 assertEquals(YII_PEER, result);
52 public void testPeerKey() throws Exception {
53 final NodeIdentifierWithPredicates result = IdentifierUtils.peerKey(YII_PEER);
54 assertEquals(NIWP_PEER, result);
58 public void testPeerId() throws Exception {
59 final PeerId result = IdentifierUtils.peerId(NIWP_PEER);
60 assertEquals(PEER_ID, result);
64 public void testPeerKeyToPeerId() throws Exception {
65 final PeerId result = IdentifierUtils.peerKeyToPeerId(YII_PEER);
66 assertEquals(PEER_ID, result);
70 public void testTableKey() throws Exception {
71 final NodeIdentifierWithPredicates result = IdentifierUtils.tableKey(YII_TABLE);
72 assertEquals(NIWP_TABLE, result);
76 public void testDomPeerId() throws Exception {
77 final NodeIdentifierWithPredicates result = IdentifierUtils.domPeerId(PEER_ID);
78 assertEquals(NIWP_PEER, result);