blob: d343cd7f5375ffe395662c3f416db6c5ae040485 [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;
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;
26
27/**
28 * Unit tests for PiTableId class.
29 */
30public class PiTableIdTest {
31 final String table10 = "table10";
32 final String table20 = "table20";
33 final PiTableId piTableId1 = PiTableId.of(table10);
34 final PiTableId sameAsPiTableId1 = PiTableId.of(table10);
35 final PiTableId piTableId2 = PiTableId.of(table20);
36
37 final String tableScope = "local";
38 final PiTableId piTableIdWithScope1 = PiTableId.of(tableScope, table10);
39 final PiTableId sameAsPiTableIdWithScope1 = PiTableId.of(tableScope, table10);
40 final PiTableId piTableIdWithScope2 = PiTableId.of(tableScope, table20);
41 /**
42 * Checks that the PiTableId class is immutable.
43 */
44 @Test
45 public void testImmutability() {
46 assertThatClassIsImmutable(PiTableId.class);
47 }
48
49 /**
50 * Checks the operation of equals(), hashCode() and toString() methods.
51 */
52 @Test
53 public void testEquals() {
54 new EqualsTester()
55 .addEqualityGroup(piTableId1, sameAsPiTableId1)
56 .addEqualityGroup(piTableId2)
57 .testEquals();
58 }
59
60 /**
61 * Checks the operation of equals(), hashCode() and toString() methods.
62 */
63 @Test
64 public void testEqualsWithScope() {
65 new EqualsTester()
66 .addEqualityGroup(piTableIdWithScope1, sameAsPiTableIdWithScope1)
67 .addEqualityGroup(piTableIdWithScope2)
68 .testEquals();
69 }
70
71 /**
72 * Checks the construction of a PiTableId object.
73 */
74 @Test
75 public void testConstruction() {
76 final String name = "table1";
77 final PiTableId piTableId = PiTableId.of(name);
78 assertThat(piTableId, is(notNullValue()));
79 assertThat(piTableId.name(), is(name));
80 }
81
82 /**
83 * Checks the construction of a PiTableId object.
84 */
85 @Test
86 public void testConstructionWithScope() {
87 final String name = "table1";
88 final String scope = "local";
89 final PiTableId piTableId = PiTableId.of(scope, name);
90 assertThat(piTableId, is(notNullValue()));
91 assertThat(piTableId.name(), is(name));
92 assertThat(piTableId.scope().get(), is(scope));
93 }
94}