blob: a62588a5e011008435312ba038721df8f2c46796 [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.PiMatchFieldId;
Frank Wange33e4ed2017-06-28 10:01:07 +080022import 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;
Carmelo Cascone87892e22017-11-13 16:01:29 -080028import static org.onosproject.net.pi.runtime.PiConstantsTest.DOT;
Frank Wange33e4ed2017-06-28 10:01:07 +080029import static org.onosproject.net.pi.runtime.PiConstantsTest.VID;
30import static org.onosproject.net.pi.runtime.PiConstantsTest.VLAN_HEADER_NAME;
31
32/**
33 * Unit tests for PiValidFieldMatch class.
34 */
35public class PiValidFieldMatchTest {
Carmelo Cascone87892e22017-11-13 16:01:29 -080036 private final boolean isValid1 = true;
37 private final boolean isValid2 = false;
38 private final PiMatchFieldId piMatchField = PiMatchFieldId.of(VLAN_HEADER_NAME + DOT + VID);
39 private PiValidFieldMatch piValidFieldMatch1 = new PiValidFieldMatch(piMatchField, isValid1);
40 private PiValidFieldMatch sameAsPiValidFieldMatch1 = new PiValidFieldMatch(piMatchField, isValid1);
41 private PiValidFieldMatch piValidFieldMatch2 = new PiValidFieldMatch(piMatchField, isValid2);
Frank Wange33e4ed2017-06-28 10:01:07 +080042
43 /**
44 * Checks that the PiValidFieldMatch class is immutable.
45 */
46 @Test
47 public void testImmutability() {
48 assertThatClassIsImmutable(PiValidFieldMatch.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(piValidFieldMatch1, sameAsPiValidFieldMatch1)
58 .addEqualityGroup(piValidFieldMatch2)
59 .testEquals();
60 }
61
62 /**
63 * Checks the construction of a PiValidFieldMatch object.
64 */
65 @Test
66 public void testConstruction() {
Carmelo Cascone87892e22017-11-13 16:01:29 -080067 assertThat(piValidFieldMatch1, is(notNullValue()));
68 assertThat(piValidFieldMatch1.isValid(), is(isValid1));
69 assertThat(piValidFieldMatch1.type(), is(PiMatchType.VALID));
Frank Wange33e4ed2017-06-28 10:01:07 +080070 }
71}