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