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

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