blob: 3dcb62fa5905fb46c2bb2c6377e2b1c81a841f03 [file] [log] [blame]
alshabibe1248b62015-08-20 17:21:55 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabibe1248b62015-08-20 17:21:55 -07003 *
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.meter;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21
22import java.util.Collections;
23
24import static org.hamcrest.MatcherAssert.assertThat;
25import static org.hamcrest.Matchers.is;
26import static org.onosproject.net.NetTestTools.APP_ID;
27import static org.onosproject.net.NetTestTools.did;
28
29
30/**
31 * DefaultMeter Tests.
32 */
33public class DefaultMeterTest {
34
35 private Meter m1;
36 private Meter sameAsm1;
37 private Meter m2;
Jayasree Ghoshe7a240c2016-09-10 14:45:15 +053038 private Meter m3;
alshabibe1248b62015-08-20 17:21:55 -070039
40 @Before
41 public void setup() {
42
43 Band band = DefaultBand.builder()
44 .ofType(Band.Type.DROP)
45 .withRate(500)
46 .build();
47
Jayasree Ghoshe7a240c2016-09-10 14:45:15 +053048 Band band1 = DefaultBand.builder()
49 .ofType(Band.Type.REMARK)
50 .withRate(500)
51 .dropPrecedence((short) 1)
52 .build();
53
alshabibe1248b62015-08-20 17:21:55 -070054 m1 = DefaultMeter.builder()
55 .forDevice(did("1"))
56 .fromApp(APP_ID)
57 .withId(MeterId.meterId(1))
58 .withUnit(Meter.Unit.KB_PER_SEC)
59 .withBands(Collections.singletonList(band))
60 .build();
61
62 sameAsm1 = DefaultMeter.builder()
63 .forDevice(did("1"))
64 .fromApp(APP_ID)
65 .withId(MeterId.meterId(1))
66 .withUnit(Meter.Unit.KB_PER_SEC)
67 .withBands(Collections.singletonList(band))
68 .build();
69
70 m2 = DefaultMeter.builder()
71 .forDevice(did("2"))
72 .fromApp(APP_ID)
73 .withId(MeterId.meterId(2))
74 .withUnit(Meter.Unit.KB_PER_SEC)
75 .withBands(Collections.singletonList(band))
76 .build();
77
Jayasree Ghoshe7a240c2016-09-10 14:45:15 +053078 m3 = DefaultMeter.builder()
79 .forDevice(did("3"))
80 .fromApp(APP_ID)
81 .withId(MeterId.meterId(3))
82 .withUnit(Meter.Unit.KB_PER_SEC)
83 .withBands(Collections.singletonList(band1))
84 .build();
85
86
alshabibe1248b62015-08-20 17:21:55 -070087 }
88
89 @Test
90 public void testEquality() {
91 new EqualsTester()
92 .addEqualityGroup(m1, sameAsm1)
Jayasree Ghoshe7a240c2016-09-10 14:45:15 +053093 .addEqualityGroup(m2)
94 .addEqualityGroup(m3).testEquals();
alshabibe1248b62015-08-20 17:21:55 -070095 }
96
97 @Test
98 public void testConstruction() {
99 DefaultMeter m = (DefaultMeter) m1;
100
101 assertThat(m.deviceId(), is(did("1")));
102 assertThat(m.appId(), is(APP_ID));
103 assertThat(m.id(), is(MeterId.meterId(1)));
104 assertThat(m.isBurst(), is(false));
105
106 assertThat(m.life(), is(0L));
107 assertThat(m.bytesSeen(), is(0L));
108 assertThat(m.packetsSeen(), is(0L));
109 assertThat(m.referenceCount(), is(0L));
110
111 }
112
113
114
115
116}