blob: 3ca00132a3f69e3c5668ab90c89a1bb8e39fd5c3 [file] [log] [blame]
Ray Milkeye8c632f2015-05-20 16:34:29 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeye8c632f2015-05-20 16:34:29 -07003 *
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 */
16package org.onosproject.net.group;
17
18import org.junit.Test;
19import org.onosproject.core.DefaultGroupId;
20import org.onosproject.core.GroupId;
21import org.onosproject.net.flow.DefaultTrafficTreatment;
22import org.onosproject.net.flow.TrafficTreatment;
23
24import com.google.common.collect.ImmutableList;
25import com.google.common.testing.EqualsTester;
26
27import static org.hamcrest.CoreMatchers.is;
28import static org.hamcrest.MatcherAssert.assertThat;
29import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
30import static org.onosproject.net.group.GroupDescription.Type.ALL;
31import static org.onosproject.net.group.GroupDescription.Type.INDIRECT;
32import static org.onosproject.net.group.GroupOperation.Type.ADD;
33
34/**
35 * Tests for the group operation class.
36 */
37public 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}