blob: 7c060ef4e53c779db677b9c70b33f6e26ea39c5f [file] [log] [blame]
Carmelo Cascone58136812018-07-19 03:40:16 +02001/*
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
17package org.onosproject.net.pi.runtime;
18
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21import org.onosproject.net.PortNumber;
22
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.contains;
25import static org.hamcrest.Matchers.is;
26
27/**
28 * Tests for {@link PiMulticastGroupEntry}.
29 */
30public class PiMulticastGroupEntryTest {
31 private final long groupId1 = 1;
32 private final long groupId2 = 2;
33
34 private final long instanceId1 = 1;
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}