blob: b881dff0d21759049879d605f662644ed61eaeae [file] [log] [blame]
Hyunsun Moon090d77d2017-07-05 17:48:37 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Hyunsun Moon090d77d2017-07-05 17:48:37 +09003 *
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 */
16package org.onosproject.openstacknode.impl;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.packet.IpAddress;
21import org.onosproject.net.Device;
22import org.onosproject.openstacknode.api.NodeState;
23import org.onosproject.openstacknode.api.OpenstackNode;
24
25/**
26 * Unit tests for DefaultOpenstackNode.
27 */
28public class DefaultOpenstackNodeTest extends OpenstackNodeTest {
29
30 private static final IpAddress TEST_IP = IpAddress.valueOf("10.100.0.3");
31
32 private static final String HOSTNAME_1 = "hostname_1";
33 private static final String HOSTNAME_2 = "hostname_2";
34 private static final Device DEVICE_1 = createDevice(1);
35 private static final Device DEVICE_2 = createDevice(2);
36 private static final OpenstackNode OS_NODE_1 = createNode(
37 HOSTNAME_1,
38 OpenstackNode.NodeType.COMPUTE,
39 DEVICE_1,
40 TEST_IP,
41 NodeState.INIT);
42 private static final OpenstackNode OS_NODE_2 = createNode(
43 HOSTNAME_1,
44 OpenstackNode.NodeType.COMPUTE,
45 DEVICE_1,
46 TEST_IP,
47 NodeState.COMPLETE);
48 private static final OpenstackNode OS_NODE_3 = createNode(
49 HOSTNAME_2,
50 OpenstackNode.NodeType.COMPUTE,
51 DEVICE_2,
52 TEST_IP,
53 NodeState.INIT);
54
55 /**
56 * Checks equals method works as expected.
57 */
58 @Test
59 public void testEquality() {
60 new EqualsTester().addEqualityGroup(OS_NODE_1, OS_NODE_2)
61 .addEqualityGroup(OS_NODE_3)
62 .testEquals();
63 }
64
65 /**
66 * Checks building a node without hostname fails with proper exception.
67 */
68 @Test(expected = IllegalArgumentException.class)
69 public void testBuildWithoutHostname() {
70 DefaultOpenstackNode.builder()
71 .type(OpenstackNode.NodeType.COMPUTE)
72 .intgBridge(DEVICE_1.id())
73 .managementIp(TEST_IP)
74 .dataIp(TEST_IP)
75 .state(NodeState.INIT)
76 .build();
77 }
78
79 /**
80 * Checks building a node without type fails with proper exception.
81 */
82 @Test(expected = IllegalArgumentException.class)
83 public void testBuildWithoutType() {
84 DefaultOpenstackNode.builder()
85 .hostname(HOSTNAME_1)
86 .intgBridge(DEVICE_1.id())
87 .managementIp(TEST_IP)
88 .dataIp(TEST_IP)
89 .state(NodeState.INIT)
90 .build();
91 }
92
93 /**
94 * Checks building a node without integration bridge ID fails with
95 * proper exception.
96 */
97 @Test(expected = IllegalArgumentException.class)
98 public void testBuildWithoutIntegrationBridgeId() {
99 DefaultOpenstackNode.builder()
100 .hostname(HOSTNAME_1)
101 .type(OpenstackNode.NodeType.COMPUTE)
102 .managementIp(TEST_IP)
103 .dataIp(TEST_IP)
104 .state(NodeState.INIT)
105 .build();
106 }
107
108 /**
109 * Checks building a node without management IP address fails with
110 * proper exception.
111 */
112 @Test(expected = IllegalArgumentException.class)
113 public void testBuildWithoutManagementIp() {
114 DefaultOpenstackNode.builder()
115 .hostname(HOSTNAME_1)
116 .type(OpenstackNode.NodeType.COMPUTE)
117 .intgBridge(DEVICE_1.id())
118 .dataIp(TEST_IP)
119 .state(NodeState.INIT)
120 .build();
121 }
122
123 /**
124 * Checks building a node without data IP nor VLAN interface name
125 * fails with proper exception.
126 */
127 @Test(expected = IllegalArgumentException.class)
128 public void testBuildWithoutDataIpNorVlanIntf() {
129 DefaultOpenstackNode.builder()
130 .hostname(HOSTNAME_1)
131 .type(OpenstackNode.NodeType.COMPUTE)
132 .intgBridge(DEVICE_1.id())
133 .state(NodeState.INIT)
134 .build();
135 }
136
137 /**
138 * Checks building a gateway type node without router bridge ID
139 * fails with proper exception.
140 */
141 @Test(expected = IllegalArgumentException.class)
142 public void testGatewayWithoutRouterBridgeId() {
143 DefaultOpenstackNode.builder()
144 .hostname(HOSTNAME_1)
145 .type(OpenstackNode.NodeType.GATEWAY)
146 .intgBridge(DEVICE_1.id())
147 .managementIp(TEST_IP)
148 .dataIp(TEST_IP)
149 .state(NodeState.INIT)
150 .build();
151 }
152}