blob: 0bd833ff88fa11716c4fc24b3819ecced996d006 [file] [log] [blame]
Sho SHIMIZUe571d442016-02-11 19:10:52 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Sho SHIMIZUe571d442016-02-11 19:10:52 -08003 *
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
7 *
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.
15 */
Sho SHIMIZUe18cb122016-02-22 21:04:56 -080016package org.onosproject.net.resource;
Sho SHIMIZUe571d442016-02-11 19:10:52 -080017
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.packet.VlanId;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.PortNumber;
23
Sho SHIMIZU74ac9012016-02-12 10:03:21 -080024import static org.hamcrest.Matchers.is;
25import static org.junit.Assert.assertThat;
26
Sho SHIMIZUe571d442016-02-11 19:10:52 -080027/**
28 * Unit test for DiscreteResourceId.
29 */
30public class DiscreteResourceIdTest {
31
32 private static final DeviceId D1 = DeviceId.deviceId("of:001");
33 private static final DeviceId D2 = DeviceId.deviceId("of:002");
34 private static final PortNumber P1 = PortNumber.portNumber(1);
35 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
36
37 @Test
38 public void testEquality() {
39 DiscreteResourceId id1 = Resources.discrete(D1, P1, VLAN1).id();
40 DiscreteResourceId sameAsId1 = Resources.discrete(D1, P1, VLAN1).id();
41 DiscreteResourceId id2 = Resources.discrete(D2, P1, VLAN1).id();
42
43 new EqualsTester()
44 .addEqualityGroup(id1, sameAsId1)
Ray Milkey1f8fcc32018-09-17 14:25:29 -070045 .addEqualityGroup(id2)
46 .testEquals();
Sho SHIMIZUe571d442016-02-11 19:10:52 -080047 }
Sho SHIMIZU74ac9012016-02-12 10:03:21 -080048
Ray Milkey1f8fcc32018-09-17 14:25:29 -070049
Sho SHIMIZU74ac9012016-02-12 10:03:21 -080050 @Test
51 public void testSimpleTypeName() {
52 DiscreteResourceId id = Resources.discrete(D1, P1, VLAN1).id();
53 assertThat(id.simpleTypeName(), is("VlanId"));
54 }
55
56 @Test
57 public void testSimpleTypeNameOfRoot() {
58 assertThat(ResourceId.ROOT.simpleTypeName(), is("Root"));
59 }
Sho SHIMIZUe571d442016-02-11 19:10:52 -080060}