blob: 574a321a31d0c672e0840e0a172661b7cca9683b [file] [log] [blame]
Frank Wange33e4ed2017-06-28 10:01:07 +08001/*
2 * Copyright 2017-present Open Networking Laboratory
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;
21import org.onlab.util.ImmutableByteSequence;
22
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.onlab.util.ImmutableByteSequence.copyFrom;
28import static org.onosproject.net.pi.runtime.PiConstantsTest.DST_ADDR;
29import static org.onosproject.net.pi.runtime.PiConstantsTest.SRC_ADDR;
30
31/**
32 * Unit tests for PiActionParam class.
33 */
34public class PiActionParamTest {
35 ImmutableByteSequence value1 = copyFrom(0x0a010101);
36 ImmutableByteSequence value2 = copyFrom(0x0a010102);
37 final PiActionParam piActionParam1 = new PiActionParam(PiActionParamId.of(DST_ADDR), value1);
38 final PiActionParam sameAsPiActionParam1 = new PiActionParam(PiActionParamId.of(DST_ADDR), value1);
39 final PiActionParam piActionParam2 = new PiActionParam(PiActionParamId.of(DST_ADDR), value2);
40
41 /**
42 * Checks that the PiActionParam class is immutable.
43 */
44 @Test
45 public void testImmutability() {
46 assertThatClassIsImmutable(PiActionParam.class);
47 }
48
49 /**
50 * Checks the operation of equals(), hashCode() and toString() methods.
51 */
52 @Test
53 public void testEquals() {
54 new EqualsTester()
55 .addEqualityGroup(piActionParam1, sameAsPiActionParam1)
56 .addEqualityGroup(piActionParam2)
57 .testEquals();
58 }
59
60 /**
61 * Checks the construction of a PiActionParam object.
62 */
63 @Test
64 public void testConstruction() {
65 ImmutableByteSequence value = copyFrom(0x0b010102);
66 final PiActionParamId piActionParamId = PiActionParamId.of(SRC_ADDR);
67 final PiActionParam piActionParam = new PiActionParam(piActionParamId, value);
68 assertThat(piActionParam, is(notNullValue()));
69 assertThat(piActionParam.id(), is(piActionParamId));
70 assertThat(piActionParam.value(), is(value));
71 }
72}