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.p4runtime.model; |
| 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.pi.model.PiMeterId; |
| 22 | import org.onosproject.net.pi.model.PiMeterModel; |
| 23 | import org.onosproject.net.pi.model.PiMeterType; |
| 24 | import org.onosproject.net.pi.model.PiTableId; |
| 25 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 26 | |
| 27 | /** |
| 28 | * Unit tests for P4MeterModel class. |
| 29 | */ |
| 30 | public class P4MeterModelTest { |
| 31 | |
| 32 | private static final PiMeterId PI_METER_ID_1 = PiMeterId.of("Meter1"); |
| 33 | private static final PiMeterId PI_METER_ID_2 = PiMeterId.of("Meter2"); |
| 34 | |
| 35 | private static final PiMeterType PI_METER_TYPE_1 = PiMeterType.DIRECT; |
| 36 | private static final PiMeterType PI_METER_TYPE_2 = PiMeterType.INDIRECT; |
| 37 | |
| 38 | private static final PiMeterModel.Unit PI_METER_MODEL_UNIT_1 = PiMeterModel.Unit.BYTES; |
| 39 | private static final PiMeterModel.Unit PI_METER_MODEL_UNIT_2 = PiMeterModel.Unit.PACKETS; |
| 40 | |
| 41 | private static final PiTableId PI_TABLE_ID_1 = PiTableId.of("Table1"); |
| 42 | private static final PiTableId PI_TABLE_ID_2 = PiTableId.of("Table2"); |
| 43 | |
| 44 | private static final long SIZE_1 = 100; |
| 45 | private static final long SIZE_2 = 200; |
| 46 | |
| 47 | private static final P4MeterModel P4_METER_MODEL_1 = |
| 48 | new P4MeterModel(PI_METER_ID_1, PI_METER_TYPE_1, PI_METER_MODEL_UNIT_1, PI_TABLE_ID_1, SIZE_1); |
| 49 | private static final P4MeterModel SAME_AS_P4_METER_MODEL_1 = |
| 50 | new P4MeterModel(PI_METER_ID_1, PI_METER_TYPE_1, PI_METER_MODEL_UNIT_1, PI_TABLE_ID_1, SIZE_1); |
| 51 | private static final P4MeterModel P4_METER_MODEL_2 = |
| 52 | new P4MeterModel(PI_METER_ID_2, PI_METER_TYPE_2, PI_METER_MODEL_UNIT_2, PI_TABLE_ID_2, SIZE_2); |
| 53 | private static final P4MeterModel P4_METER_MODEL_3 = |
| 54 | new P4MeterModel(PI_METER_ID_1, PI_METER_TYPE_2, PI_METER_MODEL_UNIT_1, PI_TABLE_ID_2, SIZE_1); |
| 55 | |
| 56 | /** |
| 57 | * Checks that the P4MeterModel class is immutable. |
| 58 | */ |
| 59 | @Test |
| 60 | public void testImmutability() { |
| 61 | assertThatClassIsImmutable(P4MeterModel.class); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 66 | */ |
| 67 | @Test |
| 68 | public void testEquals() { |
| 69 | new EqualsTester() |
| 70 | .addEqualityGroup(P4_METER_MODEL_1, SAME_AS_P4_METER_MODEL_1) |
| 71 | .addEqualityGroup(P4_METER_MODEL_2) |
| 72 | .addEqualityGroup(P4_METER_MODEL_3) |
| 73 | .testEquals(); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | } |