Merge "Added more (de)serialization factories + ByteBufUtils methods"
[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 java.util.List;\r
8 \r
9 import org.junit.Test;\r
10 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
11 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder;\r
17 \r
18 import com.google.common.collect.Lists;\r
19 \r
20 /**\r
21  * @author michal.polkorab\r
22  *\r
23  */\r
24 public class HelloInputMessageFactoryTest {\r
25 \r
26     private static final byte HELLO_MESSAGE_CODE_TYPE = 0;\r
27     \r
28     /**\r
29      * Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
30      * @throws Exception \r
31      */\r
32     @Test\r
33     public void testWithoutElementsSet() throws Exception {\r
34         HelloInputBuilder hib = new HelloInputBuilder();\r
35         BufferHelper.setupHeader(hib);\r
36         HelloInput hi = hib.build();\r
37         \r
38         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
39         HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();\r
40         himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);\r
41         \r
42         BufferHelper.checkHeaderV13(out, HELLO_MESSAGE_CODE_TYPE, 8);\r
43     }\r
44     \r
45     /**\r
46      * Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
47      * @throws Exception \r
48      */\r
49     @Test\r
50     public void testWithElementsSet() throws Exception {\r
51         HelloInputBuilder hib = new HelloInputBuilder();\r
52         BufferHelper.setupHeader(hib);\r
53         ElementsBuilder eb = new ElementsBuilder();\r
54         eb.setType(HelloElementType.VERSIONBITMAP);\r
55         eb.setData(new byte[]{0x01, 0x02, 0x42, 0x03});\r
56         List<Elements> elementList = Lists.newArrayList(eb.build());\r
57         hib.setElements(elementList);\r
58         HelloInput hi = hib.build();\r
59         \r
60         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
61         HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();\r
62         himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);\r
63         \r
64         BufferHelper.checkHeaderV13(out, HELLO_MESSAGE_CODE_TYPE, 8);\r
65         // TODO - element list\r
66     }\r
67 \r
68 }\r