Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 16 | package org.onlab.packet; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import com.google.common.testing.EqualsTester; |
| 23 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 24 | public class VlanIdTest { |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 25 | |
| 26 | @Test |
| 27 | public void testEquality() { |
Luca Prete | 283a962 | 2016-03-29 16:12:20 -0700 | [diff] [blame] | 28 | VlanId vlan1 = VlanId.vlanId("None"); |
| 29 | VlanId vlan2 = VlanId.vlanId((short) -1); |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 30 | VlanId vlan3 = VlanId.vlanId((short) 100); |
Luca Prete | 283a962 | 2016-03-29 16:12:20 -0700 | [diff] [blame] | 31 | VlanId vlan4 = VlanId.vlanId((short) 100); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 32 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 33 | new EqualsTester().addEqualityGroup(VlanId.vlanId(), vlan1) |
Luca Prete | 283a962 | 2016-03-29 16:12:20 -0700 | [diff] [blame] | 34 | .addEqualityGroup(vlan1, vlan2) |
| 35 | .addEqualityGroup(vlan3, vlan4) |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 36 | .addEqualityGroup(VlanId.vlanId((short) 10)); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 37 | |
| 38 | } |
| 39 | |
| 40 | @Test |
| 41 | public void basics() { |
| 42 | // purposefully create UNTAGGED VLAN |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 43 | VlanId vlan1 = VlanId.vlanId((short) 10); |
| 44 | VlanId vlan2 = VlanId.vlanId((short) -1); |
Luca Prete | 283a962 | 2016-03-29 16:12:20 -0700 | [diff] [blame] | 45 | VlanId vlan3 = VlanId.vlanId("None"); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 46 | |
| 47 | assertEquals("incorrect VLAN value", 10, vlan1.toShort()); |
Luca Prete | 283a962 | 2016-03-29 16:12:20 -0700 | [diff] [blame] | 48 | assertEquals("invalid untagged value", VlanId.UNTAGGED, |
| 49 | vlan2.toShort(), vlan3.toShort()); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Test(expected = IllegalArgumentException.class) |
Charles Chan | 9b26bf3 | 2016-04-12 16:46:36 -0700 | [diff] [blame] | 53 | public void testIllicitVlan() { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 54 | VlanId.vlanId((short) 5000); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 55 | } |
Charles Chan | 9b26bf3 | 2016-04-12 16:46:36 -0700 | [diff] [blame] | 56 | |
| 57 | @Test(expected = IllegalArgumentException.class) |
| 58 | public void testIllicitVlanString() { |
| 59 | VlanId.vlanId("5000"); |
| 60 | } |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 61 | } |