blob: feb10e800df1b859aeb18a5215856a11337dd1da [file] [log] [blame]
Ray Milkey33d44c52015-06-10 16:12:02 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkey33d44c52015-06-10 16:12:02 -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.NetTestTools;
22import org.onosproject.net.flow.DefaultTrafficTreatment;
23
24import com.google.common.collect.ImmutableList;
25import com.google.common.testing.EqualsTester;
26
27import static org.hamcrest.Matchers.is;
28import static org.junit.Assert.*;
29import static org.onosproject.net.NetTestTools.did;
30
31/**
32 * Unit tests for DefaultGroup class.
33 */
34public class DefaultGroupTest {
35 private final GroupId id1 = new DefaultGroupId(6);
36 private final GroupId id2 = new DefaultGroupId(7);
37 private final GroupBucket bucket =
38 DefaultGroupBucket.createSelectGroupBucket(
39 DefaultTrafficTreatment.emptyTreatment());
40 private final GroupBuckets groupBuckets =
41 new GroupBuckets(ImmutableList.of(bucket));
42 private final GroupDescription groupDesc1 =
43 new DefaultGroupDescription(did("1"),
44 GroupDescription.Type.FAILOVER,
45 groupBuckets);
46 private final GroupDescription groupDesc2 =
47 new DefaultGroupDescription(did("2"),
48 GroupDescription.Type.FAILOVER,
49 groupBuckets);
50
51 DefaultGroup group1 = new DefaultGroup(id1, groupDesc1);
52 DefaultGroup sameAsGroup1 = new DefaultGroup(id1, groupDesc1);
53 DefaultGroup group2 = new DefaultGroup(id1, groupDesc2);
54 DefaultGroup group3 = new DefaultGroup(id2, groupDesc2);
55
56 /**
57 * Tests for proper operation of equals(), hashCode() and toString() methods.
58 */
59 @Test
60 public void checkEquals() {
61 new EqualsTester()
62 .addEqualityGroup(group1, sameAsGroup1)
63 .addEqualityGroup(group2)
64 .addEqualityGroup(group3)
65 .testEquals();
66 }
67
68 /**
69 * Tests that objects are created properly.
70 */
71 @Test
72 public void checkConstruction() {
73 assertThat(group1.id(), is(id1));
74 assertThat(group1.bytes(), is(0L));
75 assertThat(group1.life(), is(0L));
76 assertThat(group1.packets(), is(0L));
77 assertThat(group1.referenceCount(), is(0L));
78 assertThat(group1.buckets(), is(groupBuckets));
79 assertThat(group1.state(), is(Group.GroupState.PENDING_ADD));
80 }
81
82 /**
83 * Tests that objects are created properly using the device based constructor.
84 */
85 @Test
86 public void checkConstructionWithDid() {
87 DefaultGroup group = new DefaultGroup(id2, NetTestTools.did("1"),
88 GroupDescription.Type.INDIRECT, groupBuckets);
89 assertThat(group.id(), is(id2));
90 assertThat(group.bytes(), is(0L));
91 assertThat(group.life(), is(0L));
92 assertThat(group.packets(), is(0L));
93 assertThat(group.referenceCount(), is(0L));
94 assertThat(group.deviceId(), is(NetTestTools.did("1")));
95 assertThat(group.buckets(), is(groupBuckets));
96 }
97}