blob: bfe37454ac38cc465586c497525583776f6c9dec [file] [log] [blame]
Jian Li0a5d4d22018-06-08 14:06:56 +09001/*
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 */
16package org.onosproject.openstacktelemetry.impl;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onosproject.openstacktelemetry.api.StatsInfo;
22
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.is;
Jian Liae3fcff2018-07-30 11:55:44 +090025import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Jian Li0a5d4d22018-06-08 14:06:56 +090026
27/**
28 * Unit tests for DefaultStatsInfo class.
29 */
Jian Li3db90852018-06-10 22:29:16 +090030public final class DefaultStatsInfoTest {
Jian Li0a5d4d22018-06-08 14:06:56 +090031
32 private static final int STATIC_INTEGER_1 = 1;
33 private static final int STATIC_INTEGER_2 = 2;
34
35 private StatsInfo info1;
36 private StatsInfo sameAsInfo1;
37 private StatsInfo info2;
38
Jian Liae3fcff2018-07-30 11:55:44 +090039 /**
40 * Initial setup for this unit test.
41 */
Jian Li0a5d4d22018-06-08 14:06:56 +090042 @Before
43 public void setup() {
44 StatsInfo.Builder builder1 = new DefaultStatsInfo.DefaultBuilder();
45 StatsInfo.Builder builder2 = new DefaultStatsInfo.DefaultBuilder();
46 StatsInfo.Builder builder3 = new DefaultStatsInfo.DefaultBuilder();
47
48 info1 = builder1
49 .withStartupTime(STATIC_INTEGER_1)
50 .withCurrAccPkts(STATIC_INTEGER_1)
51 .withCurrAccBytes(STATIC_INTEGER_1)
52 .withPrevAccPkts(STATIC_INTEGER_1)
53 .withPrevAccBytes(STATIC_INTEGER_1)
54 .withFstPktArrTime(STATIC_INTEGER_1)
55 .withLstPktOffset(STATIC_INTEGER_1)
56 .withErrorPkts((short) STATIC_INTEGER_1)
57 .withDropPkts((short) STATIC_INTEGER_1)
58 .build();
59
60 sameAsInfo1 = builder2
61 .withStartupTime(STATIC_INTEGER_1)
62 .withCurrAccPkts(STATIC_INTEGER_1)
63 .withCurrAccBytes(STATIC_INTEGER_1)
64 .withPrevAccPkts(STATIC_INTEGER_1)
65 .withPrevAccBytes(STATIC_INTEGER_1)
66 .withFstPktArrTime(STATIC_INTEGER_1)
67 .withLstPktOffset(STATIC_INTEGER_1)
68 .withErrorPkts((short) STATIC_INTEGER_1)
69 .withDropPkts((short) STATIC_INTEGER_1)
70 .build();
71
72 info2 = builder3
73 .withStartupTime(STATIC_INTEGER_2)
74 .withCurrAccPkts(STATIC_INTEGER_2)
75 .withCurrAccBytes(STATIC_INTEGER_2)
76 .withPrevAccPkts(STATIC_INTEGER_2)
77 .withPrevAccBytes(STATIC_INTEGER_2)
78 .withFstPktArrTime(STATIC_INTEGER_2)
79 .withLstPktOffset(STATIC_INTEGER_2)
80 .withErrorPkts((short) STATIC_INTEGER_2)
81 .withDropPkts((short) STATIC_INTEGER_2)
82 .build();
83 }
84
Jian Liae3fcff2018-07-30 11:55:44 +090085 /**
86 * Tests class immutability.
87 */
88 @Test
89 public void testImmutability() {
90 assertThatClassIsImmutable(DefaultStatsInfo.class);
91 }
92
93 /**
94 * Tests object equality.
95 */
Jian Li0a5d4d22018-06-08 14:06:56 +090096 @Test
97 public void testEquality() {
98 new EqualsTester()
99 .addEqualityGroup(info1, sameAsInfo1)
100 .addEqualityGroup(info2).testEquals();
101 }
102
Jian Liae3fcff2018-07-30 11:55:44 +0900103 /**
104 * Tests object construction.
105 */
Jian Li0a5d4d22018-06-08 14:06:56 +0900106 @Test
107 public void testConstruction() {
108 StatsInfo info = info1;
109
110 assertThat(info.startupTime(), is((long) STATIC_INTEGER_1));
111 assertThat(info.currAccPkts(), is(STATIC_INTEGER_1));
112 assertThat(info.currAccBytes(), is((long) STATIC_INTEGER_1));
113 assertThat(info.prevAccPkts(), is(STATIC_INTEGER_1));
114 assertThat(info.prevAccBytes(), is((long) STATIC_INTEGER_1));
115 assertThat(info.fstPktArrTime(), is((long) STATIC_INTEGER_1));
116 assertThat(info.lstPktOffset(), is(STATIC_INTEGER_1));
117 assertThat(info.errorPkts(), is((short) STATIC_INTEGER_1));
118 assertThat(info.dropPkts(), is((short) STATIC_INTEGER_1));
119 }
120}