Merge "Error code support for ErrorMessage"
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / TableModInputMessageFactoryTest.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 import io.netty.buffer.UnpooledByteBufAllocator;\r
6 import junit.framework.Assert;\r
7 \r
8 import org.junit.Test;\r
9 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
10 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
11 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInputBuilder;\r
16 \r
17 /**\r
18  * @author timotej.kubas\r
19  * @author michal.polkorab\r
20  */\r
21 public class TableModInputMessageFactoryTest {\r
22     private static final byte MESSAGE_TYPE = 17;\r
23     private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3;\r
24     \r
25     /**\r
26      * Testing of {@link TableModInputMessageFactory} for correct translation from POJO\r
27      * @throws Exception \r
28      */\r
29     @Test\r
30     public void testTableModInput() throws Exception {\r
31         TableModInputBuilder builder = new TableModInputBuilder();\r
32         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);\r
33         builder.setTableId(new TableId(9L));\r
34         builder.setConfig(new TableConfig(true));\r
35         TableModInput message = builder.build();\r
36         \r
37         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
38         TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance();\r
39         factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
40         \r
41         BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16);\r
42         Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte());\r
43         out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE);\r
44         Assert.assertEquals("Wrong TableConfig", 8, out.readUnsignedInt());\r
45     }\r
46     \r
47 }\r