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.host; |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 17 | |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 18 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.net.HostLocation; |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 20 | |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 22 | import org.onosproject.net.TestDeviceParams; |
| 23 | |
| 24 | import java.util.Set; |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 25 | |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 26 | import static org.junit.Assert.assertEquals; |
| 27 | import static org.junit.Assert.assertTrue; |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Test for the default host description. |
| 31 | */ |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 32 | public class DefaultHostDecriptionTest extends TestDeviceParams { |
| 33 | private static final Set<HostLocation> LOCATIONS = ImmutableSet.of(LOC1, LOC2, LOC3); |
| 34 | private static final HostDescription SINGLE_HOMED_HOST_DESCR = |
| 35 | new DefaultHostDescription(MAC1, VLAN1, LOC1, IP1); |
| 36 | private static final HostDescription MULTI_HOMED_HOST_DESCR = |
| 37 | new DefaultHostDescription(MAC1, VLAN1, LOCATIONS, IPSET1, false); |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 38 | |
| 39 | @Test |
| 40 | public void basics() { |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 41 | assertEquals("incorrect mac", MAC1, SINGLE_HOMED_HOST_DESCR.hwAddress()); |
| 42 | assertEquals("incorrect vlan", VLAN1, SINGLE_HOMED_HOST_DESCR.vlan()); |
| 43 | assertEquals("incorrect location", LOC1, SINGLE_HOMED_HOST_DESCR.location()); |
| 44 | assertEquals("incorrect IPs", ImmutableSet.of(IP1), SINGLE_HOMED_HOST_DESCR.ipAddress()); |
| 45 | assertTrue("incorrect toString", SINGLE_HOMED_HOST_DESCR.toString().contains("vlan=11")); |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Charles Chan | cd06c69 | 2017-04-27 20:46:06 -0700 | [diff] [blame] | 48 | @Test |
| 49 | public void testLocation() { |
| 50 | assertEquals("Latest location should be LOC3", LOC3, MULTI_HOMED_HOST_DESCR.location()); |
| 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void testLocations() { |
| 55 | Set<HostLocation> locations = MULTI_HOMED_HOST_DESCR.locations(); |
| 56 | |
| 57 | assertEquals("There should be 3 locations", locations.size(), 3); |
| 58 | assertTrue("Host location contains 1st location", locations.contains(LOC1)); |
| 59 | assertTrue("Host location contains 2nd location", locations.contains(LOC2)); |
| 60 | assertTrue("Host location contains 3rd location", locations.contains(LOC3)); |
| 61 | } |
Ayaka Koshibe | 93afebc | 2014-09-15 13:25:22 -0700 | [diff] [blame] | 62 | } |