blob: 998875acc4dd0b9a96f1e56b42773ef70ecb432d [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.PiControlMetadataId;
21
22import static org.junit.Assert.*;
23import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
24
25/**
26 * Test for P4ControlMetadataModel class.
27 */
28public class P4ControlMetadataModelTest {
29
30 private final PiControlMetadataId piControlMetadataId = PiControlMetadataId.of("EGRESS_PORT");
31 private final PiControlMetadataId sameAsPiControlMetadataId = PiControlMetadataId.of("EGRESS_PORT");
32 private final PiControlMetadataId piControlMetadataId2 = PiControlMetadataId.of("INGRESS_PORT");
33
34 private static final int BIT_WIDTH_32 = 32;
35 private static final int BIT_WIDTH_64 = 64;
36
37 private final P4ControlMetadataModel metadataModel = new P4ControlMetadataModel(piControlMetadataId, BIT_WIDTH_32);
38
39 private final P4ControlMetadataModel sameAsMetadataModel = new P4ControlMetadataModel(sameAsPiControlMetadataId,
40 BIT_WIDTH_32);
41
42 private final P4ControlMetadataModel metadataModel2 = new P4ControlMetadataModel(piControlMetadataId2,
43 BIT_WIDTH_32);
44
45 private final P4ControlMetadataModel metadataModel3 = new P4ControlMetadataModel(piControlMetadataId, BIT_WIDTH_64);
46
47
48
49 /**
50 * Checks that the P4CounterModel class is immutable.
51 */
52 @Test
53 public void testImmutability() {
54 assertThatClassIsImmutable(P4ControlMetadataModel.class);
55 }
56
57 /**
58 * Checks the operation of equals(), hashCode() and toString() methods.
59 */
60 @Test
61 public void testEquals() {
62 new EqualsTester()
63 .addEqualityGroup(metadataModel, sameAsMetadataModel)
64 .addEqualityGroup(metadataModel2)
65 .addEqualityGroup(metadataModel3)
66 .testEquals();
67 }
68}