blob: 035465c10f3ec2b8fa3eaebe94ac7739dd9a99bd [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.testing.EqualsTester;
19import org.junit.Test;
20import org.onosproject.net.pi.model.PiActionParamId;
21
22import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
23
24/**
25 * Test for P4ActionParamModel class.
26 */
27public class P4ActionParamModelTest {
28 private final PiActionParamId piActionParamId = PiActionParamId.of("port");
29 private final PiActionParamId sameAsPiActionParamId = PiActionParamId.of("port");
30 private final PiActionParamId piActionParamId2 = PiActionParamId.of("dstAddr");
31
32 private static final int BIT_WIDTH_32 = 32;
33 private static final int BIT_WIDTH_64 = 64;
34
35 private final P4ActionParamModel actionParamModel = new P4ActionParamModel(piActionParamId, BIT_WIDTH_32);
36
37 private final P4ActionParamModel sameAsActionParamModel = new P4ActionParamModel(sameAsPiActionParamId,
38 BIT_WIDTH_32);
39
40 private final P4ActionParamModel actionParamModel2 = new P4ActionParamModel(piActionParamId2, BIT_WIDTH_32);
41
42 private final P4ActionParamModel actionParamModel3 = new P4ActionParamModel(piActionParamId, BIT_WIDTH_64);
43
44
45
46 /**
47 * Checks that the P4CounterModel class is immutable.
48 */
49 @Test
50 public void testImmutability() {
51 assertThatClassIsImmutable(P4ActionParamModel.class);
52 }
53
54 /**
55 * Checks the operation of equals(), hashCode() and toString() methods.
56 */
57 @Test
58 public void testEquals() {
59 new EqualsTester()
60 .addEqualityGroup(actionParamModel, sameAsActionParamModel)
61 .addEqualityGroup(actionParamModel2)
62 .addEqualityGroup(actionParamModel3)
63 .testEquals();
64 }
65}