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