blob: 990a3bdc0e649bee6c9f53214e929a65dfa51698 [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;
22import org.onosproject.net.pi.model.PiMatchType;
23
24import static org.hamcrest.MatcherAssert.assertThat;
25import static org.hamcrest.Matchers.is;
26import static org.hamcrest.Matchers.notNullValue;
27import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
28import static org.onlab.util.ImmutableByteSequence.copyFrom;
29import static org.onosproject.net.pi.runtime.PiConstantsTest.ETH_HEADER_NAME;
30import static org.onosproject.net.pi.runtime.PiConstantsTest.ETH_TYPE;
31
32/**
33 * Unit tests for PiExactFieldMatch class.
34 */
35public class PiExactFieldMatchTest {
36 final ImmutableByteSequence value1 = copyFrom(0x0800);
37 final ImmutableByteSequence value2 = copyFrom(0x0806);
38 final PiHeaderFieldId piHeaderField = PiHeaderFieldId.of(ETH_HEADER_NAME, ETH_TYPE);
39 PiExactFieldMatch piExactFieldMatch1 = new PiExactFieldMatch(piHeaderField, value1);
40 PiExactFieldMatch sameAsPiExactFieldMatch1 = new PiExactFieldMatch(piHeaderField, value1);
41 PiExactFieldMatch piExactFieldMatch2 = new PiExactFieldMatch(piHeaderField, value2);
42
43 /**
44 * Checks that the PiExactFieldMatch class is immutable.
45 */
46 @Test
47 public void testImmutability() {
48 assertThatClassIsImmutable(PiExactFieldMatch.class);
49 }
50
51 /**
52 * Checks the operation of equals(), hashCode() and toString() methods.
53 */
54 @Test
55 public void testEquals() {
56 new EqualsTester()
57 .addEqualityGroup(piExactFieldMatch1, sameAsPiExactFieldMatch1)
58 .addEqualityGroup(piExactFieldMatch2)
59 .testEquals();
60 }
61
62 /**
63 * Checks the construction of a PiExactFieldMatch object.
64 */
65 @Test
66 public void testConstruction() {
67 final ImmutableByteSequence value = copyFrom(0x0806);
68 final PiHeaderFieldId piHeaderField = PiHeaderFieldId.of(ETH_HEADER_NAME, ETH_TYPE);
69 PiExactFieldMatch piExactFieldMatch = new PiExactFieldMatch(piHeaderField, value);
70 assertThat(piExactFieldMatch, is(notNullValue()));
71 assertThat(piExactFieldMatch.value(), is(value));
72 assertThat(piExactFieldMatch.type(), is(PiMatchType.EXACT));
73 }
74}