blob: 317f3220f4a288363a5c637bf8c65bfb5a58e42d [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 Casconee44592f2018-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/**
Carmelo Casconecb4327a2018-09-11 15:17:23 -070034 * Unit tests for PiActionProfileMember class.
Frank Wang4e848042017-08-03 19:48:11 +080035 */
Carmelo Casconecb4327a2018-09-11 15:17:23 -070036public class PiActionProfileMemberTest {
Frank Wang4e848042017-08-03 19:48:11 +080037
Carmelo Casconee44592f2018-09-12 02:24:47 -070038 private final PiActionProfileId actionProfileId1 = PiActionProfileId.of("foo");
39 private final PiActionProfileId actionProfileId2 = PiActionProfileId.of("bar");
Carmelo Casconecb4327a2018-09-11 15:17:23 -070040 private final PiActionProfileMemberId piActionProfileMemberId = PiActionProfileMemberId.of(10);
Carmelo Cascone87892e22017-11-13 16:01:29 -080041 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 Casconecb4327a2018-09-11 15:17:23 -070045 private final PiActionProfileMember piActionProfileMember1 = PiActionProfileMember.builder()
Carmelo Casconee44592f2018-09-12 02:24:47 -070046 .forActionProfile(actionProfileId1)
Carmelo Casconecb4327a2018-09-11 15:17:23 -070047 .withId(piActionProfileMemberId)
Frank Wang4e848042017-08-03 19:48:11 +080048 .withAction(piAction)
49 .withWeight(10)
50 .build();
Carmelo Casconecb4327a2018-09-11 15:17:23 -070051 private final PiActionProfileMember sameAsPiActionProfileMember1 = PiActionProfileMember.builder()
Carmelo Casconee44592f2018-09-12 02:24:47 -070052 .forActionProfile(actionProfileId1)
Carmelo Casconecb4327a2018-09-11 15:17:23 -070053 .withId(piActionProfileMemberId)
Frank Wang4e848042017-08-03 19:48:11 +080054 .withAction(piAction)
55 .withWeight(10)
56 .build();
Carmelo Casconecb4327a2018-09-11 15:17:23 -070057 private final PiActionProfileMember piActionProfileMember2 = PiActionProfileMember.builder()
Carmelo Casconee44592f2018-09-12 02:24:47 -070058 .forActionProfile(actionProfileId1)
Carmelo Casconecb4327a2018-09-11 15:17:23 -070059 .withId(piActionProfileMemberId)
Frank Wang4e848042017-08-03 19:48:11 +080060 .withAction(piAction)
61 .withWeight(20)
62 .build();
Carmelo Casconecb4327a2018-09-11 15:17:23 -070063 private final PiActionProfileMember piActionGroupMember1ForOtherProfile = PiActionProfileMember.builder()
Carmelo Casconee44592f2018-09-12 02:24:47 -070064 .forActionProfile(actionProfileId2)
Carmelo Casconecb4327a2018-09-11 15:17:23 -070065 .withId(piActionProfileMemberId)
Carmelo Casconee44592f2018-09-12 02:24:47 -070066 .withAction(piAction)
67 .withWeight(10)
68 .build();
Frank Wang4e848042017-08-03 19:48:11 +080069
70 /**
Carmelo Casconecb4327a2018-09-11 15:17:23 -070071 * Checks that the PiActionProfileMember class is immutable.
Frank Wang4e848042017-08-03 19:48:11 +080072 */
73 @Test
74 public void testImmutability() {
75
Carmelo Casconecb4327a2018-09-11 15:17:23 -070076 assertThatClassIsImmutable(PiActionProfileMember.class);
Frank Wang4e848042017-08-03 19:48:11 +080077 }
78
79 /**
80 * Checks the operation of equals(), hashCode() and toString() methods.
81 */
82 @Test
83 public void testEquals() {
84
85 new EqualsTester()
Carmelo Casconecb4327a2018-09-11 15:17:23 -070086 .addEqualityGroup(piActionProfileMember1, sameAsPiActionProfileMember1)
87 .addEqualityGroup(piActionProfileMember2)
Carmelo Casconee44592f2018-09-12 02:24:47 -070088 .addEqualityGroup(piActionGroupMember1ForOtherProfile)
Frank Wang4e848042017-08-03 19:48:11 +080089 .testEquals();
90 }
91
92 /**
Carmelo Casconecb4327a2018-09-11 15:17:23 -070093 * Checks the methods of PiActionProfileMember.
Frank Wang4e848042017-08-03 19:48:11 +080094 */
95 @Test
96 public void testMethods() {
97
Carmelo Casconecb4327a2018-09-11 15:17:23 -070098 assertThat(piActionProfileMember1, is(notNullValue()));
99 assertThat(piActionProfileMember1.weight(), is(10));
100 assertThat(piActionProfileMember1.id(), is(piActionProfileMemberId));
101 assertThat(piActionProfileMember1.action(), is(piAction));
Frank Wang4e848042017-08-03 19:48:11 +0800102 }
103}