Ray Milkey | aae402c | 2017-08-22 16:24:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.net.behaviour; |
| 18 | |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 19 | import com.google.common.testing.EqualsTester; |
Ray Milkey | aae402c | 2017-08-22 16:24:41 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
| 21 | import org.onlab.util.Bandwidth; |
| 22 | |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 23 | import java.util.EnumSet; |
Ray Milkey | aae402c | 2017-08-22 16:24:41 -0700 | [diff] [blame] | 24 | |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 25 | import static com.spotify.hamcrest.optional.OptionalMatchers.optionalWithValue; |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
Ray Milkey | aae402c | 2017-08-22 16:24:41 -0700 | [diff] [blame] | 27 | import static org.hamcrest.Matchers.is; |
Ray Milkey | aae402c | 2017-08-22 16:24:41 -0700 | [diff] [blame] | 28 | |
| 29 | |
| 30 | public class DefaultQueueDescriptionTest { |
| 31 | |
| 32 | private static final Bandwidth MAX_BANDWIDTH_1 = Bandwidth.bps(2L); |
| 33 | private static final Bandwidth MIN_BANDWIDTH_1 = Bandwidth.bps(1L); |
| 34 | private static final QueueId QUEUE_ID1 = QueueId.queueId("QUEUE 1"); |
| 35 | private static final Bandwidth MAX_BANDWIDTH_2 = Bandwidth.bps(12L); |
| 36 | private static final Bandwidth MIN_BANDWIDTH_2 = Bandwidth.bps(11L); |
| 37 | private static final QueueId QUEUE_ID2 = QueueId.queueId("QUEUE 2"); |
| 38 | |
| 39 | private QueueDescription queueDescription1 = |
| 40 | DefaultQueueDescription.builder() |
| 41 | .burst(1L) |
| 42 | .dscp(11) |
| 43 | .maxRate(MAX_BANDWIDTH_1) |
| 44 | .minRate(MIN_BANDWIDTH_1) |
| 45 | .priority(1L) |
| 46 | .type(EnumSet.of(QueueDescription.Type.MAX)) |
| 47 | .queueId(QUEUE_ID1) |
| 48 | .build(); |
| 49 | private QueueDescription sameAsQueueDescription1 = |
| 50 | DefaultQueueDescription.builder() |
| 51 | .burst(1L) |
| 52 | .dscp(11) |
| 53 | .maxRate(MAX_BANDWIDTH_1) |
| 54 | .minRate(MIN_BANDWIDTH_1) |
| 55 | .priority(1L) |
| 56 | .type(EnumSet.of(QueueDescription.Type.MAX)) |
| 57 | .queueId(QUEUE_ID1) |
| 58 | .build(); |
| 59 | private QueueDescription queueDescription2 = |
| 60 | DefaultQueueDescription.builder() |
| 61 | .burst(2L) |
| 62 | .dscp(12) |
| 63 | .maxRate(MAX_BANDWIDTH_2) |
| 64 | .minRate(MIN_BANDWIDTH_2) |
| 65 | .priority(1L) |
| 66 | .type(EnumSet.of(QueueDescription.Type.MAX)) |
| 67 | .queueId(QUEUE_ID2) |
| 68 | .build(); |
| 69 | |
| 70 | @Test |
| 71 | public void testConstruction() { |
Ray Milkey | 3f038c4 | 2017-09-26 11:31:54 -0700 | [diff] [blame] | 72 | assertThat(queueDescription1.burst(), optionalWithValue(is(1L))); |
| 73 | assertThat(queueDescription1.dscp(), optionalWithValue(is(11))); |
| 74 | assertThat(queueDescription1.maxRate(), optionalWithValue(is(MAX_BANDWIDTH_1))); |
| 75 | assertThat(queueDescription1.minRate(), optionalWithValue(is(MIN_BANDWIDTH_1))); |
| 76 | assertThat(queueDescription1.priority(), optionalWithValue(is(1L))); |
Ray Milkey | aae402c | 2017-08-22 16:24:41 -0700 | [diff] [blame] | 77 | assertThat(queueDescription1.queueId(), is(QUEUE_ID1)); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void testEquals() { |
| 82 | new EqualsTester() |
| 83 | .addEqualityGroup(queueDescription1, sameAsQueueDescription1) |
| 84 | .addEqualityGroup(queueDescription2) |
| 85 | .testEquals(); |
| 86 | } |
| 87 | } |