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