| /* |
| * Copyright 2017-present Open Networking Foundation |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package org.onosproject.p4runtime.model; |
| |
| import com.google.common.collect.ImmutableList; |
| import com.google.common.testing.EqualsTester; |
| import org.junit.Test; |
| import org.onosproject.net.pi.model.PiControlMetadataId; |
| import org.onosproject.net.pi.model.PiControlMetadataModel; |
| import org.onosproject.net.pi.model.PiPacketOperationType; |
| import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| |
| /** |
| * Unit tests for P4PacketOperationModel class. |
| */ |
| public class P4PacketOperationModelTest { |
| |
| private static final PiPacketOperationType PI_PACKET_OPERATION_TYPE_1 = PiPacketOperationType.PACKET_IN; |
| private static final PiPacketOperationType PI_PACKET_OPERATION_TYPE_2 = PiPacketOperationType.PACKET_OUT; |
| |
| private static final PiControlMetadataId PI_CONTROL_METADATA_ID_1 = PiControlMetadataId.of("Metadata1"); |
| private static final PiControlMetadataId PI_CONTROL_METADATA_ID_2 = PiControlMetadataId.of("Metadata2"); |
| |
| private static final int BIT_WIDTH_1 = 8; |
| private static final int BIT_WIDTH_2 = 9; |
| |
| private static final PiControlMetadataModel PI_CONTROL_METADATA_MODEL_1 = |
| new P4ControlMetadataModel(PI_CONTROL_METADATA_ID_1, BIT_WIDTH_1); |
| private static final PiControlMetadataModel PI_CONTROL_METADATA_MODEL_2 = |
| new P4ControlMetadataModel(PI_CONTROL_METADATA_ID_2, BIT_WIDTH_2); |
| |
| private static final ImmutableList<PiControlMetadataModel> METADATAS_1 = |
| new ImmutableList.Builder<PiControlMetadataModel>() |
| .add(PI_CONTROL_METADATA_MODEL_1) |
| .build(); |
| |
| private static final ImmutableList<PiControlMetadataModel> METADATAS_2 = |
| new ImmutableList.Builder<PiControlMetadataModel>() |
| .add(PI_CONTROL_METADATA_MODEL_2) |
| .build(); |
| |
| private static final ImmutableList<PiControlMetadataModel> METADATAS_3 = |
| new ImmutableList.Builder<PiControlMetadataModel>() |
| .add(PI_CONTROL_METADATA_MODEL_1) |
| .add(PI_CONTROL_METADATA_MODEL_2) |
| .build(); |
| |
| private static final P4PacketOperationModel P4_PACKET_OPERATION_MODEL_1 = |
| new P4PacketOperationModel(PI_PACKET_OPERATION_TYPE_1, METADATAS_1); |
| private static final P4PacketOperationModel SAME_AS_P4_PACKET_OPERATION_MODEL_1 = |
| new P4PacketOperationModel(PI_PACKET_OPERATION_TYPE_1, METADATAS_1); |
| private static final P4PacketOperationModel P4_PACKET_OPERATION_MODEL_2 = |
| new P4PacketOperationModel(PI_PACKET_OPERATION_TYPE_2, METADATAS_2); |
| private static final P4PacketOperationModel P4_PACKET_OPERATION_MODEL_3 = |
| new P4PacketOperationModel(PI_PACKET_OPERATION_TYPE_2, METADATAS_3); |
| |
| /** |
| * Checks that the P4PacketOperationModel class is immutable. |
| */ |
| @Test |
| public void testImmutability() { |
| assertThatClassIsImmutable(P4PacketOperationModel.class); |
| } |
| |
| /** |
| * Checks the operation of equals(), hashCode() and toString() methods. |
| */ |
| @Test |
| public void testEquals() { |
| new EqualsTester() |
| .addEqualityGroup(P4_PACKET_OPERATION_MODEL_1, SAME_AS_P4_PACKET_OPERATION_MODEL_1) |
| .addEqualityGroup(P4_PACKET_OPERATION_MODEL_2) |
| .addEqualityGroup(P4_PACKET_OPERATION_MODEL_3) |
| .testEquals(); |
| } |
| } |