4d8cb22849121be8f444f090989ce2408368a1f2
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / QueueGetConfigReplyMessageFactoryMultiTest.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;
29
30 /**
31  * @author timotej.kubas
32  * @author michal.polkorab
33  */
34 public class QueueGetConfigReplyMessageFactoryMultiTest {
35
36     /**
37      * Testing of {@link QueueGetConfigReplyMessageFactory} for correct
38      * translation into POJO
39      */
40     @Test
41     public void test() {
42         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port
43                 "00 00 00 00 " + // padding
44                 "00 00 00 01 " + // queueId
45                 "00 00 00 01 " + // port
46                 "00 20 " + // length
47                 "00 00 00 00 00 00 " + // pad
48                 "00 02 " + // property
49                 "00 10 " + // length
50                 "00 00 00 00 " + // pad
51                 "00 05 " + // rate
52                 "00 00 00 00 00 00 " + // pad
53                 "00 00 00 02 " + // queueId
54                 "00 00 00 02 " + // port
55                 "00 20 " + // length
56                 "00 00 00 00 00 00 " + // pad
57                 "00 02 " + // property
58                 "00 10 " + // length
59                 "00 00 00 00 " + // pad
60                 "00 05 " + // rate
61                 "00 00 00 00 00 00 " // pad
62         );
63
64         GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(
65                 QueueGetConfigReplyMessageFactory.getInstance(), bb);
66
67         BufferHelper.checkHeaderV13(builtByFactory);
68         Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue());
69         Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues());
70     }
71
72     private static List<Queues> createQueuesList() {
73         List<Queues> queuesList = new ArrayList<>();
74         for (int i = 1; i < 3; i++) {
75             QueuesBuilder qb = new QueuesBuilder();
76             qb.setQueueId(new QueueId((long) i));
77             qb.setPort(new PortNumber((long) i));
78             qb.setQueueProperty(createPropertiesList());
79             queuesList.add(qb.build());
80         }
81         return queuesList;
82     }
83
84     private static List<QueueProperty> createPropertiesList() {
85         List<QueueProperty> propertiesList = new ArrayList<>();
86         QueuePropertyBuilder pb = new QueuePropertyBuilder();
87         pb.setProperty(QueueProperties.forValue(2));
88         RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
89         rateBuilder.setRate(5);
90         pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());
91         propertiesList.add(pb.build());
92         return propertiesList;
93     }
94
95 }