blob: 021d341b63379589d264e63d154ebd3bf8e5a8d6 [file] [log] [blame]
Ekber Aziz123ad5d2017-11-27 12:36:35 -08001/*
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 */
16package org.onosproject.p4runtime.model;
17
18import com.google.common.collect.ImmutableSet;
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21import org.onosproject.net.pi.model.PiActionProfileId;
22import org.onosproject.net.pi.model.PiTableId;
23
Ekber Aziz123ad5d2017-11-27 12:36:35 -080024import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25
26/**
27 * Test for P4ActionProfile class.
28 */
29public 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 Cascone99c59db2019-01-17 15:39:35 -080054 true, 64, 10);
Ekber Aziz123ad5d2017-11-27 12:36:35 -080055 private final P4ActionProfileModel sameAsMetadataModel = new P4ActionProfileModel(id, sameAsTables,
Carmelo Cascone99c59db2019-01-17 15:39:35 -080056 true, 64, 10);
Ekber Aziz123ad5d2017-11-27 12:36:35 -080057 private final P4ActionProfileModel metadataModel2 = new P4ActionProfileModel(id, tables2,
Carmelo Cascone99c59db2019-01-17 15:39:35 -080058 true, 64, 10);
Ekber Aziz123ad5d2017-11-27 12:36:35 -080059 private final P4ActionProfileModel metadataModel3 = new P4ActionProfileModel(id2, tables,
Carmelo Cascone99c59db2019-01-17 15:39:35 -080060 true, 64, 10);
Ekber Aziz123ad5d2017-11-27 12:36:35 -080061 private final P4ActionProfileModel metadataModel4 = new P4ActionProfileModel(id, tables,
Carmelo Cascone99c59db2019-01-17 15:39:35 -080062 false, 64, 10);
Ekber Aziz123ad5d2017-11-27 12:36:35 -080063 private final P4ActionProfileModel metadataModel5 = new P4ActionProfileModel(id, tables,
Carmelo Cascone99c59db2019-01-17 15:39:35 -080064 true, 32, 5);
Ekber Aziz123ad5d2017-11-27 12:36:35 -080065
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 Cascone99c59db2019-01-17 15:39:35 -080087}