new changes incorporated in serialization/deserialization factories
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / HelloMessageFactoryTest.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
3 \r
4 import java.util.ArrayList;\r
5 import java.util.List;\r
6 \r
7 import io.netty.buffer.ByteBuf;\r
8 \r
9 import org.junit.Assert;\r
10 import org.junit.Test;\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.HelloMessage;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder;\r
16 \r
17 /**\r
18  * @author michal.polkorab\r
19  * @author timotej.kubas\r
20  */\r
21 public class HelloMessageFactoryTest {\r
22 \r
23     /** Number of currently supported version / codec */\r
24     public static final Short VERSION_YET_SUPPORTED = 0x04;\r
25 \r
26     /**\r
27      * Testing {@link HelloMessageFactory} for correct translation into POJO\r
28      */\r
29     @Test\r
30     public void test() {\r
31         ByteBuf bb = BufferHelper.buildBuffer("00 01 "+ //type\r
32                                               "00 00 00 11 "+//booelan element 1\r
33                                               "00 00 00 11"//booelan element 2\r
34                 );\r
35         HelloMessage builtByFactory = BufferHelper.decodeV13(\r
36                 HelloMessageFactory.getInstance(), bb);\r
37 \r
38         BufferHelper.checkHeaderV13(builtByFactory);\r
39         Assert.assertEquals("Wrong type", createElement().get(0).getType().getIntValue(), builtByFactory.getElements().get(0).getType().getIntValue());\r
40     }\r
41     \r
42     private static List<Elements> createElement() {\r
43         ElementsBuilder elementsBuilder = new ElementsBuilder();\r
44         List<Elements> elementsList = new ArrayList<Elements>();\r
45         List<Boolean> booleanList = new ArrayList<Boolean>();\r
46         booleanList.add(true);\r
47         booleanList.add(false);\r
48         booleanList.add(false);\r
49         booleanList.add(false);\r
50         booleanList.add(true);\r
51         for (int i = 1; i < 60; i++) {\r
52             booleanList.add(false);\r
53         }\r
54         elementsBuilder.setType(HelloElementType.forValue(1));\r
55         elementsBuilder.setVersionBitmap(booleanList);\r
56         elementsList.add(elementsBuilder.build());\r
57         \r
58         return elementsList;\r
59     }\r
60 }\r