Factory tests back to stable
[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.augments.rev131002.RateQueueProperty;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;\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 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;\r
22 \r
23 /**\r
24  * @author timotej.kubas\r
25  * @author michal.polkorab\r
26  */\r
27 public class QueueGetConfigReplyMessageFactoryMultiTest {\r
28 \r
29     /**\r
30      * Testing of {@link QueueGetConfigReplyMessageFactory} for correct\r
31      * translation into POJO\r
32      */\r
33     @Test\r
34     public void test() {\r
35         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port\r
36                 "00 00 00 00 " + // padding\r
37                 "00 00 00 01 " + // queueId\r
38                 "00 00 00 01 " + // port\r
39                 "00 20 " + // length\r
40                 "00 00 00 00 00 00 " + // pad\r
41                 "00 02 " + // property\r
42                 "00 10 " + // length\r
43                 "00 00 00 00 " + // pad\r
44                 "00 05 " + // rate\r
45                 "00 00 00 00 00 00 " + // pad\r
46                 "00 00 00 02 " + // queueId\r
47                 "00 00 00 02 " + // port\r
48                 "00 20 " + // length\r
49                 "00 00 00 00 00 00 " + // pad\r
50                 "00 02 " + // property\r
51                 "00 10 " + // length\r
52                 "00 00 00 00 " + // pad\r
53                 "00 05 " + // rate\r
54                 "00 00 00 00 00 00 " // pad\r
55         );\r
56 \r
57         GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(\r
58                 QueueGetConfigReplyMessageFactory.getInstance(), bb);\r
59 \r
60         BufferHelper.checkHeaderV13(builtByFactory);\r
61         Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue());\r
62         Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues());\r
63     }\r
64 \r
65     private static List<Queues> createQueuesList() {\r
66         List<Queues> queuesList = new ArrayList<>();\r
67         for (int i = 1; i < 3; i++) {\r
68             QueuesBuilder qb = new QueuesBuilder();\r
69             qb.setQueueId(new QueueId((long) i));\r
70             qb.setPort(new PortNumber((long) i));\r
71             qb.setQueueProperty(createPropertiesList());\r
72             queuesList.add(qb.build());\r
73         }\r
74         return queuesList;\r
75     }\r
76 \r
77     private static List<QueueProperty> createPropertiesList() {\r
78         List<QueueProperty> propertiesList = new ArrayList<>();\r
79         QueuePropertyBuilder pb = new QueuePropertyBuilder();\r
80         pb.setProperty(QueueProperties.forValue(2));\r
81         RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();\r
82         rateBuilder.setRate(5);\r
83         pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());\r
84         propertiesList.add(pb.build());\r
85         return propertiesList;\r
86     }\r
87 \r
88 }\r