Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 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() { |
| 28 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 29 | VlanId vlan1 = VlanId.vlanId((short) -1); |
| 30 | VlanId vlan2 = VlanId.vlanId((short) 100); |
| 31 | VlanId vlan3 = 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) |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 34 | .addEqualityGroup(vlan2, vlan3) |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 35 | .addEqualityGroup(VlanId.vlanId((short) 10)); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 36 | |
| 37 | } |
| 38 | |
| 39 | @Test |
| 40 | public void basics() { |
| 41 | // purposefully create UNTAGGED VLAN |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 42 | VlanId vlan1 = VlanId.vlanId((short) 10); |
| 43 | VlanId vlan2 = VlanId.vlanId((short) -1); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 44 | |
| 45 | assertEquals("incorrect VLAN value", 10, vlan1.toShort()); |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 46 | assertEquals("invalid untagged value", VlanId.UNTAGGED, vlan2.toShort()); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Test(expected = IllegalArgumentException.class) |
| 50 | public void testIllicitVLAN() { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 51 | VlanId.vlanId((short) 5000); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 52 | } |
| 53 | } |