alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 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 | package org.onosproject.net.meter; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import java.util.Collections; |
| 23 | |
| 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | import static org.hamcrest.Matchers.is; |
| 26 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 27 | import static org.onosproject.net.NetTestTools.did; |
| 28 | |
| 29 | |
| 30 | /** |
| 31 | * DefaultMeter Tests. |
| 32 | */ |
| 33 | public class DefaultMeterTest { |
| 34 | |
| 35 | private Meter m1; |
| 36 | private Meter sameAsm1; |
| 37 | private Meter m2; |
Jayasree Ghosh | e7a240c | 2016-09-10 14:45:15 +0530 | [diff] [blame] | 38 | private Meter m3; |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 39 | |
| 40 | @Before |
| 41 | public void setup() { |
| 42 | |
| 43 | Band band = DefaultBand.builder() |
| 44 | .ofType(Band.Type.DROP) |
| 45 | .withRate(500) |
| 46 | .build(); |
| 47 | |
Jayasree Ghosh | e7a240c | 2016-09-10 14:45:15 +0530 | [diff] [blame] | 48 | Band band1 = DefaultBand.builder() |
| 49 | .ofType(Band.Type.REMARK) |
| 50 | .withRate(500) |
| 51 | .dropPrecedence((short) 1) |
| 52 | .build(); |
| 53 | |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 54 | 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 Ghosh | e7a240c | 2016-09-10 14:45:15 +0530 | [diff] [blame] | 78 | 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 | |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void testEquality() { |
| 91 | new EqualsTester() |
| 92 | .addEqualityGroup(m1, sameAsm1) |
Jayasree Ghosh | e7a240c | 2016-09-10 14:45:15 +0530 | [diff] [blame] | 93 | .addEqualityGroup(m2) |
| 94 | .addEqualityGroup(m3).testEquals(); |
alshabib | e1248b6 | 2015-08-20 17:21:55 -0700 | [diff] [blame] | 95 | } |
| 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 | } |