blob: e66e5a686ae109d297b623c9cc846057e0eb55a9 [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;
38
39 @Before
40 public void setup() {
41
42 Band band = DefaultBand.builder()
43 .ofType(Band.Type.DROP)
44 .withRate(500)
45 .build();
46
47 m1 = DefaultMeter.builder()
48 .forDevice(did("1"))
49 .fromApp(APP_ID)
50 .withId(MeterId.meterId(1))
51 .withUnit(Meter.Unit.KB_PER_SEC)
52 .withBands(Collections.singletonList(band))
53 .build();
54
55 sameAsm1 = DefaultMeter.builder()
56 .forDevice(did("1"))
57 .fromApp(APP_ID)
58 .withId(MeterId.meterId(1))
59 .withUnit(Meter.Unit.KB_PER_SEC)
60 .withBands(Collections.singletonList(band))
61 .build();
62
63 m2 = DefaultMeter.builder()
64 .forDevice(did("2"))
65 .fromApp(APP_ID)
66 .withId(MeterId.meterId(2))
67 .withUnit(Meter.Unit.KB_PER_SEC)
68 .withBands(Collections.singletonList(band))
69 .build();
70
71 }
72
73 @Test
74 public void testEquality() {
75 new EqualsTester()
76 .addEqualityGroup(m1, sameAsm1)
77 .addEqualityGroup(m2).testEquals();
78 }
79
80 @Test
81 public void testConstruction() {
82 DefaultMeter m = (DefaultMeter) m1;
83
84 assertThat(m.deviceId(), is(did("1")));
85 assertThat(m.appId(), is(APP_ID));
86 assertThat(m.id(), is(MeterId.meterId(1)));
87 assertThat(m.isBurst(), is(false));
88
89 assertThat(m.life(), is(0L));
90 assertThat(m.bytesSeen(), is(0L));
91 assertThat(m.packetsSeen(), is(0L));
92 assertThat(m.referenceCount(), is(0L));
93
94 }
95
96
97
98
99}