blob: 3042414d9a97d46b5271758a209f757ea7d7a084 [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
24
25import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
26
27/**
28 * Test for P4ActionProfile class.
29 */
30public class P4ActionProfileModelTest {
31
32 private static final String TABLE_0 = "table0";
33 private static final String WCMP_TABLE = "wcmp_table";
34
35 private final PiTableId tableId = PiTableId.of(TABLE_0);
36 private final PiTableId sameAsTableId = PiTableId.of(TABLE_0);
37 private final PiTableId tableId2 = PiTableId.of(WCMP_TABLE);
38
39 private final ImmutableSet<PiTableId> tables = new ImmutableSet.Builder<PiTableId>()
40 .add(tableId, tableId2)
41 .build();
42
43 private final ImmutableSet<PiTableId> sameAsTables = new ImmutableSet.Builder<PiTableId>()
44 .add(sameAsTableId, tableId2)
45 .build();
46
47 private final ImmutableSet<PiTableId> tables2 = new ImmutableSet.Builder<PiTableId>()
48 .add(tableId, sameAsTableId)
49 .build();
50
51 private final PiActionProfileId id = PiActionProfileId.of("name");
52 private final PiActionProfileId id2 = PiActionProfileId.of("name2");
53
54 private final P4ActionProfileModel metadataModel = new P4ActionProfileModel(id, tables,
55 true, 64);
56 private final P4ActionProfileModel sameAsMetadataModel = new P4ActionProfileModel(id, sameAsTables,
57 true, 64);
58 private final P4ActionProfileModel metadataModel2 = new P4ActionProfileModel(id, tables2,
59 true, 64);
60 private final P4ActionProfileModel metadataModel3 = new P4ActionProfileModel(id2, tables,
61 true, 64);
62 private final P4ActionProfileModel metadataModel4 = new P4ActionProfileModel(id, tables,
63 false, 64);
64 private final P4ActionProfileModel metadataModel5 = new P4ActionProfileModel(id, tables,
65 true, 32);
66
67 /**
68 * Checks that the P4ActionProfileModel class is immutable.
69 */
70 @Test
71 public void testImmutability() {
72 assertThatClassIsImmutable(P4ActionProfileModel.class);
73 }
74
75 /**
76 * Checks the operation of equals(), hashCode() and toString() methods.
77 */
78 @Test
79 public void testEquals() {
80 new EqualsTester()
81 .addEqualityGroup(metadataModel, sameAsMetadataModel)
82 .addEqualityGroup(metadataModel2)
83 .addEqualityGroup(metadataModel3)
84 .addEqualityGroup(metadataModel4)
85 .addEqualityGroup(metadataModel5)
86 .testEquals();
87 }
88}