Jian Li | 0a5d4d2 | 2018-06-08 14:06:56 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-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 | package org.onosproject.openstacktelemetry.impl; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.openstacktelemetry.api.StatsInfo; |
| 22 | |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.is; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for DefaultStatsInfo class. |
| 28 | */ |
| 29 | public final class TestDefaultStatsInfo { |
| 30 | |
| 31 | private static final int STATIC_INTEGER_1 = 1; |
| 32 | private static final int STATIC_INTEGER_2 = 2; |
| 33 | |
| 34 | private StatsInfo info1; |
| 35 | private StatsInfo sameAsInfo1; |
| 36 | private StatsInfo info2; |
| 37 | |
| 38 | @Before |
| 39 | public void setup() { |
| 40 | StatsInfo.Builder builder1 = new DefaultStatsInfo.DefaultBuilder(); |
| 41 | StatsInfo.Builder builder2 = new DefaultStatsInfo.DefaultBuilder(); |
| 42 | StatsInfo.Builder builder3 = new DefaultStatsInfo.DefaultBuilder(); |
| 43 | |
| 44 | info1 = builder1 |
| 45 | .withStartupTime(STATIC_INTEGER_1) |
| 46 | .withCurrAccPkts(STATIC_INTEGER_1) |
| 47 | .withCurrAccBytes(STATIC_INTEGER_1) |
| 48 | .withPrevAccPkts(STATIC_INTEGER_1) |
| 49 | .withPrevAccBytes(STATIC_INTEGER_1) |
| 50 | .withFstPktArrTime(STATIC_INTEGER_1) |
| 51 | .withLstPktOffset(STATIC_INTEGER_1) |
| 52 | .withErrorPkts((short) STATIC_INTEGER_1) |
| 53 | .withDropPkts((short) STATIC_INTEGER_1) |
| 54 | .build(); |
| 55 | |
| 56 | sameAsInfo1 = builder2 |
| 57 | .withStartupTime(STATIC_INTEGER_1) |
| 58 | .withCurrAccPkts(STATIC_INTEGER_1) |
| 59 | .withCurrAccBytes(STATIC_INTEGER_1) |
| 60 | .withPrevAccPkts(STATIC_INTEGER_1) |
| 61 | .withPrevAccBytes(STATIC_INTEGER_1) |
| 62 | .withFstPktArrTime(STATIC_INTEGER_1) |
| 63 | .withLstPktOffset(STATIC_INTEGER_1) |
| 64 | .withErrorPkts((short) STATIC_INTEGER_1) |
| 65 | .withDropPkts((short) STATIC_INTEGER_1) |
| 66 | .build(); |
| 67 | |
| 68 | info2 = builder3 |
| 69 | .withStartupTime(STATIC_INTEGER_2) |
| 70 | .withCurrAccPkts(STATIC_INTEGER_2) |
| 71 | .withCurrAccBytes(STATIC_INTEGER_2) |
| 72 | .withPrevAccPkts(STATIC_INTEGER_2) |
| 73 | .withPrevAccBytes(STATIC_INTEGER_2) |
| 74 | .withFstPktArrTime(STATIC_INTEGER_2) |
| 75 | .withLstPktOffset(STATIC_INTEGER_2) |
| 76 | .withErrorPkts((short) STATIC_INTEGER_2) |
| 77 | .withDropPkts((short) STATIC_INTEGER_2) |
| 78 | .build(); |
| 79 | } |
| 80 | |
| 81 | @Test |
| 82 | public void testEquality() { |
| 83 | new EqualsTester() |
| 84 | .addEqualityGroup(info1, sameAsInfo1) |
| 85 | .addEqualityGroup(info2).testEquals(); |
| 86 | } |
| 87 | |
| 88 | @Test |
| 89 | public void testConstruction() { |
| 90 | StatsInfo info = info1; |
| 91 | |
| 92 | assertThat(info.startupTime(), is((long) STATIC_INTEGER_1)); |
| 93 | assertThat(info.currAccPkts(), is(STATIC_INTEGER_1)); |
| 94 | assertThat(info.currAccBytes(), is((long) STATIC_INTEGER_1)); |
| 95 | assertThat(info.prevAccPkts(), is(STATIC_INTEGER_1)); |
| 96 | assertThat(info.prevAccBytes(), is((long) STATIC_INTEGER_1)); |
| 97 | assertThat(info.fstPktArrTime(), is((long) STATIC_INTEGER_1)); |
| 98 | assertThat(info.lstPktOffset(), is(STATIC_INTEGER_1)); |
| 99 | assertThat(info.errorPkts(), is((short) STATIC_INTEGER_1)); |
| 100 | assertThat(info.dropPkts(), is((short) STATIC_INTEGER_1)); |
| 101 | } |
| 102 | } |