blob: 020d575fac2f004154e220b7e165c3cd84e980fa [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;
Carmelo Cascone87892e22017-11-13 16:01:29 -080021import org.onosproject.net.pi.model.PiActionId;
22import org.onosproject.net.pi.model.PiActionParamId;
Frank Wang4e848042017-08-03 19:48:11 +080023
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.DST_ADDR;
30import static org.onosproject.net.pi.runtime.PiConstantsTest.MOD_NW_DST;
31
32/**
33 * Unit tests for PiActionGroupMember class.
34 */
35public class PiActionGroupMemberTest {
36
Carmelo Cascone87892e22017-11-13 16:01:29 -080037 private final PiActionGroupMemberId piActionGroupMemberId = PiActionGroupMemberId.of(10);
38 private final PiAction piAction = PiAction.builder().withId(PiActionId.of(MOD_NW_DST))
Frank Wang4e848042017-08-03 19:48:11 +080039 .withParameter(new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101)))
40 .build();
41
Carmelo Cascone87892e22017-11-13 16:01:29 -080042 private final PiActionGroupMember piActionGroupMember1 = PiActionGroupMember.builder()
Frank Wang4e848042017-08-03 19:48:11 +080043 .withId(piActionGroupMemberId)
44 .withAction(piAction)
45 .withWeight(10)
46 .build();
Carmelo Cascone87892e22017-11-13 16:01:29 -080047 private final PiActionGroupMember sameAsPiActionGroupMember1 = PiActionGroupMember.builder()
Frank Wang4e848042017-08-03 19:48:11 +080048 .withId(piActionGroupMemberId)
49 .withAction(piAction)
50 .withWeight(10)
51 .build();
Carmelo Cascone87892e22017-11-13 16:01:29 -080052 private final PiActionGroupMember piActionGroupMember2 = PiActionGroupMember.builder()
Frank Wang4e848042017-08-03 19:48:11 +080053 .withId(piActionGroupMemberId)
54 .withAction(piAction)
55 .withWeight(20)
56 .build();
57
58 /**
59 * Checks that the PiActionGroupMember class is immutable.
60 */
61 @Test
62 public void testImmutability() {
63
64 assertThatClassIsImmutable(PiActionGroupMember.class);
65 }
66
67 /**
68 * Checks the operation of equals(), hashCode() and toString() methods.
69 */
70 @Test
71 public void testEquals() {
72
73 new EqualsTester()
74 .addEqualityGroup(piActionGroupMember1, sameAsPiActionGroupMember1)
75 .addEqualityGroup(piActionGroupMember2)
76 .testEquals();
77 }
78
79 /**
80 * Checks the methods of PiActionGroupMember.
81 */
82 @Test
83 public void testMethods() {
84
85 assertThat(piActionGroupMember1, is(notNullValue()));
86 assertThat(piActionGroupMember1.weight(), is(10));
87 assertThat(piActionGroupMember1.id(), is(piActionGroupMemberId));
88 assertThat(piActionGroupMember1.action(), is(piAction));
89 }
90}