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.collect.ImmutableSet; |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.pi.model.PiActionProfileId; |
| 22 | import org.onosproject.net.pi.model.PiTableId; |
| 23 | |
Ekber Aziz | 123ad5d | 2017-11-27 12:36:35 -0800 | [diff] [blame] | 24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 25 | |
| 26 | /** |
| 27 | * Test for P4ActionProfile class. |
| 28 | */ |
| 29 | public class P4ActionProfileModelTest { |
| 30 | |
| 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 ImmutableSet<PiTableId> tables = new ImmutableSet.Builder<PiTableId>() |
| 39 | .add(tableId, tableId2) |
| 40 | .build(); |
| 41 | |
| 42 | private final ImmutableSet<PiTableId> sameAsTables = new ImmutableSet.Builder<PiTableId>() |
| 43 | .add(sameAsTableId, tableId2) |
| 44 | .build(); |
| 45 | |
| 46 | private final ImmutableSet<PiTableId> tables2 = new ImmutableSet.Builder<PiTableId>() |
| 47 | .add(tableId, sameAsTableId) |
| 48 | .build(); |
| 49 | |
| 50 | private final PiActionProfileId id = PiActionProfileId.of("name"); |
| 51 | private final PiActionProfileId id2 = PiActionProfileId.of("name2"); |
| 52 | |
| 53 | private final P4ActionProfileModel metadataModel = new P4ActionProfileModel(id, tables, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 54 | true, 64, 10); |
Ekber Aziz | 123ad5d | 2017-11-27 12:36:35 -0800 | [diff] [blame] | 55 | private final P4ActionProfileModel sameAsMetadataModel = new P4ActionProfileModel(id, sameAsTables, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 56 | true, 64, 10); |
Ekber Aziz | 123ad5d | 2017-11-27 12:36:35 -0800 | [diff] [blame] | 57 | private final P4ActionProfileModel metadataModel2 = new P4ActionProfileModel(id, tables2, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 58 | true, 64, 10); |
Ekber Aziz | 123ad5d | 2017-11-27 12:36:35 -0800 | [diff] [blame] | 59 | private final P4ActionProfileModel metadataModel3 = new P4ActionProfileModel(id2, tables, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 60 | true, 64, 10); |
Ekber Aziz | 123ad5d | 2017-11-27 12:36:35 -0800 | [diff] [blame] | 61 | private final P4ActionProfileModel metadataModel4 = new P4ActionProfileModel(id, tables, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 62 | false, 64, 10); |
Ekber Aziz | 123ad5d | 2017-11-27 12:36:35 -0800 | [diff] [blame] | 63 | private final P4ActionProfileModel metadataModel5 = new P4ActionProfileModel(id, tables, |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 64 | true, 32, 5); |
Ekber Aziz | 123ad5d | 2017-11-27 12:36:35 -0800 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Checks that the P4ActionProfileModel class is immutable. |
| 68 | */ |
| 69 | @Test |
| 70 | public void testImmutability() { |
| 71 | assertThatClassIsImmutable(P4ActionProfileModel.class); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 76 | */ |
| 77 | @Test |
| 78 | public void testEquals() { |
| 79 | new EqualsTester() |
| 80 | .addEqualityGroup(metadataModel, sameAsMetadataModel) |
| 81 | .addEqualityGroup(metadataModel2) |
| 82 | .addEqualityGroup(metadataModel3) |
| 83 | .addEqualityGroup(metadataModel4) |
| 84 | .addEqualityGroup(metadataModel5) |
| 85 | .testEquals(); |
| 86 | } |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 87 | } |