Bump upstreams
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / test / java / org / opendaylight / openflowjava / nx / codec / action / AbstractActionCodecTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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 package org.opendaylight.openflowjava.nx.codec.action;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.ByteBufAllocator;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.nx.api.NiciraConstants;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
21
22 public class AbstractActionCodecTest {
23     private final int msgLength = 10;
24     private final byte subType = 5;
25
26     private ByteBuf buffer;
27     private byte[] bytes = new byte[10];
28
29     @Before
30     public void setUp() {
31         buffer = ByteBufAllocator.DEFAULT.buffer();
32     }
33
34     @Test
35     public void serializeHeaderTest() {
36         AbstractActionCodec.serializeHeader(msgLength, subType, buffer);
37         assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
38         assertEquals(msgLength, buffer.readUnsignedShort());
39         assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
40         assertEquals(subType, buffer.readUnsignedShort());
41     }
42
43     @Test
44     public void deserializeHeaderTest() {
45         buffer.writeBytes(bytes);
46         int readerIndex = buffer.readerIndex();
47         ActionBuilder actionBuilder = AbstractActionCodec.deserializeHeader(buffer);
48         assertNotNull(actionBuilder);
49         assertEquals(NiciraConstants.NX_VENDOR_ID, actionBuilder.getExperimenterId().getValue());
50         assertTrue(buffer.readerIndex() - readerIndex == 10);
51     }
52 }