blob: 4104050c6f53449efd09339a62a0630958e2adad [file] [log] [blame]
Mehmed Mustafa3e269df2017-11-24 17:19:49 +03001/*
2 * Copyright 2017-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.pi.model.PiActionId;
22import org.onosproject.net.pi.model.PiCounterId;
23import org.onosproject.net.pi.model.PiTableId;
24
25import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
26import static org.onosproject.net.pi.runtime.PiConstantsTest.DROP;
27
28/**
29 * Unit tests for PiCounterCellData class.
30 */
31public class PiCounterCellDataTest {
32
33 private static final PiCounterId PI_COUNTER_ID_1 = PiCounterId.of("Name1");
34 private static final PiCounterId PI_COUNTER_ID_2 = PiCounterId.of("Name2");
35
36 private static final PiTableEntry PI_TABLE_ENTRY_1 = PiTableEntry.builder()
37 .forTable(PiTableId.of("T10"))
38 .withCookie(0xac)
39 .withPriority(10)
40 .withAction(PiAction.builder().withId(PiActionId.of(DROP)).build())
41 .withTimeout(100)
42 .build();
43 private static final PiTableEntry PI_TABLE_ENTRY_2 = PiTableEntry.builder()
44 .forTable(PiTableId.of("T20"))
45 .withCookie(0xac)
46 .withPriority(10)
47 .withAction(PiAction.builder().withId(PiActionId.of(DROP)).build())
48 .withTimeout(1000)
49 .build();
50
51 private static final PiCounterCellId PI_COUNTER_CELL_ID_1 =
52 PiCounterCellId.ofDirect(PI_COUNTER_ID_1, PI_TABLE_ENTRY_1);
53 private static final PiCounterCellId PI_COUNTER_CELL_ID_2 =
54 PiCounterCellId.ofDirect(PI_COUNTER_ID_2, PI_TABLE_ENTRY_2);
55
56 private static final long PACKETS_1 = 10;
57 private static final long PACKETS_2 = 20;
58 private static final long BYTES_1 = 100;
59 private static final long BYTES_2 = 200;
60
61 private static final PiCounterCellData PI_COUNTER_CELL_DATA_1 =
62 new PiCounterCellData(PI_COUNTER_CELL_ID_1, PACKETS_1, BYTES_1);
63 private static final PiCounterCellData SAME_AS_PI_COUNTER_CELL_DATA_1 =
64 new PiCounterCellData(PI_COUNTER_CELL_ID_1, PACKETS_1, BYTES_1);
65 private static final PiCounterCellData PI_COUNTER_CELL_DATA_2 =
66 new PiCounterCellData(PI_COUNTER_CELL_ID_2, PACKETS_2, BYTES_2);
67
68 /**
69 * Checks that the PiCounterCellData class is immutable.
70 */
71 @Test
72 public void testImmutability() {
73 assertThatClassIsImmutable(PiCounterCellData.class);
74 }
75
76 /**
77 * Checks the operation of equals(), hashCode() and toString() methods.
78 */
79 @Test
80 public void testEquals() {
81 new EqualsTester()
82 .addEqualityGroup(PI_COUNTER_CELL_DATA_1, SAME_AS_PI_COUNTER_CELL_DATA_1)
83 .addEqualityGroup(PI_COUNTER_CELL_DATA_2)
84 .testEquals();
85 }
86}