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