Ray Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 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; |
Charles Chan | c88ebaa | 2018-11-01 20:08:47 -0700 | [diff] [blame] | 19 | import org.onosproject.core.GroupId; |
| 20 | import org.onosproject.net.PortNumber; |
Ray Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 21 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 22 | import org.onosproject.net.flow.TrafficTreatment; |
| 23 | |
| 24 | import com.google.common.collect.ImmutableList; |
| 25 | import com.google.common.testing.EqualsTester; |
| 26 | |
| 27 | import static org.hamcrest.CoreMatchers.is; |
| 28 | import static org.hamcrest.MatcherAssert.assertThat; |
| 29 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; |
| 30 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 31 | import static org.onosproject.net.NetTestTools.did; |
| 32 | |
| 33 | /** |
| 34 | * Default group description unit tests. |
| 35 | */ |
| 36 | public class DefaultGroupDescriptionTest { |
Charles Chan | c88ebaa | 2018-11-01 20:08:47 -0700 | [diff] [blame] | 37 | private final byte[] keyData = "abcdefg".getBytes(); |
Ray Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 38 | private final GroupKey key = new DefaultGroupKey(keyData); |
Charles Chan | c88ebaa | 2018-11-01 20:08:47 -0700 | [diff] [blame] | 39 | 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 Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 49 | private final DefaultGroupDescription d1 = |
| 50 | new DefaultGroupDescription(did("2"), |
| 51 | GroupDescription.Type.FAILOVER, |
Charles Chan | c88ebaa | 2018-11-01 20:08:47 -0700 | [diff] [blame] | 52 | failoverGroupBuckets); |
| 53 | private final DefaultGroupDescription sameAsD1 = new DefaultGroupDescription(d1); |
Ray Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 54 | private final DefaultGroupDescription d2 = |
| 55 | new DefaultGroupDescription(did("2"), |
| 56 | GroupDescription.Type.INDIRECT, |
Charles Chan | c88ebaa | 2018-11-01 20:08:47 -0700 | [diff] [blame] | 57 | indirectGroupBuckets); |
Ray Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 58 | private final DefaultGroupDescription d3 = |
| 59 | new DefaultGroupDescription(did("3"), |
| 60 | GroupDescription.Type.FAILOVER, |
Charles Chan | c88ebaa | 2018-11-01 20:08:47 -0700 | [diff] [blame] | 61 | failoverGroupBuckets, |
Ray Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 62 | 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 Chan | c88ebaa | 2018-11-01 20:08:47 -0700 | [diff] [blame] | 94 | assertThat(d3.buckets(), is(failoverGroupBuckets)); |
Ray Milkey | 02ce274 | 2015-05-26 14:44:10 -0700 | [diff] [blame] | 95 | 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 | |