Rework bit-copying functions and re-enable tests
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / action / OutputActionDeserializerTest.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.action;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.UnpooledByteBufAllocator;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
18 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
19 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction;
23
24 public class OutputActionDeserializerTest extends AbstractActionDeserializerTest {
25
26     @Test
27     public void testDeserialize() throws Exception {
28         final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
29         final int portNum = 10;
30         final short maxLength = 24;
31         writeHeader(in);
32         in.writeInt(portNum);
33         in.writeShort(maxLength);
34         in.writeZero(ActionConstants.OUTPUT_PADDING);
35
36         final Action action = deserializeAction(in);
37         assertTrue(OutputActionCase.class.isInstance(action));
38
39         final OutputAction outputAction = OutputActionCase.class.cast(action).getOutputAction();
40         assertEquals(portNum, InventoryDataServiceUtil.portNumberfromNodeConnectorId(
41                 OpenflowVersion.OF13, outputAction.getOutputNodeConnector().getValue()).intValue());
42         assertEquals(maxLength, outputAction.getMaxLength().shortValue());
43         assertEquals(0, in.readableBytes());
44     }
45
46     @Override
47     protected short getType() {
48         return ActionConstants.OUTPUT_CODE;
49     }
50
51     @Override
52     protected short getLength() {
53         return ActionConstants.GENERAL_ACTION_LENGTH;
54     }
55
56 }