Committed by
Gerrit Code Review
Add unit test to check equality for resource constructs
Change-Id: Iaf23c6c634ffd77c13578256ebb7e57d5626d1bb
Showing
2 changed files
with
100 additions
and
0 deletions
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.net.newresource; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | +import org.onlab.packet.VlanId; | ||
21 | +import org.onosproject.net.ConnectPoint; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.LinkKey; | ||
24 | +import org.onosproject.net.PortNumber; | ||
25 | + | ||
26 | +public class DefaultResourceTest { | ||
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); | ||
31 | + private static final ConnectPoint CP1_1 = new ConnectPoint(D1, P1); | ||
32 | + private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); | ||
33 | + private static final VlanId VLAN1 = VlanId.vlanId((short) 100); | ||
34 | + | ||
35 | + @Test | ||
36 | + public void testEquals() { | ||
37 | + DefaultResource<LinkKey, VlanId> resource1 = | ||
38 | + new DefaultResource<>(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); | ||
39 | + DefaultResource<LinkKey, VlanId> sameAsResource1 = | ||
40 | + new DefaultResource<>(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); | ||
41 | + DefaultResource<LinkKey, VlanId> resource2 = | ||
42 | + new DefaultResource<>(LinkKey.linkKey(CP2_1, CP1_1), VLAN1); | ||
43 | + | ||
44 | + new EqualsTester() | ||
45 | + .addEqualityGroup(resource1, sameAsResource1) | ||
46 | + .addEqualityGroup(resource2) | ||
47 | + .testEquals(); | ||
48 | + } | ||
49 | +} |
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.net.newresource; | ||
17 | + | ||
18 | +import com.google.common.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | +import org.onlab.packet.VlanId; | ||
21 | +import org.onosproject.net.ConnectPoint; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.LinkKey; | ||
24 | +import org.onosproject.net.PortNumber; | ||
25 | +import org.onosproject.net.intent.IntentId; | ||
26 | + | ||
27 | +public class ResourceAllocationTest { | ||
28 | + | ||
29 | + private static final DeviceId D1 = DeviceId.deviceId("of:001"); | ||
30 | + private static final DeviceId D2 = DeviceId.deviceId("of:002"); | ||
31 | + private static final PortNumber P1 = PortNumber.portNumber(1); | ||
32 | + private static final ConnectPoint CP1_1 = new ConnectPoint(D1, P1); | ||
33 | + private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); | ||
34 | + private static final VlanId VLAN1 = VlanId.vlanId((short) 100); | ||
35 | + private static final IntentId IID1 = IntentId.valueOf(30); | ||
36 | + | ||
37 | + @Test | ||
38 | + public void testEquals() { | ||
39 | + DefaultResourceAllocation<LinkKey, VlanId> alloc1 = | ||
40 | + new DefaultResourceAllocation<>(LinkKey.linkKey(CP1_1, CP2_1), VLAN1, IID1); | ||
41 | + DefaultResourceAllocation<LinkKey, VlanId> sameAsAlloc1 = | ||
42 | + new DefaultResourceAllocation<>(LinkKey.linkKey(CP1_1, CP2_1), VLAN1, IID1); | ||
43 | + DefaultResourceAllocation<LinkKey, VlanId> alloc2 = | ||
44 | + new DefaultResourceAllocation<>(LinkKey.linkKey(CP2_1, CP1_1), VLAN1, IID1); | ||
45 | + | ||
46 | + new EqualsTester() | ||
47 | + .addEqualityGroup(alloc1, sameAsAlloc1) | ||
48 | + .addEqualityGroup(alloc2) | ||
49 | + .testEquals(); | ||
50 | + } | ||
51 | +} |
-
Please register or login to post a comment