Merge "Added more serialization factories"
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / EchoInputMessageFactoryTest.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 \r
7 import org.junit.Assert;\r
8 import org.junit.Test;\r
9 import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
10 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;\r
13 \r
14 /**\r
15  * @author michal.polkorab\r
16  *\r
17  */\r
18 public class EchoInputMessageFactoryTest {\r
19 \r
20     private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = 2;\r
21     \r
22     /**\r
23      * Testing of {@link EchoInputMessageFactory} for correct translation from POJO\r
24      */\r
25     @Test\r
26     public void test() {\r
27         EchoInputBuilder eib = new EchoInputBuilder();\r
28         eib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
29         eib.setXid(16909060L);\r
30         EchoInput ei = eib.build();\r
31         \r
32         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
33         EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance();\r
34         eimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, ei);\r
35         \r
36         Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
37         Assert.assertTrue(out.readByte() == ECHO_REQUEST_MESSAGE_CODE_TYPE);\r
38         Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
39         Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
40     }\r
41 \r
42 }\r