blob: 3d2d3687bc081610206d99d78c9111e2b20b31b6 [file] [log] [blame]
Ray Milkey02ce2742015-05-26 14:44:10 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Ray Milkey02ce2742015-05-26 14:44:10 -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;
Charles Chanc88ebaa2018-11-01 20:08:47 -070019import org.onosproject.core.GroupId;
20import org.onosproject.net.PortNumber;
Ray Milkey02ce2742015-05-26 14:44:10 -070021import 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.assertThatClassIsImmutableBaseClass;
30import static org.onosproject.net.NetTestTools.APP_ID;
31import static org.onosproject.net.NetTestTools.did;
32
33/**
34 * Default group description unit tests.
35 */
36public class DefaultGroupDescriptionTest {
Charles Chanc88ebaa2018-11-01 20:08:47 -070037 private final byte[] keyData = "abcdefg".getBytes();
Ray Milkey02ce2742015-05-26 14:44:10 -070038 private final GroupKey key = new DefaultGroupKey(keyData);
Charles Chanc88ebaa2018-11-01 20:08:47 -070039 private final GroupId groupId1 = new GroupId(1);
40 private final TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
41
42 private final GroupBucket failoverGroupBucket =
43 DefaultGroupBucket.createFailoverGroupBucket(treatment, PortNumber.IN_PORT, groupId1);
44 private final GroupBuckets failoverGroupBuckets = new GroupBuckets(ImmutableList.of(failoverGroupBucket));
45 private final GroupBucket indirectGroupBucket =
46 DefaultGroupBucket.createIndirectGroupBucket(treatment);
47 private final GroupBuckets indirectGroupBuckets = new GroupBuckets(ImmutableList.of(indirectGroupBucket));
48
Ray Milkey02ce2742015-05-26 14:44:10 -070049 private final DefaultGroupDescription d1 =
50 new DefaultGroupDescription(did("2"),
51 GroupDescription.Type.FAILOVER,
Charles Chanc88ebaa2018-11-01 20:08:47 -070052 failoverGroupBuckets);
53 private final DefaultGroupDescription sameAsD1 = new DefaultGroupDescription(d1);
Ray Milkey02ce2742015-05-26 14:44:10 -070054 private final DefaultGroupDescription d2 =
55 new DefaultGroupDescription(did("2"),
56 GroupDescription.Type.INDIRECT,
Charles Chanc88ebaa2018-11-01 20:08:47 -070057 indirectGroupBuckets);
Ray Milkey02ce2742015-05-26 14:44:10 -070058 private final DefaultGroupDescription d3 =
59 new DefaultGroupDescription(did("3"),
60 GroupDescription.Type.FAILOVER,
Charles Chanc88ebaa2018-11-01 20:08:47 -070061 failoverGroupBuckets,
Ray Milkey02ce2742015-05-26 14:44:10 -070062 key,
63 711,
64 APP_ID);
65
66 /**
67 * Checks that the Default group description class is immutable and can be
68 * inherited from.
69 */
70 @Test
71 public void testImmutability() {
72 assertThatClassIsImmutableBaseClass(DefaultGroupDescription.class);
73 }
74
75 /**
76 * Tests for proper operation of equals(), hashCode() and toString() methods.
77 */
78 @Test
79 public void checkEquals() {
80 new EqualsTester()
81 .addEqualityGroup(d1, sameAsD1)
82 .addEqualityGroup(d2)
83 .addEqualityGroup(d3)
84 .testEquals();
85 }
86
87 /**
88 * Checks that construction of an object was correct.
89 */
90 @Test
91 public void testConstruction() {
92 assertThat(d3.deviceId(), is(did("3")));
93 assertThat(d3.type(), is(GroupDescription.Type.FAILOVER));
Charles Chanc88ebaa2018-11-01 20:08:47 -070094 assertThat(d3.buckets(), is(failoverGroupBuckets));
Ray Milkey02ce2742015-05-26 14:44:10 -070095 assertThat(d3.appId(), is(APP_ID));
96 assertThat(d3.givenGroupId(), is(711));
97 assertThat(key.key(), is(keyData));
98 assertThat(d3.appCookie().key(), is(keyData));
99 }
100}
101