blob: 2fe0d2a0b185aa9687ca17cfc8d98bb6d45dde7d [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 */
Jian Li5a38ab62018-07-02 22:34:11 +090016package org.onosproject.openstacknode.api;
Hyunsun Moon090d77d2017-07-05 17:48:37 +090017
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.packet.IpAddress;
21import org.onosproject.net.Device;
Hyunsun Moon090d77d2017-07-05 17:48:37 +090022
23/**
24 * Unit tests for DefaultOpenstackNode.
25 */
26public class DefaultOpenstackNodeTest extends OpenstackNodeTest {
27
28 private static final IpAddress TEST_IP = IpAddress.valueOf("10.100.0.3");
29
30 private static final String HOSTNAME_1 = "hostname_1";
31 private static final String HOSTNAME_2 = "hostname_2";
32 private static final Device DEVICE_1 = createDevice(1);
33 private static final Device DEVICE_2 = createDevice(2);
34 private static final OpenstackNode OS_NODE_1 = createNode(
35 HOSTNAME_1,
36 OpenstackNode.NodeType.COMPUTE,
37 DEVICE_1,
38 TEST_IP,
39 NodeState.INIT);
40 private static final OpenstackNode OS_NODE_2 = createNode(
41 HOSTNAME_1,
42 OpenstackNode.NodeType.COMPUTE,
43 DEVICE_1,
44 TEST_IP,
45 NodeState.COMPLETE);
46 private static final OpenstackNode OS_NODE_3 = createNode(
47 HOSTNAME_2,
48 OpenstackNode.NodeType.COMPUTE,
49 DEVICE_2,
50 TEST_IP,
51 NodeState.INIT);
52
53 /**
54 * Checks equals method works as expected.
55 */
56 @Test
57 public void testEquality() {
58 new EqualsTester().addEqualityGroup(OS_NODE_1, OS_NODE_2)
59 .addEqualityGroup(OS_NODE_3)
60 .testEquals();
61 }
62
63 /**
64 * Checks building a node without hostname fails with proper exception.
65 */
66 @Test(expected = IllegalArgumentException.class)
67 public void testBuildWithoutHostname() {
68 DefaultOpenstackNode.builder()
69 .type(OpenstackNode.NodeType.COMPUTE)
70 .intgBridge(DEVICE_1.id())
71 .managementIp(TEST_IP)
72 .dataIp(TEST_IP)
73 .state(NodeState.INIT)
74 .build();
75 }
76
77 /**
78 * Checks building a node without type fails with proper exception.
79 */
80 @Test(expected = IllegalArgumentException.class)
81 public void testBuildWithoutType() {
82 DefaultOpenstackNode.builder()
83 .hostname(HOSTNAME_1)
84 .intgBridge(DEVICE_1.id())
85 .managementIp(TEST_IP)
86 .dataIp(TEST_IP)
87 .state(NodeState.INIT)
88 .build();
89 }
90
91 /**
Hyunsun Moon090d77d2017-07-05 17:48:37 +090092 * Checks building a node without management IP address fails with
93 * proper exception.
94 */
95 @Test(expected = IllegalArgumentException.class)
96 public void testBuildWithoutManagementIp() {
97 DefaultOpenstackNode.builder()
98 .hostname(HOSTNAME_1)
99 .type(OpenstackNode.NodeType.COMPUTE)
100 .intgBridge(DEVICE_1.id())
101 .dataIp(TEST_IP)
102 .state(NodeState.INIT)
103 .build();
104 }
105
106 /**
107 * Checks building a node without data IP nor VLAN interface name
108 * fails with proper exception.
109 */
110 @Test(expected = IllegalArgumentException.class)
111 public void testBuildWithoutDataIpNorVlanIntf() {
112 DefaultOpenstackNode.builder()
113 .hostname(HOSTNAME_1)
114 .type(OpenstackNode.NodeType.COMPUTE)
115 .intgBridge(DEVICE_1.id())
116 .state(NodeState.INIT)
117 .build();
118 }
Hyunsun Moon090d77d2017-07-05 17:48:37 +0900119}