Ekber Aziz | 123ad5d | 2017-11-27 12:36:35 -0800 | [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 | package org.onosproject.p4runtime.model; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.net.pi.model.PiCounterId; |
| 21 | import org.onosproject.net.pi.model.PiCounterModel; |
| 22 | import org.onosproject.net.pi.model.PiCounterType; |
| 23 | import org.onosproject.net.pi.model.PiTableId; |
| 24 | |
| 25 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 26 | |
| 27 | /** |
| 28 | * Test for P4CounterModel class. |
| 29 | */ |
| 30 | public class P4CounterModelTest { |
| 31 | private static final String TABLE_0 = "table0"; |
| 32 | private static final String WCMP_TABLE = "wcmp_table"; |
| 33 | |
| 34 | private final PiTableId tableId = PiTableId.of(TABLE_0); |
| 35 | private final PiTableId sameAsTableId = PiTableId.of(TABLE_0); |
| 36 | private final PiTableId tableId2 = PiTableId.of(WCMP_TABLE); |
| 37 | |
| 38 | private final PiCounterId counterId = PiCounterId.of("name"); |
| 39 | |
| 40 | private final P4CounterModel counterModel = new P4CounterModel(counterId, PiCounterType.DIRECT, |
| 41 | PiCounterModel.Unit.BYTES, tableId, 16); |
| 42 | |
| 43 | private final P4CounterModel sameAsCounterModel = new P4CounterModel(counterId, PiCounterType.DIRECT, |
| 44 | PiCounterModel.Unit.BYTES, sameAsTableId, 16); |
| 45 | |
| 46 | private final P4CounterModel counterModel2 = new P4CounterModel(counterId, PiCounterType.INDIRECT, |
| 47 | PiCounterModel.Unit.BYTES, tableId, 16); |
| 48 | |
| 49 | private final P4CounterModel counterModel3 = new P4CounterModel(counterId, PiCounterType.DIRECT, |
| 50 | PiCounterModel.Unit.PACKETS, tableId, 16); |
| 51 | |
| 52 | private final P4CounterModel counterModel4 = new P4CounterModel(counterId, PiCounterType.DIRECT, |
| 53 | PiCounterModel.Unit.BYTES, tableId2, 16); |
| 54 | |
| 55 | private final P4CounterModel counterModel5 = new P4CounterModel(counterId, PiCounterType.DIRECT, |
| 56 | PiCounterModel.Unit.BYTES, tableId, 32); |
| 57 | /** |
| 58 | * Checks that the P4CounterModel class is immutable. |
| 59 | */ |
| 60 | @Test |
| 61 | public void testImmutability() { |
| 62 | assertThatClassIsImmutable(P4CounterModel.class); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 67 | */ |
| 68 | @Test |
| 69 | public void testEquals() { |
| 70 | new EqualsTester() |
| 71 | .addEqualityGroup(counterModel, sameAsCounterModel) |
| 72 | .addEqualityGroup(counterModel2) |
| 73 | .addEqualityGroup(counterModel3) |
| 74 | .addEqualityGroup(counterModel4) |
| 75 | .addEqualityGroup(counterModel5) |
| 76 | .testEquals(); |
| 77 | } |
| 78 | } |