blob: c9e53ee79c8a12232b42820f199a0354ef179150 [file] [log] [blame]
Frank Wang4e848042017-08-03 19:48:11 +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;
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;
26import static org.onlab.util.ImmutableByteSequence.copyFrom;
27import static org.onosproject.net.pi.runtime.PiConstantsTest.DST_ADDR;
28import static org.onosproject.net.pi.runtime.PiConstantsTest.MOD_NW_DST;
29
30/**
31 * Unit tests for PiActionGroupMember class.
32 */
33public class PiActionGroupMemberTest {
34
35 final PiActionGroupMemberId piActionGroupMemberId = PiActionGroupMemberId.of(10);
36 final PiAction piAction = PiAction.builder().withId(PiActionId.of(MOD_NW_DST))
37 .withParameter(new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101)))
38 .build();
39
40 final PiActionGroupMember piActionGroupMember1 = PiActionGroupMember.builder()
41 .withId(piActionGroupMemberId)
42 .withAction(piAction)
43 .withWeight(10)
44 .build();
45 final PiActionGroupMember sameAsPiActionGroupMember1 = PiActionGroupMember.builder()
46 .withId(piActionGroupMemberId)
47 .withAction(piAction)
48 .withWeight(10)
49 .build();
50 final PiActionGroupMember piActionGroupMember2 = PiActionGroupMember.builder()
51 .withId(piActionGroupMemberId)
52 .withAction(piAction)
53 .withWeight(20)
54 .build();
55
56 /**
57 * Checks that the PiActionGroupMember class is immutable.
58 */
59 @Test
60 public void testImmutability() {
61
62 assertThatClassIsImmutable(PiActionGroupMember.class);
63 }
64
65 /**
66 * Checks the operation of equals(), hashCode() and toString() methods.
67 */
68 @Test
69 public void testEquals() {
70
71 new EqualsTester()
72 .addEqualityGroup(piActionGroupMember1, sameAsPiActionGroupMember1)
73 .addEqualityGroup(piActionGroupMember2)
74 .testEquals();
75 }
76
77 /**
78 * Checks the methods of PiActionGroupMember.
79 */
80 @Test
81 public void testMethods() {
82
83 assertThat(piActionGroupMember1, is(notNullValue()));
84 assertThat(piActionGroupMember1.weight(), is(10));
85 assertThat(piActionGroupMember1.id(), is(piActionGroupMemberId));
86 assertThat(piActionGroupMember1.action(), is(piAction));
87 }
88}