blob: c32e5aab54613070d1952066ed98c68f18959e61 [file] [log] [blame]
Ray Milkey02ce2742015-05-26 14:44:10 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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;
19import org.onosproject.net.flow.DefaultTrafficTreatment;
20import org.onosproject.net.flow.TrafficTreatment;
21
22import com.google.common.collect.ImmutableList;
23import com.google.common.testing.EqualsTester;
24
25import static org.hamcrest.CoreMatchers.is;
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
28import static org.onosproject.net.NetTestTools.APP_ID;
29import static org.onosproject.net.NetTestTools.did;
30
31/**
32 * Default group description unit tests.
33 */
34public class DefaultGroupDescriptionTest {
35 byte[] keyData = "abcdefg".getBytes();
36 private final GroupKey key = new DefaultGroupKey(keyData);
37 private final TrafficTreatment treatment =
38 DefaultTrafficTreatment.emptyTreatment();
39 private final GroupBucket bucket =
40 DefaultGroupBucket.createSelectGroupBucket(treatment);
41 private final GroupBuckets groupBuckets =
42 new GroupBuckets(ImmutableList.of(bucket));
43 private final DefaultGroupDescription d1 =
44 new DefaultGroupDescription(did("2"),
45 GroupDescription.Type.FAILOVER,
46 groupBuckets);
47 private final DefaultGroupDescription sameAsD1 =
48 new DefaultGroupDescription(d1);
49 private final DefaultGroupDescription d2 =
50 new DefaultGroupDescription(did("2"),
51 GroupDescription.Type.INDIRECT,
52 groupBuckets);
53 private final DefaultGroupDescription d3 =
54 new DefaultGroupDescription(did("3"),
55 GroupDescription.Type.FAILOVER,
56 groupBuckets,
57 key,
58 711,
59 APP_ID);
60
61 /**
62 * Checks that the Default group description class is immutable and can be
63 * inherited from.
64 */
65 @Test
66 public void testImmutability() {
67 assertThatClassIsImmutableBaseClass(DefaultGroupDescription.class);
68 }
69
70 /**
71 * Tests for proper operation of equals(), hashCode() and toString() methods.
72 */
73 @Test
74 public void checkEquals() {
75 new EqualsTester()
76 .addEqualityGroup(d1, sameAsD1)
77 .addEqualityGroup(d2)
78 .addEqualityGroup(d3)
79 .testEquals();
80 }
81
82 /**
83 * Checks that construction of an object was correct.
84 */
85 @Test
86 public void testConstruction() {
87 assertThat(d3.deviceId(), is(did("3")));
88 assertThat(d3.type(), is(GroupDescription.Type.FAILOVER));
89 assertThat(d3.buckets(), is(groupBuckets));
90 assertThat(d3.appId(), is(APP_ID));
91 assertThat(d3.givenGroupId(), is(711));
92 assertThat(key.key(), is(keyData));
93 assertThat(d3.appCookie().key(), is(keyData));
94 }
95}
96