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 com.google.common.collect.ImmutableMap;
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
28 public class IdentifierUtilsTest {
29 private static final QName TABLES_KEY_QNAME = QName.create(Tables.QNAME, "tables-key").intern();
30 private static final TablesKey TK = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
31 private static final PeerId PEER_ID = new PeerId("127.0.0.1");
32 private static final NodeIdentifierWithPredicates NIWP_PEER = new NodeIdentifierWithPredicates(Peer.QNAME,
33 ImmutableMap.of(PEER_ID_QNAME, PEER_ID.getValue()));
34 private static final NodeIdentifierWithPredicates NIWP_TABLE = new NodeIdentifierWithPredicates(Tables.QNAME,
35 ImmutableMap.of(TABLES_KEY_QNAME, TK));
36 private static final YangInstanceIdentifier YII_PEER;
37 private static final YangInstanceIdentifier YII_TABLE;
40 YII_PEER = YangInstanceIdentifier.builder().node(BGPRIB_NID).node(PEER_NID)
41 .nodeWithKey(Peer.QNAME, PEER_ID_QNAME, PEER_ID.getValue()).build();
42 YII_TABLE = YangInstanceIdentifier.builder().node(LOCRIB_NID).node(Tables.QNAME)
43 .nodeWithKey(Tables.QNAME, TABLES_KEY_QNAME, TK).build();
47 public void testPeerPath() throws Exception {
48 final YangInstanceIdentifier result = IdentifierUtils.peerPath(YII_PEER);
49 assertEquals(YII_PEER, result);
53 public void testPeerKey() throws Exception {
54 final NodeIdentifierWithPredicates result = IdentifierUtils.peerKey(YII_PEER);
55 assertEquals(NIWP_PEER, result);
59 public void testPeerId() throws Exception {
60 final PeerId result = IdentifierUtils.peerId(NIWP_PEER);
61 assertEquals(PEER_ID, result);
65 public void testPeerKeyToPeerId() throws Exception {
66 final PeerId result = IdentifierUtils.peerKeyToPeerId(YII_PEER);
67 assertEquals(PEER_ID, result);
71 public void testTableKey() throws Exception {
72 final NodeIdentifierWithPredicates result = IdentifierUtils.tableKey(YII_TABLE);
73 assertEquals(NIWP_TABLE, result);
77 public void testDomPeerId() throws Exception {
78 final NodeIdentifierWithPredicates result = IdentifierUtils.domPeerId(PEER_ID);
79 assertEquals(NIWP_PEER, result);