blob: 2e63d455942b57bf6b5d18d2b5b987a99901563a [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 org.junit.Test;
Carmelo Cascone87892e22017-11-13 16:01:29 -080020import org.onosproject.net.pi.model.PiMatchFieldId;
Frank Wange33e4ed2017-06-28 10:01:07 +080021import org.onosproject.net.pi.model.PiMatchType;
22
23import static org.junit.Assert.assertEquals;
24import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
25import static org.onlab.util.ImmutableByteSequence.copyFrom;
Carmelo Cascone87892e22017-11-13 16:01:29 -080026import static org.onosproject.net.pi.runtime.PiConstantsTest.DOT;
Frank Wange33e4ed2017-06-28 10:01:07 +080027import static org.onosproject.net.pi.runtime.PiConstantsTest.ETH_HEADER_NAME;
28import static org.onosproject.net.pi.runtime.PiConstantsTest.ETH_TYPE;
29
30/**
31 * Unit tests for PiFieldMatch class.
32 */
33public class PiFieldMatchTest {
34
35 /**
36 * Checks that the PiFieldMatch class is immutable but can be
37 * inherited from.
38 */
39 @Test
40 public void testImmutability() {
41 assertThatClassIsImmutableBaseClass(PiFieldMatch.class);
42 }
43
44 @Test
45 public void basics() {
Carmelo Cascone87892e22017-11-13 16:01:29 -080046 final PiMatchFieldId piMatchField = PiMatchFieldId.of(ETH_HEADER_NAME + DOT + ETH_TYPE);
47 PiFieldMatch piFieldMatch = new PiExactFieldMatch(piMatchField, copyFrom(0x0806));
Frank Wange33e4ed2017-06-28 10:01:07 +080048
Carmelo Cascone87892e22017-11-13 16:01:29 -080049 assertEquals(piFieldMatch.fieldId(), piMatchField);
Frank Wange33e4ed2017-06-28 10:01:07 +080050 assertEquals(piFieldMatch.type(), PiMatchType.EXACT);
51 }
52}