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 | /** |
| 34 | * Unit tests for PiActionGroupMember class. |
| 35 | */ |
| 36 | public class PiActionGroupMemberTest { |
| 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 | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 40 | private final PiActionGroupMemberId piActionGroupMemberId = PiActionGroupMemberId.of(10); |
| 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 | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 45 | private final PiActionGroupMember piActionGroupMember1 = PiActionGroupMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 46 | .forActionProfile(actionProfileId1) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 47 | .withId(piActionGroupMemberId) |
| 48 | .withAction(piAction) |
| 49 | .withWeight(10) |
| 50 | .build(); |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 51 | private final PiActionGroupMember sameAsPiActionGroupMember1 = PiActionGroupMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 52 | .forActionProfile(actionProfileId1) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 53 | .withId(piActionGroupMemberId) |
| 54 | .withAction(piAction) |
| 55 | .withWeight(10) |
| 56 | .build(); |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 57 | private final PiActionGroupMember piActionGroupMember2 = PiActionGroupMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 58 | .forActionProfile(actionProfileId1) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 59 | .withId(piActionGroupMemberId) |
| 60 | .withAction(piAction) |
| 61 | .withWeight(20) |
| 62 | .build(); |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 63 | private final PiActionGroupMember piActionGroupMember1ForOtherProfile = PiActionGroupMember.builder() |
| 64 | .forActionProfile(actionProfileId2) |
| 65 | .withId(piActionGroupMemberId) |
| 66 | .withAction(piAction) |
| 67 | .withWeight(10) |
| 68 | .build(); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 69 | |
| 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 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 | /** |
| 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 | } |