Ray Milkey | 201f04b | 2017-09-25 10:13:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | |
| 17 | package org.onosproject.net.behaviour; |
| 18 | |
| 19 | import java.util.Map; |
| 20 | |
| 21 | import org.junit.Test; |
| 22 | |
| 23 | import com.google.common.collect.ImmutableMap; |
| 24 | import com.google.common.testing.EqualsTester; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 29 | |
| 30 | public class MirroringStatisticsTest { |
| 31 | |
| 32 | private static final long BYTES_1 = 100L; |
| 33 | private static final long PACKETS_1 = 2L; |
| 34 | private static final String NAME_1 = "mirror1"; |
| 35 | private Map<String, Integer> statistics1 = |
| 36 | ImmutableMap.of("tx_bytes", (int) BYTES_1, "tx_packets", (int) PACKETS_1); |
| 37 | private MirroringStatistics mirrorStatisticStats1 = MirroringStatistics.mirroringStatistics(NAME_1, statistics1); |
| 38 | |
| 39 | private Map<String, Integer> sameAsStatistics1 = |
| 40 | ImmutableMap.of("tx_bytes", (int) BYTES_1, "tx_packets", (int) PACKETS_1); |
| 41 | private MirroringStatistics sameAsMirrorStatisticStats1 = |
| 42 | MirroringStatistics.mirroringStatistics(NAME_1, sameAsStatistics1); |
| 43 | |
| 44 | private static final long BYTES_2 = 100L; |
| 45 | private static final long PACKETS_2 = 2L; |
| 46 | private static final String NAME_2 = "mirror2"; |
| 47 | private Map<String, Integer> statistics2 = |
| 48 | ImmutableMap.of("tx_bytes", (int) BYTES_2, "tx_packets", (int) PACKETS_2); |
| 49 | private MirroringStatistics mirrorStatisticStats2 = MirroringStatistics.mirroringStatistics(NAME_2, statistics2); |
| 50 | |
| 51 | private static final long BYTES_3 = 100L; |
| 52 | private static final long PACKETS_3 = 2L; |
| 53 | private static final String NAME_3 = "mirror3"; |
| 54 | private Map<String, Integer> statistics3 = |
| 55 | ImmutableMap.of("tx_bytes", (int) BYTES_3, "tx_packets", (int) PACKETS_3); |
| 56 | private MirroringStatistics mirrorStatisticStats3 = MirroringStatistics.mirroringStatistics(NAME_3, statistics3); |
| 57 | |
| 58 | @Test |
| 59 | public void testImmutability() { |
| 60 | assertThatClassIsImmutable(MirroringStatistics.class); |
| 61 | } |
| 62 | |
| 63 | @Test |
| 64 | public void testConstruction() { |
| 65 | assertThat(mirrorStatisticStats1.bytes(), is(BYTES_1)); |
| 66 | assertThat(mirrorStatisticStats1.name().name(), is(NAME_1)); |
| 67 | assertThat(mirrorStatisticStats1.packets(), is(PACKETS_1)); |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void testEquals() { |
| 72 | new EqualsTester() |
| 73 | .addEqualityGroup(mirrorStatisticStats1, sameAsMirrorStatisticStats1) |
| 74 | .addEqualityGroup(mirrorStatisticStats2) |
| 75 | .addEqualityGroup(mirrorStatisticStats3) |
| 76 | .testEquals(); |
| 77 | } |
| 78 | } |