GetAsyncReplyMessageFactory, QueueGetConfigReplyMessageFactoryTest
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / QueueGetConfigReplyMessageFactoryTest.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.Comparator;\r
6 import java.util.List;\r
7 \r
8 import io.netty.buffer.ByteBuf;\r
9 \r
10 import org.junit.Assert;\r
11 import org.junit.Test;\r
12 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperty;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.Properties;\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.PropertiesBuilder;\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;\r
21 \r
22 import com.google.common.collect.ComparisonChain;\r
23 \r
24 /**\r
25  * @author timotej.kubas\r
26  * @author michal.polkorab\r
27  */\r
28 public class QueueGetConfigReplyMessageFactoryTest {\r
29 \r
30     @Test\r
31     public void test(){\r
32         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00");\r
33         GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb);\r
34         BufferHelper.checkHeaderV13(builtByFactory);\r
35         Assert.assertTrue("Wrong port",66051L == builtByFactory.getPort().getValue());\r
36         Assert.assertTrue("Wrong queues", true == compareLists(builtByFactory.getQueues(), createQueuesList()));\r
37     }\r
38     \r
39     public List<Queues> createQueuesList(){\r
40         final byte PADDING_IN_PACKET_QUEUE_HEADER = 6;\r
41         List<Queues> queuesList = new ArrayList<Queues>();\r
42         QueuesBuilder qb = new QueuesBuilder();\r
43         qb.setQueueId(new QueueId((long) 1));\r
44         qb.setPort(new PortNumber((long) 1));\r
45         qb.setProperties(createPropertiesList());\r
46         queuesList.add(qb.build());\r
47         \r
48         return queuesList;\r
49     }\r
50     \r
51     public List<Properties> createPropertiesList(){\r
52         final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4;\r
53         List<Properties> propertiesList = new ArrayList<Properties>();\r
54         PropertiesBuilder pb = new PropertiesBuilder();\r
55         pb.setProperty(QueueProperty.values()[2]);\r
56         propertiesList.add(pb.build());\r
57         \r
58         return propertiesList;\r
59     }\r
60     \r
61     public boolean compareLists(List<Queues> originalList, List<Queues> testList){\r
62         boolean decision = false;\r
63         int originalListLength = originalList.size();\r
64         int testListLength = testList.size();\r
65         \r
66         for(int i=0; i<originalListLength; i++){\r
67             if(originalList.get(i).getPort().equals(testList.get(i).getPort())) {\r
68                 decision = true;\r
69             } else {\r
70                 decision = false;\r
71                 break;\r
72             }\r
73             if(originalList.get(i).getQueueId().equals(testList.get(i).getQueueId())) {\r
74                 decision = true;\r
75             } else {\r
76                 decision = false;\r
77                 break;\r
78             }\r
79             if(originalList.get(i).getProperties().get(0).getProperty().equals(\r
80                     testList.get(i).getProperties().get(0).getProperty())) {\r
81                 decision = true;\r
82             } else {\r
83                 decision = false;\r
84                 break;\r
85             }\r
86         }\r
87         return decision;\r
88     }\r
89 }\r