Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.PortNumber; |
| 22 | |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.contains; |
| 25 | import static org.hamcrest.Matchers.is; |
| 26 | |
| 27 | /** |
| 28 | * Tests for {@link PiMulticastGroupEntry}. |
| 29 | */ |
| 30 | public class PiMulticastGroupEntryTest { |
Carmelo Cascone | 03ae0ac | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 31 | private final int groupId1 = 1; |
| 32 | private final int groupId2 = 2; |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 33 | |
Carmelo Cascone | 03ae0ac | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 34 | private final int instanceId1 = 1; |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 35 | |
| 36 | private final PortNumber port1 = PortNumber.portNumber(1); |
| 37 | private final PortNumber port2 = PortNumber.portNumber(2); |
| 38 | private final PortNumber port3 = PortNumber.portNumber(3); |
| 39 | |
| 40 | private final PiPreReplica replica1 = new PiPreReplica(port1, instanceId1); |
| 41 | private final PiPreReplica replica2 = new PiPreReplica(port2, instanceId1); |
| 42 | private final PiPreReplica replica3 = new PiPreReplica(port3, instanceId1); |
| 43 | |
| 44 | private final PiMulticastGroupEntry group1 = PiMulticastGroupEntry.builder() |
| 45 | .withGroupId(groupId1) |
| 46 | .addReplica(replica1) |
| 47 | .addReplica(replica2) |
| 48 | .build(); |
| 49 | |
| 50 | private final PiMulticastGroupEntry sameAsGroup1 = PiMulticastGroupEntry.builder() |
| 51 | .withGroupId(groupId1) |
| 52 | .addReplica(replica1) |
| 53 | .addReplica(replica2) |
| 54 | .build(); |
| 55 | |
| 56 | private final PiMulticastGroupEntry group2 = PiMulticastGroupEntry.builder() |
| 57 | .withGroupId(groupId2) |
| 58 | .addReplica(replica1) |
| 59 | .addReplica(replica2) |
| 60 | .addReplica(replica3) |
| 61 | .build(); |
| 62 | |
| 63 | @Test |
| 64 | public void testPiMulticastGroupEntry() { |
| 65 | assertThat("Invalid group ID", |
| 66 | group1.groupId(), is(groupId1)); |
| 67 | assertThat("Invalid replicas size", |
| 68 | group1.replicas().size(), is(2)); |
| 69 | assertThat("Invalid replicas", |
| 70 | group1.replicas(), contains(replica1, replica2)); |
| 71 | |
| 72 | assertThat("Invalid group ID", |
| 73 | group2.groupId(), is(groupId2)); |
| 74 | assertThat("Invalid replicas size", |
| 75 | group2.replicas().size(), is(3)); |
| 76 | assertThat("Invalid replicas", |
| 77 | group2.replicas(), contains(replica1, replica2, replica3)); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void testEquality() { |
| 82 | new EqualsTester() |
| 83 | .addEqualityGroup(group1, sameAsGroup1) |
| 84 | .addEqualityGroup(group2) |
| 85 | .testEquals(); |
| 86 | } |
| 87 | } |