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 | 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.PiMatchFieldId; |
| 21 | import org.onosproject.net.pi.model.PiMatchType; |
| 22 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 23 | |
| 24 | /** |
| 25 | * Unit tests for P4MatchFieldModel class. |
| 26 | */ |
| 27 | public class P4MatchFieldModelTest { |
| 28 | |
| 29 | private static final PiMatchFieldId PI_MATCH_FIELD_ID_1 = PiMatchFieldId.of("MatchField1"); |
| 30 | private static final PiMatchFieldId PI_MATCH_FIELD_ID_2 = PiMatchFieldId.of("MatchField2"); |
| 31 | |
| 32 | private static final int BIT_WIDTH_1 = 100; |
| 33 | private static final int BIT_WIDTH_2 = 200; |
| 34 | |
| 35 | private static final PiMatchType PI_MATCH_TYPE_1 = PiMatchType.EXACT; |
| 36 | private static final PiMatchType PI_MATCH_TYPE_2 = PiMatchType.TERNARY; |
| 37 | |
| 38 | private static final P4MatchFieldModel P4_MATCH_FIELD_MODEL_1 = |
| 39 | new P4MatchFieldModel(PI_MATCH_FIELD_ID_1, BIT_WIDTH_1, PI_MATCH_TYPE_1); |
| 40 | private static final P4MatchFieldModel SAME_AS_P4_MATCH_FIELD_MODEL_1 = |
| 41 | new P4MatchFieldModel(PI_MATCH_FIELD_ID_1, BIT_WIDTH_1, PI_MATCH_TYPE_1); |
| 42 | private static final P4MatchFieldModel P4_MATCH_FIELD_MODEL_2 = |
| 43 | new P4MatchFieldModel(PI_MATCH_FIELD_ID_2, BIT_WIDTH_2, PI_MATCH_TYPE_2); |
| 44 | |
| 45 | /** |
| 46 | * Checks that the P4MatchFieldModel class is immutable. |
| 47 | */ |
| 48 | @Test |
| 49 | public void testImmutability() { |
| 50 | assertThatClassIsImmutable(P4MatchFieldModel.class); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 55 | */ |
| 56 | @Test |
| 57 | public void testEquals() { |
| 58 | new EqualsTester() |
| 59 | .addEqualityGroup(P4_MATCH_FIELD_MODEL_1, SAME_AS_P4_MATCH_FIELD_MODEL_1) |
| 60 | .addEqualityGroup(P4_MATCH_FIELD_MODEL_2) |
| 61 | .testEquals(); |
| 62 | } |
| 63 | } |