Merge "Bug 5543 - Bo: Update JUnit tests part_2"
[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
9 package org.opendaylight.openflowjava.nx.codec.action;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.ByteBufAllocator;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.nx.api.NiciraConstants;
20 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
22
23 public class AbstractActionCodecTest {
24
25
26     private ByteBuf buffer;
27     private byte[] bytes = new byte[10];
28
29     private final int msgLength = 10;
30     private final byte subType = 5;
31
32
33     @Before
34     public void setUp() {
35         buffer = ByteBufAllocator.DEFAULT.buffer();
36     }
37
38
39     @Test
40     public void serializeHeaderTest() {
41         AbstractActionCodec.serializeHeader(msgLength, subType, buffer);
42         assertEquals(EncodeConstants.EXPERIMENTER_VALUE, buffer.readUnsignedShort());
43         assertEquals(msgLength, buffer.readUnsignedShort());
44         assertEquals(NiciraConstants.NX_VENDOR_ID.intValue(), buffer.readUnsignedInt());
45         assertEquals(subType, buffer.readUnsignedShort());
46     }
47
48     @Test
49     public void deserializeHeaderTest() {
50         buffer.writeBytes(bytes);
51         int readerIndex = buffer.readerIndex();
52         ActionBuilder actionBuilder = AbstractActionCodec.deserializeHeader(buffer);
53         assertNotNull(actionBuilder);
54         assertEquals(NiciraConstants.NX_VENDOR_ID, actionBuilder.getExperimenterId().getValue());
55         assertTrue(buffer.readerIndex() - readerIndex == 10);
56     }
57
58 }