Added more serialization factories
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / HelloInputMessageFactoryTest.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.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;\r
14 \r
15 /**\r
16  * @author michal.polkorab\r
17  *\r
18  */\r
19 public class HelloInputMessageFactoryTest {\r
20 \r
21     private static final byte HELLO_MESSAGE_CODE_TYPE = 0;\r
22     \r
23     /**\r
24      * Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
25      */\r
26     @Test\r
27     public void testWithoutElementsSet() {\r
28         HelloInputBuilder hib = new HelloInputBuilder();\r
29         hib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
30         hib.setXid(16909060L);\r
31         HelloInput hi = hib.build();\r
32         \r
33         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
34         HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();\r
35         himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);\r
36         \r
37         Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
38         Assert.assertTrue(out.readByte() == HELLO_MESSAGE_CODE_TYPE);\r
39         Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
40         Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
41     }\r
42 \r
43 }\r