blob: 5702ba9a56163fe6dcf51a8c94f7f1afaecdef5f [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
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 Koshibe16698a32014-09-13 22:19:02 -070019package org.onlab.packet;
20
21import static org.junit.Assert.assertEquals;
22
23import org.junit.Test;
24
25import com.google.common.testing.EqualsTester;
26
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070027public class VlanIdTest {
Ayaka Koshibe16698a32014-09-13 22:19:02 -070028
29 @Test
30 public void testEquality() {
31
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070032 VlanId vlan1 = VlanId.vlanId((short) -1);
33 VlanId vlan2 = VlanId.vlanId((short) 100);
34 VlanId vlan3 = VlanId.vlanId((short) 100);
Ayaka Koshibe16698a32014-09-13 22:19:02 -070035
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070036 new EqualsTester().addEqualityGroup(VlanId.vlanId(), vlan1)
Ayaka Koshibe16698a32014-09-13 22:19:02 -070037 .addEqualityGroup(vlan2, vlan3)
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070038 .addEqualityGroup(VlanId.vlanId((short) 10));
Ayaka Koshibe16698a32014-09-13 22:19:02 -070039
40 }
41
42 @Test
43 public void basics() {
44 // purposefully create UNTAGGED VLAN
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070045 VlanId vlan1 = VlanId.vlanId((short) 10);
46 VlanId vlan2 = VlanId.vlanId((short) -1);
Ayaka Koshibe16698a32014-09-13 22:19:02 -070047
48 assertEquals("incorrect VLAN value", 10, vlan1.toShort());
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070049 assertEquals("invalid untagged value", VlanId.UNTAGGED, vlan2.toShort());
Ayaka Koshibe16698a32014-09-13 22:19:02 -070050 }
51
52 @Test(expected = IllegalArgumentException.class)
53 public void testIllicitVLAN() {
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070054 VlanId.vlanId((short) 5000);
Ayaka Koshibe16698a32014-09-13 22:19:02 -070055 }
56}