blob: 9ec8dddacebefda47458a009158e54aafd61e93f [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska24c849c2014-10-27 09:53:05 -070015 */
Ayaka Koshibe16698a32014-09-13 22:19:02 -070016package org.onlab.packet;
17
18import static org.junit.Assert.assertEquals;
19
20import org.junit.Test;
21
22import com.google.common.testing.EqualsTester;
23
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070024public class VlanIdTest {
Ayaka Koshibe16698a32014-09-13 22:19:02 -070025
26 @Test
27 public void testEquality() {
28
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070029 VlanId vlan1 = VlanId.vlanId((short) -1);
30 VlanId vlan2 = VlanId.vlanId((short) 100);
31 VlanId vlan3 = VlanId.vlanId((short) 100);
Ayaka Koshibe16698a32014-09-13 22:19:02 -070032
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070033 new EqualsTester().addEqualityGroup(VlanId.vlanId(), vlan1)
Ayaka Koshibe16698a32014-09-13 22:19:02 -070034 .addEqualityGroup(vlan2, vlan3)
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070035 .addEqualityGroup(VlanId.vlanId((short) 10));
Ayaka Koshibe16698a32014-09-13 22:19:02 -070036
37 }
38
39 @Test
40 public void basics() {
41 // purposefully create UNTAGGED VLAN
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070042 VlanId vlan1 = VlanId.vlanId((short) 10);
43 VlanId vlan2 = VlanId.vlanId((short) -1);
Ayaka Koshibe16698a32014-09-13 22:19:02 -070044
45 assertEquals("incorrect VLAN value", 10, vlan1.toShort());
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070046 assertEquals("invalid untagged value", VlanId.UNTAGGED, vlan2.toShort());
Ayaka Koshibe16698a32014-09-13 22:19:02 -070047 }
48
49 @Test(expected = IllegalArgumentException.class)
50 public void testIllicitVLAN() {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070051 VlanId.vlanId((short) 5000);
Ayaka Koshibe16698a32014-09-13 22:19:02 -070052 }
53}