Sho SHIMIZU | 4ecaeea | 2015-07-27 11:49:57 -0700 | [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 | 4ecaeea | 2015-07-27 11:49:57 -0700 | [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 | 4ecaeea | 2015-07-27 11:49:57 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | import org.onlab.packet.VlanId; |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 21 | import org.onlab.util.Identifier; |
Sho SHIMIZU | 4ecaeea | 2015-07-27 11:49:57 -0700 | [diff] [blame] | 22 | import org.onosproject.net.DeviceId; |
Sho SHIMIZU | 4ecaeea | 2015-07-27 11:49:57 -0700 | [diff] [blame] | 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.net.intent.IntentId; |
| 25 | |
| 26 | public 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 Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 31 | private static final PortNumber P2 = PortNumber.portNumber(2); |
Sho SHIMIZU | 4ecaeea | 2015-07-27 11:49:57 -0700 | [diff] [blame] | 32 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 33 | 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 SHIMIZU | 4ecaeea | 2015-07-27 11:49:57 -0700 | [diff] [blame] | 41 | |
| 42 | @Test |
| 43 | public void testEquals() { |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 44 | 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 SHIMIZU | 4ecaeea | 2015-07-27 11:49:57 -0700 | [diff] [blame] | 48 | |
| 49 | new EqualsTester() |
| 50 | .addEqualityGroup(alloc1, sameAsAlloc1) |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 51 | .addEqualityGroup(alloc2, sameAsAlloc2) |
Sho SHIMIZU | 4ecaeea | 2015-07-27 11:49:57 -0700 | [diff] [blame] | 52 | .testEquals(); |
| 53 | } |
Naoki Shiota | bd1974c | 2016-04-29 18:44:17 -0700 | [diff] [blame] | 54 | |
| 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 SHIMIZU | 4ecaeea | 2015-07-27 11:49:57 -0700 | [diff] [blame] | 65 | } |