blob: 310b8363c8e8361552d23806a48ecdbf1595227d [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;
Carmelo Cascone4c289b72019-01-22 15:30:45 -080021import org.onosproject.net.pi.model.PiPacketMetadataId;
Frank Wang4e848042017-08-03 19:48:11 +080022
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.is;
25import static org.hamcrest.Matchers.notNullValue;
26import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
27import static org.onosproject.net.pi.runtime.PiConstantsTest.EGRESS_PORT;
28import static org.onosproject.net.pi.runtime.PiConstantsTest.INGRESS_PORT;
29
30/**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080031 * Unit tests for PiPacketMetadataId class.
Frank Wang4e848042017-08-03 19:48:11 +080032 */
Carmelo Cascone4c289b72019-01-22 15:30:45 -080033public class PiPacketMetadataIdTest {
Frank Wang4e848042017-08-03 19:48:11 +080034
Carmelo Cascone4c289b72019-01-22 15:30:45 -080035 final PiPacketMetadataId piPacketMetadataId1 = PiPacketMetadataId.of(EGRESS_PORT);
36 final PiPacketMetadataId sameAsPiPacketMetadataId1 = PiPacketMetadataId.of(EGRESS_PORT);
37 final PiPacketMetadataId piPacketMetadataId2 = PiPacketMetadataId.of(INGRESS_PORT);
Frank Wang4e848042017-08-03 19:48:11 +080038
39 /**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080040 * Checks that the PiPacketMetadataId class is immutable.
Frank Wang4e848042017-08-03 19:48:11 +080041 */
42 @Test
43 public void testImmutability() {
44
Carmelo Cascone4c289b72019-01-22 15:30:45 -080045 assertThatClassIsImmutable(PiPacketMetadataId.class);
Frank Wang4e848042017-08-03 19:48:11 +080046 }
47
48 /**
49 * Checks the operation of equals(), hashCode() and toString() methods.
50 */
51 @Test
52 public void testEquals() {
53
54 new EqualsTester()
Carmelo Cascone4c289b72019-01-22 15:30:45 -080055 .addEqualityGroup(piPacketMetadataId1, sameAsPiPacketMetadataId1)
56 .addEqualityGroup(piPacketMetadataId2)
Frank Wang4e848042017-08-03 19:48:11 +080057 .testEquals();
58 }
59
60 /**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080061 * Checks the methods of PiPacketMetadataId.
Frank Wang4e848042017-08-03 19:48:11 +080062 */
63 @Test
64 public void testMethods() {
Carmelo Cascone4c289b72019-01-22 15:30:45 -080065 assertThat(piPacketMetadataId1, is(notNullValue()));
66 assertThat(piPacketMetadataId1.id(), is(EGRESS_PORT));
Frank Wang4e848042017-08-03 19:48:11 +080067 }
68}