157e8d7fa402ca203354927c61447f057de68a03
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / QueueGetConfigReplyMessageFactoryTest.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 QueueGetConfigReplyMessageFactoryTest {
35
36     /**
37      * Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO
38      */
39     @Test
40     public void test(){
41         ByteBuf bb = BufferHelper.buildBuffer("00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 03 00 20 00 00 00 00 00 00 00 02 00 10 00 00 00 00 00 05 00 00 00 00 00 00");
42         GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb);
43         BufferHelper.checkHeaderV13(builtByFactory);
44         Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue());
45         Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList());
46     }
47     
48     private static List<Queues> createQueuesList(){
49         List<Queues> queuesList = new ArrayList<>();
50         QueuesBuilder qb = new QueuesBuilder();
51         qb.setQueueId(new QueueId(1L));
52         qb.setPort(new PortNumber(3L));
53         qb.setQueueProperty(createPropertiesList());
54         queuesList.add(qb.build());
55         
56         return queuesList;
57     }
58     
59     private static List<QueueProperty> createPropertiesList(){
60         List<QueueProperty> propertiesList = new ArrayList<>();
61         QueuePropertyBuilder pb = new QueuePropertyBuilder();
62         pb.setProperty(QueueProperties.forValue(2));
63         RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
64         rateBuilder.setRate(5);
65         pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());
66         propertiesList.add(pb.build());
67         return propertiesList;
68     }
69 }