blob: 99647cc685051dfcb8fde5ee8d10e8672addf247 [file] [log] [blame]
Ray Milkeyaae402c2017-08-22 16:24:41 -07001/*
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
17package org.onosproject.net.behaviour;
18
Ray Milkey3f038c42017-09-26 11:31:54 -070019import com.google.common.testing.EqualsTester;
Ray Milkeyaae402c2017-08-22 16:24:41 -070020import org.junit.Test;
21import org.onlab.util.Bandwidth;
22
Ray Milkey3f038c42017-09-26 11:31:54 -070023import java.util.EnumSet;
Ray Milkeyaae402c2017-08-22 16:24:41 -070024
Ray Milkey3f038c42017-09-26 11:31:54 -070025import static com.spotify.hamcrest.optional.OptionalMatchers.optionalWithValue;
26import static org.hamcrest.MatcherAssert.assertThat;
Ray Milkeyaae402c2017-08-22 16:24:41 -070027import static org.hamcrest.Matchers.is;
Ray Milkeyaae402c2017-08-22 16:24:41 -070028
29
30public 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 Milkey3f038c42017-09-26 11:31:54 -070072 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 Milkeyaae402c2017-08-22 16:24:41 -070077 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}