Committed by
Brian O'Connor
Unit tests for Default Group class
Change-Id: I1e28ade4dc4197a928f42924e0e9690791df30f8
Showing
1 changed file
with
97 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.core.DefaultGroupId; | ||
| 20 | +import org.onosproject.core.GroupId; | ||
| 21 | +import org.onosproject.net.NetTestTools; | ||
| 22 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 23 | + | ||
| 24 | +import com.google.common.collect.ImmutableList; | ||
| 25 | +import com.google.common.testing.EqualsTester; | ||
| 26 | + | ||
| 27 | +import static org.hamcrest.Matchers.is; | ||
| 28 | +import static org.junit.Assert.*; | ||
| 29 | +import static org.onosproject.net.NetTestTools.did; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * Unit tests for DefaultGroup class. | ||
| 33 | + */ | ||
| 34 | +public 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 | +} |
-
Please register or login to post a comment