blob: ece7f19997f0c8ec4779e341d5006e92ee7217cf [file] [log] [blame]
andreaed976a42015-10-05 14:38:25 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.net.behaviour;
18
19
20import org.junit.Rule;
21import org.junit.Test;
22import org.junit.rules.ExpectedException;
23import org.onlab.packet.IpAddress;
24
25import java.util.ArrayList;
26import java.util.Arrays;
27import java.util.List;
28
29import static org.junit.Assert.*;
30
31/**
32 * Test for ControllerInfo class.
33 */
34public class ControllerInfoTest {
35 @Rule
36 public ExpectedException thrown = ExpectedException.none();
37
38 @Test
39 public void tcpSslFormat() {
40 String target = "tcp:192.168.1.1:6653";
41 ControllerInfo controllerInfo = new ControllerInfo(target);
42 assertEquals("wrong type", controllerInfo.type(), "tcp");
43 assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
44 assertEquals("wrong port", controllerInfo.port(), 6653);
45
46 }
47
48 @Test
49 public void ptcpPsslFormat() {
50 String target = "ptcp:6653:192.168.1.1";
51 ControllerInfo controllerInfo = new ControllerInfo(target);
52 assertEquals("wrong type", controllerInfo.type(), "ptcp");
53 assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
54 assertEquals("wrong port", controllerInfo.port(), 6653);
55
56 }
57
58 @Test
59 public void unixFormat() {
60 String target = "unix:file";
61 thrown.expect(IllegalArgumentException.class);
62 ControllerInfo controllerInfo = new ControllerInfo(target);
63 assertTrue("wrong type", controllerInfo.type().contains("unix"));
64 assertNull("wrong ip", controllerInfo.ip());
65 assertEquals("wrong port", controllerInfo.port(), -1);
66
67 }
68
69 @Test
70 public void defaultValues() {
71 String target = "tcp:192.168.1.1";
72 ControllerInfo controllerInfo = new ControllerInfo(target);
73 assertEquals("wrong type", controllerInfo.type(), "tcp");
74 assertEquals("wrong ip", controllerInfo.ip(), IpAddress.valueOf("192.168.1.1"));
75 assertEquals("wrong port", controllerInfo.port(), 6653);
76 String target1 = "ptcp:5000:";
77 ControllerInfo controllerInfo2 = new ControllerInfo(target1);
78 assertEquals("wrong type", controllerInfo2.type(), "ptcp");
79 assertEquals("wrong ip", controllerInfo2.ip(), IpAddress.valueOf("0.0.0.0"));
80 assertEquals("wrong port", controllerInfo2.port(), 5000);
81 String target2 = "ptcp:";
82 ControllerInfo controllerInfo3 = new ControllerInfo(target2);
83 assertEquals("wrong type", controllerInfo3.type(), "ptcp");
84 assertEquals("wrong ip", controllerInfo3.ip(), IpAddress.valueOf("0.0.0.0"));
85 assertEquals("wrong port", controllerInfo3.port(), 6653);
86 }
87
88
89 @Test
90 public void testEquals() {
91 String target1 = "ptcp:6653:192.168.1.1";
92 ControllerInfo controllerInfo1 = new ControllerInfo(target1);
93 String target2 = "ptcp:6653:192.168.1.1";
94 ControllerInfo controllerInfo2 = new ControllerInfo(target2);
95 assertTrue("wrong equals method", controllerInfo1.equals(controllerInfo2));
96 }
97
98 @Test
99 public void testListEquals() {
100 String target1 = "ptcp:6653:192.168.1.1";
101 ControllerInfo controllerInfo1 = new ControllerInfo(target1);
102 String target2 = "ptcp:6653:192.168.1.1";
103 ControllerInfo controllerInfo2 = new ControllerInfo(target2);
104 String target3 = "tcp:192.168.1.1:6653";
105 ControllerInfo controllerInfo3 = new ControllerInfo(target3);
106 String target4 = "tcp:192.168.1.1:6653";
107 ControllerInfo controllerInfo4 = new ControllerInfo(target4);
108 List<ControllerInfo> list1 = new ArrayList<>(Arrays.asList(controllerInfo1, controllerInfo3));
109 List<ControllerInfo> list2 = new ArrayList<>(Arrays.asList(controllerInfo2, controllerInfo4));
110 assertTrue("wrong equals list method", list1.equals(list2));
111 }
112}