blob: 262a50ff3e37a7c989fc783cc90fd22c467a9076 [file] [log] [blame]
Frank Wange33e4ed2017-06-28 10:01:07 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Frank Wange33e4ed2017-06-28 10:01:07 +08003 *
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.PiActionId;
Frank Wange33e4ed2017-06-28 10:01:07 +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.DEC_TTL;
28import static org.onosproject.net.pi.runtime.PiConstantsTest.MOD_VLAN_VID;
29
30/**
31 * Unit tests for PiActionId class.
32 */
33public class PiActionIdTest {
34 final String id1 = DEC_TTL;
35 final String id2 = MOD_VLAN_VID;
36 final PiActionId actionId1 = PiActionId.of(id1);
37 final PiActionId sameAsActionId1 = PiActionId.of(id1);
38 final PiActionId actionId2 = PiActionId.of(id2);
39
40 /**
41 * Checks that the PiActionId class is immutable.
42 */
43 @Test
44 public void testImmutability() {
45 assertThatClassIsImmutable(PiActionId.class);
46 }
47
48 /**
49 * Checks the operation of equals(), hashCode() and toString() methods.
50 */
51 @Test
52 public void testEquals() {
53 new EqualsTester()
54 .addEqualityGroup(actionId1, sameAsActionId1)
55 .addEqualityGroup(actionId2)
56 .testEquals();
57 }
58
59 /**
60 * Checks the construction of a PiActionId object.
61 */
62 @Test
63 public void testConstruction() {
Carmelo Cascone87892e22017-11-13 16:01:29 -080064 final PiActionId actionId = PiActionId.of(DEC_TTL);
Frank Wange33e4ed2017-06-28 10:01:07 +080065 assertThat(actionId, is(notNullValue()));
Carmelo Cascone87892e22017-11-13 16:01:29 -080066 assertThat(actionId.id(), is(DEC_TTL));
Frank Wange33e4ed2017-06-28 10:01:07 +080067 }
68}