Fix checkstyle violations
[l2switch.git] / loopremover / implementation / src / test / java / org / opendaylight / l2switch / loopremover / util / InstanceIdentifierUtilsTest.java
1 /*
2  * Copyright (c) 2014 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.l2switch.loopremover.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 public class InstanceIdentifierUtilsTest {
29
30     private static final Short NUM_ID_1 = 1;
31     private static final String STR_ID_1 = "id1";
32     private static final String STR_ID_2 = "id2";
33
34     @Test
35     public void testCreateNodePath() throws Exception {
36         InstanceIdentifier<Node> insId = InstanceIdentifierUtils.createNodePath(new NodeId(STR_ID_1));
37         assertNotNull(insId);
38         assertNotNull(insId.firstIdentifierOf(Nodes.class));
39         assertEquals(STR_ID_1, insId.firstKeyOf(Node.class, NodeKey.class).getId().getValue());
40     }
41
42     @Test
43     public void testGetNodePath() throws Exception {
44         InstanceIdentifier<NodeConnector> ncInsId = InstanceIdentifier.builder(Nodes.class).child(Node.class)
45                 .child(NodeConnector.class).build();
46         assertNotNull(InstanceIdentifierUtils.getNodePath(ncInsId));
47     }
48
49     @Test
50     public void testCreateTablePath() throws Exception {
51         InstanceIdentifier<Table> tableInsId = InstanceIdentifierUtils.createTablePath(
52                 InstanceIdentifier.builder(Nodes.class).child(Node.class).build(), new TableKey(NUM_ID_1));
53         assertNotNull(tableInsId);
54         assertEquals(NUM_ID_1.shortValue(), tableInsId.firstKeyOf(Table.class, TableKey.class).getId().shortValue());
55         assertNotNull(tableInsId.firstIdentifierOf(FlowCapableNode.class));
56     }
57
58     @Test
59     public void testCreateNodeConnectorIdentifier() throws Exception {
60         InstanceIdentifier<NodeConnector> ncInsId = InstanceIdentifierUtils.createNodeConnectorIdentifier(STR_ID_1,
61                 STR_ID_2);
62         assertNotNull(ncInsId);
63         assertEquals(STR_ID_1, ncInsId.firstKeyOf(Node.class, NodeKey.class).getId().getValue());
64         assertEquals(STR_ID_2, ncInsId.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue());
65     }
66
67     @Test
68     public void testGenerateNodeInstanceIdentifier() throws Exception {
69         NodeConnectorRef ncRef = new NodeConnectorRef(
70                 InstanceIdentifier.builder(Nodes.class).child(Node.class).child(NodeConnector.class).build());
71         assertNotNull(InstanceIdentifierUtils.generateNodeInstanceIdentifier(ncRef));
72     }
73
74     @Test
75     public void testGenerateFlowTableInstanceIdentifier() throws Exception {
76         NodeConnectorRef ncRef = new NodeConnectorRef(
77                 InstanceIdentifier.builder(Nodes.class).child(Node.class).child(NodeConnector.class).build());
78         InstanceIdentifier<Table> tableInsId = InstanceIdentifierUtils.generateFlowTableInstanceIdentifier(ncRef,
79                 new TableKey(NUM_ID_1));
80         assertNotNull(tableInsId);
81         assertEquals(NUM_ID_1, tableInsId.firstKeyOf(Table.class, TableKey.class).getId());
82     }
83
84     @Test
85     public void testGenerateTopologyInstanceIdentifier() throws Exception {
86         InstanceIdentifier<Topology> topologyInsId = InstanceIdentifierUtils
87                 .generateTopologyInstanceIdentifier(STR_ID_1);
88         assertNotNull(topologyInsId);
89         assertEquals(STR_ID_1, topologyInsId.firstKeyOf(Topology.class, TopologyKey.class).getTopologyId().getValue());
90     }
91 }