Refactor SubnetConfig
[controller.git] / opendaylight / switchmanager / api / src / test / java / org / opendaylight / controller / switchmanager / SubnetConfigTest.java
1 package org.opendaylight.controller.switchmanager;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import org.junit.Assert;
6 import org.junit.Test;
7 import org.opendaylight.controller.sal.core.ConstructionException;
8 import org.opendaylight.controller.sal.core.Node;
9 import org.opendaylight.controller.sal.core.NodeConnector;
10 import org.opendaylight.controller.sal.utils.Status;
11
12 public class SubnetConfigTest {
13
14     @Test
15     public void configuration() throws ConstructionException {
16         // Create the node connector string list
17         Node node1 = new Node(Node.NodeIDType.OPENFLOW, 1L);
18         Node node2 = new Node(Node.NodeIDType.OPENFLOW, 2L);
19         Node node3 = new Node(Node.NodeIDType.OPENFLOW, 3L);
20         NodeConnector nc1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)1, node1);
21         NodeConnector nc2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)2, node2);
22         NodeConnector nc3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW, (short)3, node3);
23         List<String> portList = new ArrayList<String>();
24         portList.add(nc1.toString());
25         portList.add(nc2.toString());
26         portList.add(nc3.toString());
27
28         // Full subnet creation
29         SubnetConfig config = new SubnetConfig("eng", "11.1.1.254/16", portList);
30         Status status = config.validate();
31         Assert.assertTrue(status.isSuccess());
32
33         // No port set specified
34         config = new SubnetConfig("eng", "11.1.1.254/16", null);
35         status = config.validate();
36         Assert.assertTrue(status.isSuccess());
37
38         // Empty port set
39         config = new SubnetConfig("eng", "11.1.1.254/16", new ArrayList<String>(0));
40         status = config.validate();
41         Assert.assertTrue(status.isSuccess());
42
43         // Zero subnet
44         config = new SubnetConfig("eng", "1.2.3.254/1", null);
45         status = config.validate();
46         Assert.assertFalse(status.isSuccess());
47
48         // Port set with invalid port notation
49         List<String> badPortList = new ArrayList<String>();
50         badPortList.add("1/1");
51         config = new SubnetConfig("eng", "1.2.3.254/1", badPortList);
52         status = config.validate();
53         Assert.assertFalse(status.isSuccess());
54     }
55 }