blob: 6c495fb0aee94f26bf46b0417efa0dacc5991a0e [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
19import java.util.EnumSet;
20
21import org.junit.Test;
22import org.onlab.util.Bandwidth;
23
24import com.google.common.testing.EqualsTester;
25
26import static org.hamcrest.Matchers.contains;
27import static org.hamcrest.Matchers.is;
28import static org.junit.Assert.assertThat;
29import static org.junit.Assert.assertTrue;
30
31
32public class DefaultQueueDescriptionTest {
33
34 private static final Bandwidth MAX_BANDWIDTH_1 = Bandwidth.bps(2L);
35 private static final Bandwidth MIN_BANDWIDTH_1 = Bandwidth.bps(1L);
36 private static final QueueId QUEUE_ID1 = QueueId.queueId("QUEUE 1");
37 private static final Bandwidth MAX_BANDWIDTH_2 = Bandwidth.bps(12L);
38 private static final Bandwidth MIN_BANDWIDTH_2 = Bandwidth.bps(11L);
39 private static final QueueId QUEUE_ID2 = QueueId.queueId("QUEUE 2");
40
41 private QueueDescription queueDescription1 =
42 DefaultQueueDescription.builder()
43 .burst(1L)
44 .dscp(11)
45 .maxRate(MAX_BANDWIDTH_1)
46 .minRate(MIN_BANDWIDTH_1)
47 .priority(1L)
48 .type(EnumSet.of(QueueDescription.Type.MAX))
49 .queueId(QUEUE_ID1)
50 .build();
51 private QueueDescription sameAsQueueDescription1 =
52 DefaultQueueDescription.builder()
53 .burst(1L)
54 .dscp(11)
55 .maxRate(MAX_BANDWIDTH_1)
56 .minRate(MIN_BANDWIDTH_1)
57 .priority(1L)
58 .type(EnumSet.of(QueueDescription.Type.MAX))
59 .queueId(QUEUE_ID1)
60 .build();
61 private QueueDescription queueDescription2 =
62 DefaultQueueDescription.builder()
63 .burst(2L)
64 .dscp(12)
65 .maxRate(MAX_BANDWIDTH_2)
66 .minRate(MIN_BANDWIDTH_2)
67 .priority(1L)
68 .type(EnumSet.of(QueueDescription.Type.MAX))
69 .queueId(QUEUE_ID2)
70 .build();
71
72 @Test
73 public void testConstruction() {
74 assertTrue(queueDescription1.burst().isPresent());
75 assertThat(queueDescription1.burst().get(), is(1L));
76 assertTrue(queueDescription1.dscp().isPresent());
77 assertThat(queueDescription1.dscp().get(), is(11));
78 assertTrue(queueDescription1.maxRate().isPresent());
79 assertThat(queueDescription1.maxRate().get(), is(MAX_BANDWIDTH_1));
80 assertTrue(queueDescription1.minRate().isPresent());
81 assertThat(queueDescription1.minRate().get(), is(MIN_BANDWIDTH_1));
82 assertThat(queueDescription1.type(), contains(QueueDescription.Type.MAX));
83 assertTrue(queueDescription1.priority().isPresent());
84 assertThat(queueDescription1.priority().get(), is(1L));
85 assertThat(queueDescription1.queueId(), is(QUEUE_ID1));
86 }
87
88 @Test
89 public void testEquals() {
90 new EqualsTester()
91 .addEqualityGroup(queueDescription1, sameAsQueueDescription1)
92 .addEqualityGroup(queueDescription2)
93 .testEquals();
94 }
95}