/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.l2switch.loopremover.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class InstanceIdentifierUtilsTest { private static final Short NUM_ID_1 = 1; private static final String STR_ID_1 = "id1"; private static final String STR_ID_2 = "id2"; @Test public void testCreateNodePath() throws Exception { InstanceIdentifier insId = InstanceIdentifierUtils.createNodePath(new NodeId(STR_ID_1)); assertNotNull(insId); assertNotNull(insId.firstIdentifierOf(Nodes.class)); assertEquals(STR_ID_1, insId.firstKeyOf(Node.class).getId().getValue()); } @Test public void testGetNodePath() throws Exception { InstanceIdentifier ncInsId = InstanceIdentifier.builder(Nodes.class).child(Node.class) .child(NodeConnector.class).build(); assertNotNull(InstanceIdentifierUtils.getNodePath(ncInsId)); } @Test public void testCreateTablePath() throws Exception { InstanceIdentifier tableInsId = InstanceIdentifierUtils.createTablePath( InstanceIdentifier.builder(Nodes.class).child(Node.class).build(), new TableKey(NUM_ID_1)); assertNotNull(tableInsId); assertEquals(NUM_ID_1.shortValue(), tableInsId.firstKeyOf(Table.class).getId().shortValue()); assertNotNull(tableInsId.firstIdentifierOf(FlowCapableNode.class)); } @Test public void testCreateNodeConnectorIdentifier() throws Exception { InstanceIdentifier ncInsId = InstanceIdentifierUtils.createNodeConnectorIdentifier(STR_ID_1, STR_ID_2); assertNotNull(ncInsId); assertEquals(STR_ID_1, ncInsId.firstKeyOf(Node.class).getId().getValue()); assertEquals(STR_ID_2, ncInsId.firstKeyOf(NodeConnector.class).getId().getValue()); } @Test public void testGenerateNodeInstanceIdentifier() throws Exception { NodeConnectorRef ncRef = new NodeConnectorRef( InstanceIdentifier.builder(Nodes.class).child(Node.class).child(NodeConnector.class).build()); assertNotNull(InstanceIdentifierUtils.generateNodeInstanceIdentifier(ncRef)); } @Test public void testGenerateFlowTableInstanceIdentifier() throws Exception { NodeConnectorRef ncRef = new NodeConnectorRef( InstanceIdentifier.builder(Nodes.class).child(Node.class).child(NodeConnector.class).build()); InstanceIdentifier
tableInsId = InstanceIdentifierUtils.generateFlowTableInstanceIdentifier(ncRef, new TableKey(NUM_ID_1)); assertNotNull(tableInsId); assertEquals(NUM_ID_1, tableInsId.firstKeyOf(Table.class).getId()); } @Test public void testGenerateTopologyInstanceIdentifier() throws Exception { InstanceIdentifier topologyInsId = InstanceIdentifierUtils .generateTopologyInstanceIdentifier(STR_ID_1); assertNotNull(topologyInsId); assertEquals(STR_ID_1, topologyInsId.firstKeyOf(Topology.class).getTopologyId().getValue()); } }