blob: 8ba4d4e5cf306f5ecbcb6a9ca646274dbb2c70dd [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;
21
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.is;
24import static org.hamcrest.Matchers.notNullValue;
25import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
26import static org.onlab.util.ImmutableByteSequence.copyFrom;
27import static org.onosproject.net.pi.runtime.PiConstantsTest.EGRESS_PORT;
28
29/**
30 * Unit tests for PiPacketMetadata class.
31 */
32public class PiPacketMetadataTest {
33
34 final PiPacketMetadataId piPacketMetadataId = PiPacketMetadataId.of(EGRESS_PORT);
35
36 final PiPacketMetadata piPacketMetadata1 = PiPacketMetadata.builder()
37 .withId(piPacketMetadataId)
38 .withValue(copyFrom(0x10))
39 .build();
40 final PiPacketMetadata sameAsPiPacketMetadata1 = PiPacketMetadata.builder()
41 .withId(piPacketMetadataId)
42 .withValue(copyFrom(0x10))
43 .build();
44 final PiPacketMetadata piPacketMetadata2 = PiPacketMetadata.builder()
45 .withId(piPacketMetadataId)
46 .withValue(copyFrom(0x20))
47 .build();
48
49 /**
50 * Checks that the PiPacketMetadata class is immutable.
51 */
52 @Test
53 public void testImmutability() {
54
55 assertThatClassIsImmutable(PiPacketMetadata.class);
56 }
57
58 /**
59 * Checks the operation of equals(), hashCode() and toString() methods.
60 */
61 @Test
62 public void testEquals() {
63
64 new EqualsTester()
65 .addEqualityGroup(piPacketMetadata1, sameAsPiPacketMetadata1)
66 .addEqualityGroup(piPacketMetadata2)
67 .testEquals();
68 }
69
70 /**
71 * Checks the methods of PiPacketMetadata.
72 */
73 @Test
74 public void testMethods() {
75
76 assertThat(piPacketMetadata1, is(notNullValue()));
77 assertThat(piPacketMetadata1.id(), is(PiPacketMetadataId.of(EGRESS_PORT)));
78 assertThat(piPacketMetadata1.value(), is(copyFrom(0x10)));
79 }
80}