blob: 0c2adb5125e7cd3adf1f50f5430be2efcf841148 [file] [log] [blame]
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -07003 *
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 SHIMIZU4ecaeea2015-07-27 11:49:57 -070017
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.packet.VlanId;
Naoki Shiotabd1974c2016-04-29 18:44:17 -070021import org.onlab.util.Identifier;
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -070022import org.onosproject.net.DeviceId;
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -070023import org.onosproject.net.PortNumber;
24import org.onosproject.net.intent.IntentId;
25
26public class ResourceAllocationTest {
27
28 private static final DeviceId D1 = DeviceId.deviceId("of:001");
29 private static final DeviceId D2 = DeviceId.deviceId("of:002");
30 private static final PortNumber P1 = PortNumber.portNumber(1);
Naoki Shiotabd1974c2016-04-29 18:44:17 -070031 private static final PortNumber P2 = PortNumber.portNumber(2);
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -070032 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
Naoki Shiotabd1974c2016-04-29 18:44:17 -070033 private static final VlanId VLAN2 = VlanId.vlanId((short) 200);
34 private static final TestResourceConsumer RC2 = new TestResourceConsumer(2L);
35
36 // ResourceConsumerId generated by specifying ID and class name
37 private static final ResourceConsumerId RCID1 = ResourceConsumerId.of(30L, IntentId.class);
38
39 // ResourceConsumerId generated from Identifier<Long> class
40 private static final ResourceConsumerId RCID2 = ResourceConsumerId.of(RC2);
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -070041
42 @Test
43 public void testEquals() {
Naoki Shiotabd1974c2016-04-29 18:44:17 -070044 ResourceAllocation alloc1 = new ResourceAllocation(Resources.discrete(D1, P1, VLAN1).resource(), RCID1);
45 ResourceAllocation sameAsAlloc1 = new ResourceAllocation(Resources.discrete(D1, P1, VLAN1).resource(), RCID1);
46 ResourceAllocation alloc2 = new ResourceAllocation(Resources.discrete(D2, P2, VLAN2).resource(), RCID2);
47 ResourceAllocation sameAsAlloc2 = new ResourceAllocation(Resources.discrete(D2, P2, VLAN2).resource(), RCID2);
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -070048
49 new EqualsTester()
50 .addEqualityGroup(alloc1, sameAsAlloc1)
Naoki Shiotabd1974c2016-04-29 18:44:17 -070051 .addEqualityGroup(alloc2, sameAsAlloc2)
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -070052 .testEquals();
53 }
Naoki Shiotabd1974c2016-04-29 18:44:17 -070054
55 private static class TestResourceConsumer extends Identifier<Long> implements ResourceConsumer {
56 public TestResourceConsumer(long idValue) {
57 super(idValue);
58 }
59
60 @Override
61 public ResourceConsumerId consumerId() {
62 return ResourceConsumerId.of(this);
63 }
64 }
Sho SHIMIZU4ecaeea2015-07-27 11:49:57 -070065}