Sho SHIMIZU | e571d44 | 2016-02-11 19:10:52 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Sho SHIMIZU | e571d44 | 2016-02-11 19:10:52 -0800 | [diff] [blame] | 3 | * |
| 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 SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 16 | package org.onosproject.net.resource; |
Sho SHIMIZU | e571d44 | 2016-02-11 19:10:52 -0800 | [diff] [blame] | 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | import org.onlab.util.Bandwidth; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.PortNumber; |
| 23 | |
Sho SHIMIZU | 74ac901 | 2016-02-12 10:03:21 -0800 | [diff] [blame] | 24 | import static org.hamcrest.Matchers.is; |
| 25 | import static org.junit.Assert.assertThat; |
| 26 | |
Sho SHIMIZU | e571d44 | 2016-02-11 19:10:52 -0800 | [diff] [blame] | 27 | /** |
| 28 | * Unit test for ContinuousResourceId. |
| 29 | */ |
| 30 | public class ContinuousResourceIdTest { |
| 31 | |
| 32 | private static final DeviceId D1 = DeviceId.deviceId("of:001"); |
| 33 | private static final PortNumber P1 = PortNumber.portNumber(1); |
| 34 | private static final Bandwidth BW1 = Bandwidth.gbps(2); |
| 35 | private static final Bandwidth BW2 = Bandwidth.gbps(1); |
| 36 | |
| 37 | @Test |
| 38 | public void testEquality() { |
| 39 | ContinuousResourceId id1 = Resources.continuous(D1, P1, Bandwidth.class) |
| 40 | .resource(BW1.bps()).id(); |
| 41 | // intentionally set a different value |
| 42 | ContinuousResourceId sameAsId1 = Resources.continuous(D1, P1, Bandwidth.class) |
| 43 | .resource(BW2.bps()).id(); |
| 44 | |
| 45 | new EqualsTester() |
Ray Milkey | 1f8fcc3 | 2018-09-17 14:25:29 -0700 | [diff] [blame] | 46 | .addEqualityGroup(id1, sameAsId1) |
| 47 | .testEquals(); |
Sho SHIMIZU | e571d44 | 2016-02-11 19:10:52 -0800 | [diff] [blame] | 48 | } |
Sho SHIMIZU | 74ac901 | 2016-02-12 10:03:21 -0800 | [diff] [blame] | 49 | |
| 50 | @Test |
| 51 | public void testSimpleTypeName() { |
| 52 | ContinuousResourceId id1 = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()).id(); |
| 53 | |
| 54 | assertThat(id1.simpleTypeName(), is("Bandwidth")); |
| 55 | } |
Sho SHIMIZU | e571d44 | 2016-02-11 19:10:52 -0800 | [diff] [blame] | 56 | } |