blob: e84d48f66229f525553e9ae6d2934c43d4812302 [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;
Carmelo Casconee3ba9222018-09-12 02:24:47 -070023import org.onosproject.net.pi.model.PiActionProfileId;
Frank Wang4e848042017-08-03 19:48:11 +080024
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27import static org.hamcrest.Matchers.notNullValue;
28import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
29import static org.onlab.util.ImmutableByteSequence.copyFrom;
30import static org.onosproject.net.pi.runtime.PiConstantsTest.DST_ADDR;
31import static org.onosproject.net.pi.runtime.PiConstantsTest.MOD_NW_DST;
32
33/**
34 * Unit tests for PiActionGroupMember class.
35 */
36public class PiActionGroupMemberTest {
37
Carmelo Casconee3ba9222018-09-12 02:24:47 -070038 private final PiActionProfileId actionProfileId1 = PiActionProfileId.of("foo");
39 private final PiActionProfileId actionProfileId2 = PiActionProfileId.of("bar");
Carmelo Cascone87892e22017-11-13 16:01:29 -080040 private final PiActionGroupMemberId piActionGroupMemberId = PiActionGroupMemberId.of(10);
41 private final PiAction piAction = PiAction.builder().withId(PiActionId.of(MOD_NW_DST))
Frank Wang4e848042017-08-03 19:48:11 +080042 .withParameter(new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101)))
43 .build();
44
Carmelo Cascone87892e22017-11-13 16:01:29 -080045 private final PiActionGroupMember piActionGroupMember1 = PiActionGroupMember.builder()
Carmelo Casconee3ba9222018-09-12 02:24:47 -070046 .forActionProfile(actionProfileId1)
Frank Wang4e848042017-08-03 19:48:11 +080047 .withId(piActionGroupMemberId)
48 .withAction(piAction)
49 .withWeight(10)
50 .build();
Carmelo Cascone87892e22017-11-13 16:01:29 -080051 private final PiActionGroupMember sameAsPiActionGroupMember1 = PiActionGroupMember.builder()
Carmelo Casconee3ba9222018-09-12 02:24:47 -070052 .forActionProfile(actionProfileId1)
Frank Wang4e848042017-08-03 19:48:11 +080053 .withId(piActionGroupMemberId)
54 .withAction(piAction)
55 .withWeight(10)
56 .build();
Carmelo Cascone87892e22017-11-13 16:01:29 -080057 private final PiActionGroupMember piActionGroupMember2 = PiActionGroupMember.builder()
Carmelo Casconee3ba9222018-09-12 02:24:47 -070058 .forActionProfile(actionProfileId1)
Frank Wang4e848042017-08-03 19:48:11 +080059 .withId(piActionGroupMemberId)
60 .withAction(piAction)
61 .withWeight(20)
62 .build();
Carmelo Casconee3ba9222018-09-12 02:24:47 -070063 private final PiActionGroupMember piActionGroupMember1ForOtherProfile = PiActionGroupMember.builder()
64 .forActionProfile(actionProfileId2)
65 .withId(piActionGroupMemberId)
66 .withAction(piAction)
67 .withWeight(10)
68 .build();
Frank Wang4e848042017-08-03 19:48:11 +080069
70 /**
71 * Checks that the PiActionGroupMember class is immutable.
72 */
73 @Test
74 public void testImmutability() {
75
76 assertThatClassIsImmutable(PiActionGroupMember.class);
77 }
78
79 /**
80 * Checks the operation of equals(), hashCode() and toString() methods.
81 */
82 @Test
83 public void testEquals() {
84
85 new EqualsTester()
86 .addEqualityGroup(piActionGroupMember1, sameAsPiActionGroupMember1)
87 .addEqualityGroup(piActionGroupMember2)
Carmelo Casconee3ba9222018-09-12 02:24:47 -070088 .addEqualityGroup(piActionGroupMember1ForOtherProfile)
Frank Wang4e848042017-08-03 19:48:11 +080089 .testEquals();
90 }
91
92 /**
93 * Checks the methods of PiActionGroupMember.
94 */
95 @Test
96 public void testMethods() {
97
98 assertThat(piActionGroupMember1, is(notNullValue()));
99 assertThat(piActionGroupMember1.weight(), is(10));
100 assertThat(piActionGroupMember1.id(), is(piActionGroupMemberId));
101 assertThat(piActionGroupMember1.action(), is(piAction));
102 }
103}