blob: 15b457ce53baec78a961b7ee21bd3d09c549f4e0 [file] [log] [blame]
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -07001/*
2 * Copyright 2015 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 */
16package org.onosproject.net.newresource;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.packet.VlanId;
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080021import org.onlab.util.Bandwidth;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070022import org.onosproject.net.DeviceId;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070023import org.onosproject.net.PortNumber;
24
25import java.util.Optional;
26
Sho SHIMIZU69dc5842015-11-20 16:31:12 -080027import static org.hamcrest.Matchers.contains;
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070028import static org.hamcrest.Matchers.is;
29import static org.junit.Assert.assertThat;
30
31public class ResourcePathTest {
32
33 private static final DeviceId D1 = DeviceId.deviceId("of:001");
34 private static final DeviceId D2 = DeviceId.deviceId("of:002");
35 private static final PortNumber P1 = PortNumber.portNumber(1);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070036 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080037 private static final Bandwidth BW1 = Bandwidth.gbps(2);
38 private static final Bandwidth BW2 = Bandwidth.gbps(1);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070039
40 @Test
41 public void testEquals() {
Sho SHIMIZU44f37612015-11-25 16:23:22 -080042 ResourcePath resource1 = ResourcePath.discrete(D1, P1, VLAN1);
43 ResourcePath sameAsResource1 = ResourcePath.discrete(D1, P1, VLAN1);
44 ResourcePath resource2 = ResourcePath.discrete(D2, P1, VLAN1);
45 ResourcePath resource3 = ResourcePath.continuous(BW1.bps(), D1, P1, BW1);
46 ResourcePath sameAsResource3 = ResourcePath.continuous(BW2.bps(), D1, P1, BW1);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070047
48 new EqualsTester()
49 .addEqualityGroup(resource1, sameAsResource1)
50 .addEqualityGroup(resource2)
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080051 .addEqualityGroup(resource3, sameAsResource3) // this is intentional
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070052 .testEquals();
53 }
54
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070055 @Test
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070056 public void testCreateWithZeroComponent() {
Sho SHIMIZU60ac58e2015-11-11 12:16:38 -080057 ResourcePath path = ResourcePath.discrete();
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070058
59 assertThat(path, is(ResourcePath.ROOT));
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070060 }
61
62 @Test
Sho SHIMIZU69dc5842015-11-20 16:31:12 -080063 public void testComponents() {
64 ResourcePath port = ResourcePath.discrete(D1, P1);
65
66 assertThat(port.components(), contains(D1, P1));
67 }
68
69 @Test
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070070 public void testThereIsParent() {
Sho SHIMIZU44f37612015-11-25 16:23:22 -080071 ResourcePath path = ResourcePath.discrete(D1, P1, VLAN1);
72 ResourcePath parent = ResourcePath.discrete(D1, P1);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070073
74 assertThat(path.parent(), is(Optional.of(parent)));
75 }
76
77 @Test
78 public void testNoParent() {
Sho SHIMIZU44f37612015-11-25 16:23:22 -080079 ResourcePath path = ResourcePath.discrete(D1);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070080
Sho SHIMIZUba41fc12015-08-12 15:43:22 -070081 assertThat(path.parent(), is(Optional.of(ResourcePath.ROOT)));
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070082 }
83
84 @Test
85 public void testBase() {
Sho SHIMIZU44f37612015-11-25 16:23:22 -080086 ResourcePath path = ResourcePath.discrete(D1);
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070087
Sho SHIMIZU44f37612015-11-25 16:23:22 -080088 DeviceId child = (DeviceId) path.last();
89 assertThat(child, is(D1));
Sho SHIMIZU1f5e5912015-08-10 17:00:00 -070090 }
91}