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