blob: a2ee50f502396019fc26c526981968285d0f42b4 [file] [log] [blame]
Frank Wang4e848042017-08-03 19:48:11 +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 */
16
17package org.onosproject.net.pi.runtime;
18
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.is;
24import static org.hamcrest.Matchers.notNullValue;
25import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
26import static org.onosproject.net.pi.runtime.PiConstantsTest.EGRESS_PORT;
27import static org.onosproject.net.pi.runtime.PiConstantsTest.INGRESS_PORT;
28
29/**
30 * Unit tests for PiPacketMetadataId class.
31 */
32public class PiPacketMetadataIdTest {
33
34 final PiPacketMetadataId piPacketMetadataId1 = PiPacketMetadataId.of(EGRESS_PORT);
35 final PiPacketMetadataId sameAsPiPacketMetadataId1 = PiPacketMetadataId.of(EGRESS_PORT);
36 final PiPacketMetadataId piPacketMetadataId2 = PiPacketMetadataId.of(INGRESS_PORT);
37
38 /**
39 * Checks that the PiPacketMetadataId class is immutable.
40 */
41 @Test
42 public void testImmutability() {
43
44 assertThatClassIsImmutable(PiPacketMetadataId.class);
45 }
46
47 /**
48 * Checks the operation of equals(), hashCode() and toString() methods.
49 */
50 @Test
51 public void testEquals() {
52
53 new EqualsTester()
54 .addEqualityGroup(piPacketMetadataId1, sameAsPiPacketMetadataId1)
55 .addEqualityGroup(piPacketMetadataId2)
56 .testEquals();
57 }
58
59 /**
60 * Checks the methods of PiPacketMetadataId.
61 */
62 @Test
63 public void testMethods() {
64
65 assertThat(piPacketMetadataId1, is(notNullValue()));
66 assertThat(piPacketMetadataId1.name(), is(EGRESS_PORT));
67 }
68}