Merge "Fix checkstyle warnings for impl/protocol test package"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / instruction / WriteActionsInstructionDeserializerTest.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.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.UnpooledByteBufAllocator;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
19 import org.opendaylight.openflowjava.protocol.impl.util.InstructionConstants;
20 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
21 import org.opendaylight.openflowplugin.impl.protocol.deserialization.key.MessageCodeActionExperimenterKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
25
26 public class WriteActionsInstructionDeserializerTest extends AbstractInstructionDeserializerTest {
27
28     private OFDeserializer<Instruction> deserializer;
29
30     @Override
31     @SuppressWarnings("checkstyle:LineLength")
32     protected void init() {
33         deserializer = getRegistry().getDeserializer(
34                 new MessageCodeActionExperimenterKey(EncodeConstants.OF13_VERSION_ID, getType(), Instruction.class,
35                         ActionPath
36                                 .NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION,
37                         null));
38     }
39
40     @Test
41     public void testDeserialize() throws Exception {
42         final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
43
44         // Header
45         final int startIndex = in.writerIndex();
46         in.writeShort(getType());
47         final int index = in.writerIndex();
48         in.writeShort(getLength());
49         in.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
50
51         // POP PBB action
52         in.writeShort(ActionConstants.POP_PBB_CODE);
53         in.writeShort(ActionConstants.GENERAL_ACTION_LENGTH);
54         in.writeZero(ActionConstants.PADDING_IN_ACTION_HEADER);
55
56         in.setShort(index, in.writerIndex() - startIndex);
57
58         final Instruction instruction = deserializer.deserialize(in);
59         assertEquals(WriteActionsCase.class, instruction.getImplementedInterface());
60         final WriteActionsCase actionCase = WriteActionsCase.class.cast(instruction);
61         assertEquals(1, actionCase.getWriteActions().getAction().size());
62         assertEquals(PopPbbActionCase.class, actionCase.getWriteActions().getAction().get(0)
63                 .getAction().getImplementedInterface());
64         assertEquals(0, in.readableBytes());
65     }
66
67     @Override
68     protected short getType() {
69         return InstructionConstants.WRITE_ACTIONS_TYPE;
70     }
71
72     @Override
73     protected short getLength() {
74         return EncodeConstants.EMPTY_LENGTH;
75     }
76
77 }