Ray Milkey | e8c632f | 2015-05-20 16:34:29 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | e8c632f | 2015-05-20 16:34:29 -0700 | [diff] [blame] | 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 | package org.onosproject.net.group; |
| 17 | |
| 18 | import org.junit.Test; |
Ray Milkey | e8c632f | 2015-05-20 16:34:29 -0700 | [diff] [blame] | 19 | import org.onosproject.core.GroupId; |
| 20 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 21 | import org.onosproject.net.flow.TrafficTreatment; |
| 22 | |
| 23 | import com.google.common.collect.ImmutableList; |
| 24 | import com.google.common.testing.EqualsTester; |
| 25 | |
| 26 | import static org.hamcrest.CoreMatchers.is; |
| 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 29 | import static org.onosproject.net.group.GroupDescription.Type.ALL; |
| 30 | import static org.onosproject.net.group.GroupDescription.Type.INDIRECT; |
| 31 | import static org.onosproject.net.group.GroupOperation.Type.ADD; |
| 32 | |
| 33 | /** |
| 34 | * Tests for the group operation class. |
| 35 | */ |
| 36 | public class GroupOperationTest { |
| 37 | |
Yi Tseng | fa394de | 2017-02-01 11:26:40 -0800 | [diff] [blame] | 38 | private final GroupId groupId = new GroupId(6); |
Ray Milkey | e8c632f | 2015-05-20 16:34:29 -0700 | [diff] [blame] | 39 | private final TrafficTreatment treatment = |
| 40 | DefaultTrafficTreatment.emptyTreatment(); |
| 41 | private final GroupBucket bucket = |
| 42 | DefaultGroupBucket.createSelectGroupBucket(treatment); |
| 43 | private final GroupBuckets groupBuckets = |
| 44 | new GroupBuckets(ImmutableList.of(bucket)); |
| 45 | private final GroupOperation op1 = |
| 46 | GroupOperation.createAddGroupOperation(groupId, ALL, groupBuckets); |
| 47 | private final GroupOperation sameAsOp1 = |
| 48 | GroupOperation.createAddGroupOperation(groupId, ALL, groupBuckets); |
| 49 | private final GroupOperation op2 = |
| 50 | GroupOperation.createAddGroupOperation(groupId, INDIRECT, groupBuckets); |
| 51 | private final GroupOperation op3 = |
| 52 | GroupOperation.createDeleteGroupOperation(groupId, INDIRECT); |
| 53 | private final GroupOperation op4 = |
| 54 | GroupOperation.createModifyGroupOperation(groupId, INDIRECT, groupBuckets); |
| 55 | |
| 56 | /** |
| 57 | * Checks that the GroupOperation class is immutable. |
| 58 | */ |
| 59 | @Test |
| 60 | public void testImmutability() { |
| 61 | assertThatClassIsImmutable(GroupOperation.class); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Tests for proper operation of equals(), hashCode() and toString() methods. |
| 66 | */ |
| 67 | @Test |
| 68 | public void checkEquals() { |
| 69 | new EqualsTester() |
| 70 | .addEqualityGroup(op1, sameAsOp1) |
| 71 | .addEqualityGroup(op2) |
| 72 | .addEqualityGroup(op3) |
| 73 | .addEqualityGroup(op4) |
| 74 | .testEquals(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Checks that the construction of the add operation is correct. |
| 79 | */ |
| 80 | @Test |
| 81 | public void testAddGroupOperation() { |
| 82 | assertThat(op1.buckets(), is(groupBuckets)); |
| 83 | assertThat(op1.groupId(), is(groupId)); |
| 84 | assertThat(op1.groupType(), is(ALL)); |
| 85 | assertThat(op1.opType(), is(ADD)); |
| 86 | } |
| 87 | |
| 88 | } |