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

©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.