Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [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.pi.runtime; |
| 18 | |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.net.pi.model.PiControlMetadataId; |
| 22 | |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.is; |
| 25 | import static org.hamcrest.Matchers.notNullValue; |
| 26 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 27 | import static org.onlab.util.ImmutableByteSequence.copyFrom; |
| 28 | import static org.onosproject.net.pi.runtime.PiConstantsTest.EGRESS_PORT; |
| 29 | |
| 30 | /** |
| 31 | * Unit tests for PiControlMetadata class. |
| 32 | */ |
| 33 | public class PiControlMetadataTest { |
| 34 | |
| 35 | final PiControlMetadataId piControlMetadataId = PiControlMetadataId.of(EGRESS_PORT); |
| 36 | |
| 37 | final PiControlMetadata piControlMetadata1 = PiControlMetadata.builder() |
| 38 | .withId(piControlMetadataId) |
| 39 | .withValue(copyFrom(0x10)) |
| 40 | .build(); |
| 41 | final PiControlMetadata sameAsPiControlMetadata1 = PiControlMetadata.builder() |
| 42 | .withId(piControlMetadataId) |
| 43 | .withValue(copyFrom(0x10)) |
| 44 | .build(); |
| 45 | final PiControlMetadata piControlMetadata2 = PiControlMetadata.builder() |
| 46 | .withId(piControlMetadataId) |
| 47 | .withValue(copyFrom(0x20)) |
| 48 | .build(); |
| 49 | |
| 50 | /** |
| 51 | * Checks that the PiControlMetadata class is immutable. |
| 52 | */ |
| 53 | @Test |
| 54 | public void testImmutability() { |
| 55 | |
| 56 | assertThatClassIsImmutable(PiControlMetadata.class); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Checks the operation of equals(), hashCode() and toString() methods. |
| 61 | */ |
| 62 | @Test |
| 63 | public void testEquals() { |
| 64 | |
| 65 | new EqualsTester() |
| 66 | .addEqualityGroup(piControlMetadata1, sameAsPiControlMetadata1) |
| 67 | .addEqualityGroup(piControlMetadata2) |
| 68 | .testEquals(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Checks the methods of PiControlMetadata. |
| 73 | */ |
| 74 | @Test |
| 75 | public void testMethods() { |
| 76 | |
| 77 | assertThat(piControlMetadata1, is(notNullValue())); |
| 78 | assertThat(piControlMetadata1.id(), is(PiControlMetadataId.of(EGRESS_PORT))); |
| 79 | assertThat(piControlMetadata1.value(), is(copyFrom(0x10))); |
| 80 | } |
| 81 | } |