Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.PortNumber; |
| 22 | |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.is; |
| 25 | |
| 26 | /** |
| 27 | * Tests for {@link PiPreReplica}. |
| 28 | */ |
| 29 | public class PiPreReplicaTest { |
| 30 | |
Carmelo Cascone | 03ae0ac | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 31 | private final int instanceId1 = 1; |
| 32 | private final int instanceId2 = 2; |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 33 | private final PortNumber port1 = PortNumber.portNumber(1); |
| 34 | private final PortNumber port2 = PortNumber.portNumber(2); |
| 35 | |
| 36 | private final PiPreReplica replica1of1 = new PiPreReplica(port1, instanceId1); |
| 37 | private final PiPreReplica sameAsReplica1of1 = new PiPreReplica(port1, instanceId1); |
| 38 | |
| 39 | private final PiPreReplica replica1of2 = new PiPreReplica(port2, instanceId1); |
| 40 | private final PiPreReplica sameAsReplica1of2 = new PiPreReplica(port2, instanceId1); |
| 41 | |
| 42 | private final PiPreReplica replica2of2 = new PiPreReplica(port2, instanceId2); |
| 43 | private final PiPreReplica sameAsReplica2of2 = new PiPreReplica(port2, instanceId2); |
| 44 | |
| 45 | @Test |
| 46 | public void testPiPreReplica() { |
| 47 | assertThat("Invalid port", replica1of1.egressPort(), is(port1)); |
| 48 | assertThat("Invalid instance ID", replica1of1.instanceId(), is(instanceId1)); |
| 49 | assertThat("Invalid port", replica1of2.egressPort(), is(port2)); |
| 50 | assertThat("Invalid instance ID", replica1of2.instanceId(), is(instanceId1)); |
| 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void testEquality() { |
| 55 | new EqualsTester() |
| 56 | .addEqualityGroup(replica1of1, sameAsReplica1of1) |
| 57 | .addEqualityGroup(replica1of2, sameAsReplica1of2) |
| 58 | .addEqualityGroup(replica2of2, sameAsReplica2of2) |
| 59 | .testEquals(); |
| 60 | } |
| 61 | } |