Merge "Fix checkstyle warnings for impl/protocol test package"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / instruction / WriteMetadataInstructionDeserializerTest.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization.instruction;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.UnpooledByteBufAllocator;
16 import java.math.BigInteger;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
20 import org.opendaylight.openflowplugin.openflow.md.util.ByteUtil;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
23
24 public class WriteMetadataInstructionDeserializerTest extends AbstractInstructionDeserializerTest {
25
26     @Test
27     public void testDeserialize() throws Exception {
28         final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
29         final BigInteger metadata = BigInteger.valueOf(1234L);
30         final BigInteger metadataMask = BigInteger.valueOf(9876L);
31         writeHeader(in);
32         in.writeZero(InstructionConstants.PADDING_IN_WRITE_METADATA);
33         in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadata, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
34         in.writeBytes(ByteUtil.convertBigIntegerToNBytes(metadataMask, EncodeConstants.SIZE_OF_LONG_IN_BYTES));
35
36         final Instruction instruction = deserializeInstruction(in);
37         assertEquals(WriteMetadataCase.class, instruction.getImplementedInterface());
38
39         assertArrayEquals(
40                 ByteUtil
41                         .convertBigIntegerToNBytes(metadata, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
42                 ByteUtil
43                         .convertBigIntegerToNBytes(WriteMetadataCase.class.cast(instruction).getWriteMetadata()
44                                 .getMetadata(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
45
46         assertArrayEquals(
47                 ByteUtil
48                         .convertBigIntegerToNBytes(metadataMask, EncodeConstants.SIZE_OF_LONG_IN_BYTES),
49                 ByteUtil
50                         .convertBigIntegerToNBytes(WriteMetadataCase.class.cast(instruction).getWriteMetadata()
51                                 .getMetadataMask(), EncodeConstants.SIZE_OF_LONG_IN_BYTES));
52
53         assertEquals(0, in.readableBytes());
54     }
55
56     @Override
57     protected short getType() {
58         return InstructionConstants.WRITE_METADATA_TYPE;
59     }
60
61     @Override
62     protected short getLength() {
63         return InstructionConstants.STANDARD_INSTRUCTION_LENGTH;
64     }
65
66 }