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; |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 32 | import static org.onosproject.net.pi.runtime.PiConstantsTest.MOD_VLAN_VID; |
| 33 | import static org.onosproject.net.pi.runtime.PiConstantsTest.VID; |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 34 | |
| 35 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 36 | * Unit tests for PiActionProfileMember class. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 37 | */ |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 38 | public class PiActionProfileMemberTest { |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 39 | |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 40 | private final PiActionProfileId actionProfileId1 = PiActionProfileId.of("foo"); |
| 41 | private final PiActionProfileId actionProfileId2 = PiActionProfileId.of("bar"); |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 42 | private final PiActionProfileMemberId piActionProfileMemberId1 = PiActionProfileMemberId.of(10); |
| 43 | private final PiActionProfileMemberId piActionProfileMemberId2 = PiActionProfileMemberId.of(20); |
| 44 | private final PiAction piAction1 = PiAction.builder().withId(PiActionId.of(MOD_NW_DST)) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 45 | .withParameter(new PiActionParam(PiActionParamId.of(DST_ADDR), copyFrom(0x0a010101))) |
| 46 | .build(); |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 47 | private final PiAction piAction2 = PiAction.builder().withId(PiActionId.of(MOD_VLAN_VID)) |
| 48 | .withParameter(new PiActionParam(PiActionParamId.of(VID), copyFrom(0x0b))) |
| 49 | .build(); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 50 | |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 51 | private final PiActionProfileMember piActionProfileMember1 = PiActionProfileMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 52 | .forActionProfile(actionProfileId1) |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 53 | .withId(piActionProfileMemberId1) |
| 54 | .withAction(piAction1) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 55 | .build(); |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 56 | private final PiActionProfileMember sameAsPiActionProfileMember1 = PiActionProfileMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 57 | .forActionProfile(actionProfileId1) |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 58 | .withId(piActionProfileMemberId1) |
| 59 | .withAction(piAction1) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 60 | .build(); |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 61 | private final PiActionProfileMember piActionProfileMember2 = PiActionProfileMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 62 | .forActionProfile(actionProfileId1) |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 63 | .withId(piActionProfileMemberId2) |
| 64 | .withAction(piAction2) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 65 | .build(); |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 66 | private final PiActionProfileMember piActionProfileMember3 = PiActionProfileMember.builder() |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 67 | .forActionProfile(actionProfileId2) |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 68 | .withId(piActionProfileMemberId1) |
| 69 | .withAction(piAction1) |
Carmelo Cascone | e44592f | 2018-09-12 02:24:47 -0700 | [diff] [blame] | 70 | .build(); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 71 | |
| 72 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 73 | * Checks that the PiActionProfileMember class is immutable. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 74 | */ |
| 75 | @Test |
| 76 | public void testImmutability() { |
| 77 | |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 78 | assertThatClassIsImmutable(PiActionProfileMember.class); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 83 | */ |
| 84 | @Test |
| 85 | public void testEquals() { |
| 86 | |
| 87 | new EqualsTester() |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 88 | .addEqualityGroup(piActionProfileMember1, sameAsPiActionProfileMember1) |
| 89 | .addEqualityGroup(piActionProfileMember2) |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 90 | .addEqualityGroup(piActionProfileMember3) |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 91 | .testEquals(); |
| 92 | } |
| 93 | |
| 94 | /** |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 95 | * Checks the methods of PiActionProfileMember. |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 96 | */ |
| 97 | @Test |
| 98 | public void testMethods() { |
| 99 | |
Carmelo Cascone | cb4327a | 2018-09-11 15:17:23 -0700 | [diff] [blame] | 100 | assertThat(piActionProfileMember1, is(notNullValue())); |
Carmelo Cascone | 99c59db | 2019-01-17 15:39:35 -0800 | [diff] [blame] | 101 | assertThat(piActionProfileMember1.id(), is(piActionProfileMemberId1)); |
| 102 | assertThat(piActionProfileMember1.action(), is(piAction1)); |
Frank Wang | 4e84804 | 2017-08-03 19:48:11 +0800 | [diff] [blame] | 103 | } |
| 104 | } |