Committed by
Gerrit Code Review
Unit tests for DefaultGroupDescription class
Change-Id: Ic1378e9be3067bd45def74769023d51178765260
Showing
2 changed files
with
96 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
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 | + */ | ||
16 | +package org.onosproject.net.group; | ||
17 | + | ||
18 | +import org.junit.Test; | ||
19 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
20 | +import org.onosproject.net.flow.TrafficTreatment; | ||
21 | + | ||
22 | +import com.google.common.collect.ImmutableList; | ||
23 | +import com.google.common.testing.EqualsTester; | ||
24 | + | ||
25 | +import static org.hamcrest.CoreMatchers.is; | ||
26 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
27 | +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; | ||
28 | +import static org.onosproject.net.NetTestTools.APP_ID; | ||
29 | +import static org.onosproject.net.NetTestTools.did; | ||
30 | + | ||
31 | +/** | ||
32 | + * Default group description unit tests. | ||
33 | + */ | ||
34 | +public 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 | + |
-
Please register or login to post a comment