blob: 66c9840f47bf884165ada5b88d8e8c76bc403067 [file] [log] [blame]
Ray Milkeye8c632f2015-05-20 16:34:29 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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;
Ray Milkeye8c632f2015-05-20 16:34:29 -070019import org.onosproject.core.GroupId;
20import org.onosproject.net.flow.DefaultTrafficTreatment;
21import org.onosproject.net.flow.TrafficTreatment;
22
23import com.google.common.collect.ImmutableList;
24import com.google.common.testing.EqualsTester;
25
26import static org.hamcrest.CoreMatchers.is;
27import static org.hamcrest.MatcherAssert.assertThat;
28import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
29import static org.onosproject.net.group.GroupDescription.Type.ALL;
30import static org.onosproject.net.group.GroupDescription.Type.INDIRECT;
31import static org.onosproject.net.group.GroupOperation.Type.ADD;
32
33/**
34 * Tests for the group operation class.
35 */
36public class GroupOperationTest {
37
Yi Tsengfa394de2017-02-01 11:26:40 -080038 private final GroupId groupId = new GroupId(6);
Ray Milkeye8c632f2015-05-20 16:34:29 -070039 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}