Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 21 | import org.onosproject.net.pi.model.PiActionId; |
| 22 | import org.onosproject.net.pi.model.PiActionParamId; |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 23 | import org.onosproject.net.pi.model.PiActionProfileId; |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 24 | |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.is; |
| 27 | import static org.hamcrest.Matchers.notNullValue; |
| 28 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 29 | import static org.onlab.util.ImmutableByteSequence.copyFrom; |
| 30 | import static org.onosproject.net.pi.runtime.PiConstantsTest.DST_ADDR; |
| 31 | import static org.onosproject.net.pi.runtime.PiConstantsTest.MOD_NW_DST; |
| 32 | |
| 33 | /** |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 34 | * Unit tests for PiActionProfileMember class. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 35 | */ |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 36 | public class PiActionProfileMemberTest { |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 37 | |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 38 | private final PiActionProfileId actionProfileId1 = PiActionProfileId.of("foo"); |
| 39 | private final PiActionProfileId actionProfileId2 = PiActionProfileId.of("bar"); |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 40 | private final PiActionProfileMemberId piActionProfileMemberId = PiActionProfileMemberId.of(10); |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 41 | private final PiAction piAction = PiAction.builder().withId(PiActionId.of(MOD_NW_DST)) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 42 | .withParameter(new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101))) |
| 43 | .build(); |
| 44 | |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 45 | private final PiActionProfileMember piActionProfileMember1 = PiActionProfileMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 46 | .forActionProfile(actionProfileId1) |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 47 | .withId(piActionProfileMemberId) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 48 | .withAction(piAction) |
| 49 | .withWeight(10) |
| 50 | .build(); |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 51 | private final PiActionProfileMember sameAsPiActionProfileMember1 = PiActionProfileMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 52 | .forActionProfile(actionProfileId1) |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 53 | .withId(piActionProfileMemberId) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 54 | .withAction(piAction) |
| 55 | .withWeight(10) |
| 56 | .build(); |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 57 | private final PiActionProfileMember piActionProfileMember2 = PiActionProfileMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 58 | .forActionProfile(actionProfileId1) |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 59 | .withId(piActionProfileMemberId) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 60 | .withAction(piAction) |
| 61 | .withWeight(20) |
| 62 | .build(); |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 63 | private final PiActionProfileMember piActionGroupMember1ForOtherProfile = PiActionProfileMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 64 | .forActionProfile(actionProfileId2) |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 65 | .withId(piActionProfileMemberId) |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 66 | .withAction(piAction) |
| 67 | .withWeight(10) |
| 68 | .build(); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 69 | |
| 70 | /** |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 71 | * Checks that the PiActionProfileMember class is immutable. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 72 | */ |
| 73 | @Test |
| 74 | public void testImmutability() { |
| 75 | |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 76 | assertThatClassIsImmutable(PiActionProfileMember.class); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 81 | */ |
| 82 | @Test |
| 83 | public void testEquals() { |
| 84 | |
| 85 | new EqualsTester() |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 86 | .addEqualityGroup(piActionProfileMember1, sameAsPiActionProfileMember1) |
| 87 | .addEqualityGroup(piActionProfileMember2) |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 88 | .addEqualityGroup(piActionGroupMember1ForOtherProfile) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 89 | .testEquals(); |
| 90 | } |
| 91 | |
| 92 | /** |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 93 | * Checks the methods of PiActionProfileMember. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 94 | */ |
| 95 | @Test |
| 96 | public void testMethods() { |
| 97 | |
Carmelo Cascone | a10f675 | 2018-09-11 15:17:23 -0700 | [diff] [blame^] | 98 | assertThat(piActionProfileMember1, is(notNullValue())); |
| 99 | assertThat(piActionProfileMember1.weight(), is(10)); |
| 100 | assertThat(piActionProfileMember1.id(), is(piActionProfileMemberId)); |
| 101 | assertThat(piActionProfileMember1.action(), is(piAction)); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 102 | } |
| 103 | } |