blob: d65ef2eb1b963de391167e2f4b5b85f0656e5b7a [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 Cascone87892e22017-11-13 16:01:29 -080021import org.onosproject.net.pi.model.PiControlMetadataId;
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 Cascone87892e22017-11-13 16:01:29 -080031 * Unit tests for PiControlMetadataId class.
Frank Wang4e848042017-08-03 19:48:11 +080032 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080033public class PiControlMetadataIdTest {
Frank Wang4e848042017-08-03 19:48:11 +080034
Carmelo Cascone87892e22017-11-13 16:01:29 -080035 final PiControlMetadataId piControlMetadataId1 = PiControlMetadataId.of(EGRESS_PORT);
36 final PiControlMetadataId sameAsPiControlMetadataId1 = PiControlMetadataId.of(EGRESS_PORT);
37 final PiControlMetadataId piControlMetadataId2 = PiControlMetadataId.of(INGRESS_PORT);
Frank Wang4e848042017-08-03 19:48:11 +080038
39 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080040 * Checks that the PiControlMetadataId class is immutable.
Frank Wang4e848042017-08-03 19:48:11 +080041 */
42 @Test
43 public void testImmutability() {
44
Carmelo Cascone87892e22017-11-13 16:01:29 -080045 assertThatClassIsImmutable(PiControlMetadataId.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 Cascone87892e22017-11-13 16:01:29 -080055 .addEqualityGroup(piControlMetadataId1, sameAsPiControlMetadataId1)
56 .addEqualityGroup(piControlMetadataId2)
Frank Wang4e848042017-08-03 19:48:11 +080057 .testEquals();
58 }
59
60 /**
Carmelo Cascone87892e22017-11-13 16:01:29 -080061 * Checks the methods of PiControlMetadataId.
Frank Wang4e848042017-08-03 19:48:11 +080062 */
63 @Test
64 public void testMethods() {
Carmelo Cascone87892e22017-11-13 16:01:29 -080065 assertThat(piControlMetadataId1, is(notNullValue()));
66 assertThat(piControlMetadataId1.id(), is(EGRESS_PORT));
Frank Wang4e848042017-08-03 19:48:11 +080067 }
68}