Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 19 | package org.onlab.packet; |
| 20 | |
| 21 | import static org.junit.Assert.assertEquals; |
| 22 | |
| 23 | import org.junit.Test; |
| 24 | |
| 25 | import com.google.common.testing.EqualsTester; |
| 26 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 27 | public class VlanIdTest { |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 28 | |
| 29 | @Test |
| 30 | public void testEquality() { |
| 31 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 32 | VlanId vlan1 = VlanId.vlanId((short) -1); |
| 33 | VlanId vlan2 = VlanId.vlanId((short) 100); |
| 34 | VlanId vlan3 = VlanId.vlanId((short) 100); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 35 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 36 | new EqualsTester().addEqualityGroup(VlanId.vlanId(), vlan1) |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 37 | .addEqualityGroup(vlan2, vlan3) |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 38 | .addEqualityGroup(VlanId.vlanId((short) 10)); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 39 | |
| 40 | } |
| 41 | |
| 42 | @Test |
| 43 | public void basics() { |
| 44 | // purposefully create UNTAGGED VLAN |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 45 | VlanId vlan1 = VlanId.vlanId((short) 10); |
| 46 | VlanId vlan2 = VlanId.vlanId((short) -1); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 47 | |
| 48 | assertEquals("incorrect VLAN value", 10, vlan1.toShort()); |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 49 | assertEquals("invalid untagged value", VlanId.UNTAGGED, vlan2.toShort()); |
Ayaka Koshibe | 16698a3 | 2014-09-13 22:19:02 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Test(expected = IllegalArgumentException.class) |
| 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 | } |
| 56 | } |