"Added more deserialization factories & their unit tests"
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / QueueGetConfigReplyMessageFactoryMultiTest.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 io.netty.buffer.ByteBuf;\r
5 \r
6 import java.util.ArrayList;\r
7 import java.util.List;\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.PortNumber;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperty;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.Properties;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.PropertiesBuilder;\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;\r
20 \r
21 /**\r
22  * @author timotej.kubas\r
23  * @author michal.polkorab\r
24  */\r
25 public class QueueGetConfigReplyMessageFactoryMultiTest {\r
26 \r
27     /**\r
28      * Testing of {@link QueueGetConfigReplyMessageFactory} for correct\r
29      * translation into POJO\r
30      */\r
31     @Test\r
32     public void test() {\r
33         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port\r
34                 "00 00 00 00 " + // padding\r
35                 "00 00 00 01 " + // queueId\r
36                 "00 00 00 01 " + // port\r
37                 "00 00 00 00 00 00 00 00 " + // pad\r
38                 "00 01 " + // property\r
39                 "00 00 00 00 00 00 " + // pad\r
40                 "00 00 00 02 " + // queueId\r
41                 "00 00 00 02 " + // port\r
42                 "00 00 00 00 00 00 00 00 " + // pad\r
43                 "00 01 " + // property\r
44                 "00 00 00 00 00 00 " + // pad\r
45                 "00 00 00 03 " + // queueId\r
46                 "00 00 00 03 " + // port\r
47                 "00 00 00 00 00 00 00 00 " + // pad\r
48                 "00 01 " + // property\r
49                 "00 00 00 00 00 00" // pad\r
50         );\r
51 \r
52         GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(\r
53                 QueueGetConfigReplyMessageFactory.getInstance(), bb);\r
54 \r
55         BufferHelper.checkHeaderV13(builtByFactory);\r
56         Assert.assertTrue("Wrong port", 66051L == builtByFactory.getPort().getValue());\r
57         Assert.assertTrue("Wrong queues", true == compareLists(builtByFactory.getQueues(),\r
58                         createQueuesList()));\r
59     }\r
60 \r
61     private static List<Queues> createQueuesList() {\r
62         List<Queues> queuesList = new ArrayList<Queues>();\r
63         QueuesBuilder qb = new QueuesBuilder();\r
64         for (int i = 1; i <= 3; i++) {\r
65             qb.setQueueId(new QueueId((long) i));\r
66             qb.setPort(new PortNumber((long) i));\r
67             qb.setProperties(createPropertiesList());\r
68             queuesList.add(qb.build());\r
69         }\r
70         return queuesList;\r
71     }\r
72 \r
73     private static List<Properties> createPropertiesList() {\r
74         List<Properties> propertiesList = new ArrayList<Properties>();\r
75         PropertiesBuilder pb = new PropertiesBuilder();\r
76         pb.setProperty(QueueProperty.values()[1]);\r
77         propertiesList.add(pb.build());\r
78         return propertiesList;\r
79     }\r
80 \r
81     private static boolean compareLists(List<Queues> originalList,\r
82             List<Queues> testList) {\r
83         boolean result = false;\r
84         int originalListLength = originalList.size();\r
85         for (int i = 0; i < originalListLength; i++) {\r
86             if (originalList.get(i).getPort().equals(testList.get(i).getPort())) {\r
87                 result = true;\r
88             } else {\r
89                 result = false;\r
90                 break;\r
91             }\r
92             if (originalList.get(i).getQueueId()\r
93                     .equals(testList.get(i).getQueueId())) {\r
94                 result = true;\r
95             } else {\r
96                 result = false;\r
97                 break;\r
98             }\r
99             if (originalList.get(i).getProperties().get(0).getProperty()\r
100                     .equals(testList.get(i).getProperties().get(0).getProperty())) {\r
101                 result = true;\r
102             } else {\r
103                 result = false;\r
104                 break;\r
105             }\r
106         }\r
107         return result;\r
108     }\r
109 \r
110 }\r