blob: 8196d74284c2644562eaea3b5243a575a3654090 [file] [log] [blame]
Ray Milkeyec253f82017-09-20 16:29:19 +09001/*
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 */
16package org.onosproject.net.behaviour;
17
18import java.util.Map;
19
20import org.junit.Test;
21import org.onlab.util.Bandwidth;
22
23import com.google.common.collect.ImmutableMap;
24import com.google.common.testing.EqualsTester;
25
26import static com.spotify.hamcrest.optional.OptionalMatchers.optionalWithValue;
27import static org.hamcrest.MatcherAssert.assertThat;
28import static org.hamcrest.Matchers.is;
29import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
30
31public class DefaultQosDescriptionTest {
32
33 private QosId qosId1 = QosId.qosId("1");
34 private Bandwidth bandwidth1 = Bandwidth.bps(1);
35 private Map<Long, QueueDescription> queues1 = ImmutableMap.of();
36
37 private QosDescription defaultQosDescription1 =
38 DefaultQosDescription.builder()
39 .qosId(qosId1)
40 .cbs(1L)
41 .cir(11L)
42 .maxRate(bandwidth1)
43 .queues(queues1)
44 .type(QosDescription.Type.NOOP)
45 .build();
46 private QosDescription sameAsDefaultQosDescription1 =
47 DefaultQosDescription.builder()
48 .qosId(qosId1)
49 .cbs(1L)
50 .cir(11L)
51 .maxRate(bandwidth1)
52 .queues(queues1)
53 .type(QosDescription.Type.NOOP)
54 .build();
55 private QosDescription defaultQosDescription2 =
56 DefaultQosDescription.builder()
57 .qosId(qosId1)
58 .cbs(2L)
59 .cir(11L)
60 .maxRate(bandwidth1)
61 .queues(queues1)
62 .type(QosDescription.Type.NOOP)
63 .build();
64 private QosDescription defaultQosDescription3 =
65 DefaultQosDescription.builder()
66 .qosId(qosId1)
67 .cbs(1L)
68 .cir(33L)
69 .maxRate(bandwidth1)
70 .queues(queues1)
71 .type(QosDescription.Type.NOOP)
72 .build();
73 private QosDescription defaultQosDescription4 =
74 DefaultQosDescription.builder()
75 .qosId(qosId1)
76 .cbs(1L)
77 .cir(11L)
78 .queues(queues1)
79 .type(QosDescription.Type.NOOP)
80 .build();
81 private QosDescription defaultQosDescription5 =
82 DefaultQosDescription.builder()
83 .qosId(qosId1)
84 .cbs(1L)
85 .cir(11L)
86 .maxRate(bandwidth1)
87 .type(QosDescription.Type.NOOP)
88 .build();
89 private QosDescription defaultQosDescription6 =
90 DefaultQosDescription.builder()
91 .qosId(qosId1)
92 .cbs(1L)
93 .cir(11L)
94 .maxRate(bandwidth1)
95 .queues(queues1)
96 .type(QosDescription.Type.CODEL)
97 .build();
98
99 @Test
100 public void testImmutability() {
101 assertThatClassIsImmutable(DefaultQosDescription.class);
102 }
103
104 @Test
105 public void testConstruction() {
106 assertThat(defaultQosDescription1.qosId(), is(qosId1));
107 assertThat(defaultQosDescription1.cbs(), optionalWithValue(is(1L)));
108 assertThat(defaultQosDescription1.cir(), optionalWithValue(is(11L)));
109 assertThat(defaultQosDescription1.maxRate(), optionalWithValue(is(bandwidth1)));
110 assertThat(defaultQosDescription1.queues(), optionalWithValue(is(queues1)));
111 assertThat(defaultQosDescription1.type(), is(QosDescription.Type.NOOP));
112 }
113
114 @Test
115 public void testEquals() {
116 new EqualsTester()
117 .addEqualityGroup(defaultQosDescription1, sameAsDefaultQosDescription1)
118 .addEqualityGroup(defaultQosDescription2)
119 .addEqualityGroup(defaultQosDescription3)
120 .addEqualityGroup(defaultQosDescription4)
121 .addEqualityGroup(defaultQosDescription5)
122 .addEqualityGroup(defaultQosDescription6)
123 .testEquals();
124 }
125}