Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
Ayaka Koshibe | 50ee924 | 2014-09-12 16:37:46 -0700 | [diff] [blame] | 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 19 | import static org.junit.Assert.assertTrue; |
Ayaka Koshibe | 50ee924 | 2014-09-12 16:37:46 -0700 | [diff] [blame] | 20 | |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import com.google.common.testing.EqualsTester; |
| 23 | import java.util.Set; |
Ayaka Koshibe | 50ee924 | 2014-09-12 16:37:46 -0700 | [diff] [blame] | 24 | import org.junit.Test; |
| 25 | |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 26 | public 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 Koshibe | 50ee924 | 2014-09-12 16:37:46 -0700 | [diff] [blame] | 32 | |
| 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 Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 49 | 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 Koshibe | 50ee924 | 2014-09-12 16:37:46 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | } |