blob: 2a0818a4c7427c6c3ccaa45456aaec69f4018e01 [file] [log] [blame]
Sho SHIMIZU2d310222016-01-22 11:45:11 -08001/*
2 * Copyright 2016 Open Networking Laboratory
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 SHIMIZUe18cb122016-02-22 21:04:56 -080016package org.onosproject.net.resource;
Sho SHIMIZU2d310222016-01-22 11:45:11 -080017
18import org.junit.Test;
19import org.onlab.util.Bandwidth;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.PortNumber;
22
23import java.util.Arrays;
24
25import static org.hamcrest.Matchers.is;
26import static org.junit.Assert.assertThat;
27
28public 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 SHIMIZU460b9722016-01-28 10:48:26 -080035 ResourceId resource = Resources.discrete(D1, P1).id();
Sho SHIMIZU2d310222016-01-22 11:45:11 -080036
37 assertThat(resource.toString(), is(Arrays.asList(D1, P1).toString()));
38 }
39
40 @Test
41 public void testContinuousToString() {
Sho SHIMIZU460b9722016-01-28 10:48:26 -080042 ResourceId resource = Resources.continuous(D1, P1, Bandwidth.class).id();
Sho SHIMIZU2d310222016-01-22 11:45:11 -080043
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 SHIMIZU460b9722016-01-28 10:48:26 -080049 Resources.continuous(D1, P1, BW1).id();
Sho SHIMIZU2d310222016-01-22 11:45:11 -080050 }
51}