blob: e36d0e2376ea1026a0376899b0976d9dd9563105 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net;
Ayaka Koshibe50ee9242014-09-12 16:37:46 -070017
18import static org.junit.Assert.assertEquals;
Charles Chancd06c692017-04-27 20:46:06 -070019import static org.junit.Assert.assertTrue;
Ayaka Koshibe50ee9242014-09-12 16:37:46 -070020
Charles Chancd06c692017-04-27 20:46:06 -070021import com.google.common.collect.ImmutableSet;
22import com.google.common.testing.EqualsTester;
23import java.util.Set;
Ayaka Koshibe50ee9242014-09-12 16:37:46 -070024import org.junit.Test;
25
Charles Chancd06c692017-04-27 20:46:06 -070026public class DefaultHostTest extends TestDeviceParams {
27 private static final Set<HostLocation> LOCATIONS = ImmutableSet.of(LOC1, LOC2, LOC3);
28 private static final Host SINGLE_HOMED_HOST =
29 new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, IPSET1);
30 private static final Host MULTI_HOMED_HOST =
31 new DefaultHost(PID, HID1, MAC1, VLAN1, LOCATIONS, IPSET1, false);
Ayaka Koshibe50ee9242014-09-12 16:37:46 -070032
33 @Test
34 public void testEquality() {
35 Host h1 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, IPSET1);
36 Host h2 = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, IPSET1);
37 Host h3 = new DefaultHost(PID, HID2, MAC2, VLAN2, LOC2, IPSET2);
38 Host h4 = new DefaultHost(PID, HID2, MAC2, VLAN2, LOC2, IPSET2);
39 Host h5 = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC2, IPSET1);
40
41 new EqualsTester().addEqualityGroup(h1, h2)
42 .addEqualityGroup(h3, h4)
43 .addEqualityGroup(h5)
44 .testEquals();
45 }
46
47 @Test
48 public void basics() {
Charles Chancd06c692017-04-27 20:46:06 -070049 assertEquals("incorrect provider", PID, SINGLE_HOMED_HOST.providerId());
50 assertEquals("incorrect id", HID1, SINGLE_HOMED_HOST.id());
51 assertEquals("incorrect type", MAC1, SINGLE_HOMED_HOST.mac());
52 assertEquals("incorrect VLAN", VLAN1, SINGLE_HOMED_HOST.vlan());
53 assertEquals("incorrect location", LOC1, SINGLE_HOMED_HOST.location());
54 assertEquals("incorrect IPs", IPSET1, SINGLE_HOMED_HOST.ipAddresses());
55 }
56
57 @Test
58 public void testLocation() {
59 assertEquals("Latest location should be LOC3", LOC3, MULTI_HOMED_HOST.location());
60 }
61
62 @Test
63 public void testLocations() {
64 Set<HostLocation> locations = MULTI_HOMED_HOST.locations();
65
66 assertEquals("There should be 3 locations", locations.size(), 3);
67 assertTrue("Host location contains 1st location", locations.contains(LOC1));
68 assertTrue("Host location contains 2nd location", locations.contains(LOC2));
69 assertTrue("Host location contains 3rd location", locations.contains(LOC3));
Ayaka Koshibe50ee9242014-09-12 16:37:46 -070070 }
71
72}