Add 'TableStatistics' to SAL and Northbound Statistics API.
[controller.git] / opendaylight / northbound / statistics / src / test / java / org / opendaylight / controller / statistics / northbound / StatisticsNorthboundTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.statistics.northbound;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import junit.framework.TestCase;
16
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.reader.FlowOnNode;
21 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
22 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
23 import org.opendaylight.controller.sal.utils.NodeCreator;
24
25 public class StatisticsNorthboundTest extends TestCase {
26
27     @Test
28     public void testFlowStatistics() {
29         List<FlowOnNode> fon = new ArrayList<FlowOnNode>();
30         Node node = NodeCreator.createOFNode(1L);
31         FlowStatistics fs = new FlowStatistics(node, fon);
32         Assert.assertTrue(fs.getNode().equals(node));
33         Assert.assertTrue(fs.getFlowStats().equals(fon));
34
35         Node node2 = NodeCreator.createOFNode(2L);
36         fs.setNode(node2);
37         Assert.assertTrue(fs.getNode().equals(node2));
38         fs.setNode(node2);
39         Assert.assertTrue(fs.getNode().equals(node2));
40         fs.setFlowStats(null);
41         Assert.assertTrue(fs.getFlowStats() == null);
42     }
43
44     @Test
45     public void testAllFlowStatistics() {
46         List<FlowStatistics> fs = new ArrayList<FlowStatistics>();
47         AllFlowStatistics afs = new AllFlowStatistics(fs);
48         Assert.assertTrue(afs.getFlowStatistics().equals(fs));
49         afs.setFlowStatistics(null);
50         Assert.assertTrue(afs.getFlowStatistics() == null);
51     }
52
53     @Test
54     public void testPortStatistics() {
55         List<NodeConnectorStatistics> ncs = new ArrayList<NodeConnectorStatistics>();
56         Node node = NodeCreator.createOFNode(1L);
57         PortStatistics ps = new PortStatistics(node, ncs);
58
59         Assert.assertTrue(ps.getNode().equals(node));
60         Assert.assertTrue(ps.getPortStats().equals(ncs));
61         Node node2 = NodeCreator.createOFNode(2L);
62         ps.setNode(node2);
63         Assert.assertTrue(ps.getNode().equals(node2));
64         ps.setFlowStats(null);
65         Assert.assertTrue(ps.getPortStats() == null);
66     }
67
68     @Test
69     public void testAllPortStatistics() {
70         List<PortStatistics> ps = new ArrayList<PortStatistics>();
71         AllPortStatistics aps = new AllPortStatistics(ps);
72         Assert.assertTrue(aps.getPortStatistics().equals(ps));
73         aps.setPortStatistics(null);
74         Assert.assertTrue(aps.getPortStatistics() == null);
75     }
76
77     @Test
78     public void testTableStatistics() {
79         List<NodeTableStatistics> nts = new ArrayList<NodeTableStatistics>();
80         Node node = NodeCreator.createOFNode(1L);
81         TableStatistics ts = new TableStatistics(node, nts);
82
83         Assert.assertTrue(ts.getNode().equals(node));
84         Assert.assertTrue(ts.getTableStats().equals(nts));
85         Node node2 = NodeCreator.createOFNode(2L);
86         ts.setNode(node2);
87         Assert.assertTrue(ts.getNode().equals(node2));
88         ts.setTableStats(null);
89         Assert.assertTrue(ts.getTableStats() == null);
90     }
91
92     @Test
93     public void testAllTableStatistics() {
94         List<TableStatistics> ts = new ArrayList<TableStatistics>();
95         AllTableStatistics ats = new AllTableStatistics(ts);
96         Assert.assertTrue(ats.getTableStatistics().equals(ts));
97         ats.setTableStatistics(null);
98         Assert.assertTrue(ats.getTableStatistics() == null);
99     }
100
101 }