Fix star import and enable checkstyle rule to prevent it.
[controller.git] / opendaylight / northbound / topology / src / test / java / org / opendaylight / controller / topology / northbound / TopologyTest.java
1 package org.opendaylight.controller.topology.northbound;
2
3
4
5 import org.junit.Test;
6 import org.opendaylight.controller.sal.core.Bandwidth;
7 import org.opendaylight.controller.sal.core.ConstructionException;
8 import org.opendaylight.controller.sal.core.Edge;
9 import org.opendaylight.controller.sal.core.Latency;
10 import org.opendaylight.controller.sal.core.Node;
11 import org.opendaylight.controller.sal.core.NodeConnector;
12 import org.opendaylight.controller.sal.core.Property;
13 import org.opendaylight.controller.sal.core.State;
14 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
15 import org.opendaylight.controller.sal.utils.NodeCreator;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 import java.util.ArrayList;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Set;
23
24 import static junit.framework.Assert.assertEquals;
25 import static org.junit.Assert.fail;
26
27 public class TopologyTest {
28         protected static final Logger logger = LoggerFactory
29             .getLogger(TopologyTest.class);
30
31     @Test
32     public void edgePropertiesTopologyTest() {
33
34         //Create 3 nodes and edges between them
35         Node n1 = NodeCreator.createOFNode((long)1);
36         Node n2 = NodeCreator.createOFNode((long)2);
37         Node n3 = NodeCreator.createOFNode((long)3);
38
39         NodeConnector nc11 = NodeConnectorCreator.createOFNodeConnector((short) 1, n1);
40         NodeConnector nc12 = NodeConnectorCreator.createOFNodeConnector((short) 2, n1);
41         NodeConnector nc21 = NodeConnectorCreator.createOFNodeConnector((short) 1, n2);
42         NodeConnector nc22 = NodeConnectorCreator.createOFNodeConnector((short) 2, n2);
43         NodeConnector nc23 = NodeConnectorCreator.createOFNodeConnector((short) 2, n3);
44         NodeConnector nc32 = NodeConnectorCreator.createOFNodeConnector((short) 3, n2);
45         NodeConnector nc33 = NodeConnectorCreator.createOFNodeConnector((short) 3, n3);
46
47         Edge e12 = null;
48         Edge e23 = null;
49
50         try {
51             e12 = new Edge(nc12, nc21);
52         } catch (ConstructionException e) {
53             fail("Failed to construct edge " + e.getMessage());
54         }
55         try {
56             e23 = new Edge(nc23, nc32);
57         } catch (ConstructionException e) {
58             fail("Failed to construct edge " + e.getMessage());
59         }
60
61         Set<Property> props = new HashSet<Property>();
62         State state = new State(State.EDGE_UP);
63         Bandwidth bw = new Bandwidth(Bandwidth.BW100Gbps);
64         Latency l = new Latency(Latency.LATENCY100ns);
65         props.add(state);
66         props.add(bw);
67         props.add(l);
68
69         //Check get methods for edge and properties
70         EdgeProperties edgeProp = new EdgeProperties(e12, props);
71
72         Edge getEdge = edgeProp.getEdge();
73         assertEquals(e12, getEdge);
74         assertEquals(nc12, getEdge.getTailNodeConnector());
75         assertEquals(n1, getEdge.getTailNodeConnector().getNode());
76         assertEquals((long)1, getEdge.getTailNodeConnector().getNode().getID());
77         assertEquals(nc21, getEdge.getHeadNodeConnector());
78         assertEquals(n2, getEdge.getHeadNodeConnector().getNode());
79         assertEquals((long)2, getEdge.getHeadNodeConnector().getNode().getID());
80
81         Set<Property> getProp = edgeProp.getProperties();
82         assertEquals(props, getProp);
83         assertEquals(props.size(), getProp.size());
84
85         //Use set methods
86         edgeProp.setEdge(e23);
87         getEdge = edgeProp.getEdge();
88         assertEquals(e23, getEdge);
89         assertEquals(nc23, getEdge.getTailNodeConnector());
90         assertEquals(nc32, getEdge.getHeadNodeConnector());
91
92         props.remove(state);
93         edgeProp.setProperties(props);
94         assertEquals(props, getProp);
95         assertEquals(props.size(), getProp.size());
96
97
98         //Create and check topology
99         List<EdgeProperties> edgePropList= new ArrayList<EdgeProperties>();
100         edgePropList.add(edgeProp);
101
102         Topology t = new Topology(edgePropList);
103
104         List<EdgeProperties> getEdgePropList = t.getEdgeProperties();
105         assertEquals(edgePropList, getEdgePropList);
106         assertEquals(1, getEdgePropList.size());
107
108         EdgeProperties edgeProp2 = new EdgeProperties(e23, props);
109         edgePropList.add(edgeProp2);
110         t.setEdgeProperties(edgePropList);
111
112         getEdgePropList = t.getEdgeProperties();
113         assertEquals(edgePropList, getEdgePropList);
114         assertEquals(2, getEdgePropList.size());
115
116     }
117
118
119 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.