Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -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 | 2d31022 | 2016-01-22 11:45:11 -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 | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onlab.util.Bandwidth; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.PortNumber; |
| 22 | |
| 23 | import java.util.Arrays; |
| 24 | |
| 25 | import static org.hamcrest.Matchers.is; |
| 26 | import static org.junit.Assert.assertThat; |
| 27 | |
| 28 | public class ResourceIdTest { |
| 29 | private static final DeviceId D1 = DeviceId.deviceId("a"); |
| 30 | private static final PortNumber P1 = PortNumber.portNumber(1); |
| 31 | private static final Bandwidth BW1 = Bandwidth.gbps(1); |
| 32 | |
| 33 | @Test |
| 34 | public void testDiscreteToString() { |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 35 | ResourceId resource = Resources.discrete(D1, P1).id(); |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 36 | |
| 37 | assertThat(resource.toString(), is(Arrays.asList(D1, P1).toString())); |
| 38 | } |
| 39 | |
| 40 | @Test |
| 41 | public void testContinuousToString() { |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 42 | ResourceId resource = Resources.continuous(D1, P1, Bandwidth.class).id(); |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 43 | |
| 44 | assertThat(resource.toString(), is(Arrays.asList(D1, P1, Bandwidth.class.getSimpleName()).toString())); |
| 45 | } |
| 46 | |
| 47 | @Test(expected = IllegalArgumentException.class) |
| 48 | public void testInitWithNonClassInstance() { |
Sho SHIMIZU | 460b972 | 2016-01-28 10:48:26 -0800 | [diff] [blame] | 49 | Resources.continuous(D1, P1, BW1).id(); |
Sho SHIMIZU | 2d31022 | 2016-01-22 11:45:11 -0800 | [diff] [blame] | 50 | } |
| 51 | } |