Update MRI upstreams for Phosphorus
[openflowplugin.git] / openflowjava / 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 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.RateQueuePropertyBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;
31 import org.opendaylight.yangtools.yang.common.Uint16;
32 import org.opendaylight.yangtools.yang.common.Uint32;
33
34 /**
35  * Unit tests for QueueGetConfigReplyMessageFactory.
36  *
37  * @author timotej.kubas
38  * @author michal.polkorab
39  */
40 public class QueueGetConfigReplyMessageFactoryTest {
41     private OFDeserializer<GetQueueConfigOutput> queueFactory;
42
43     /**
44      * Initializes deserializer registry and lookups correct deserializer.
45      */
46     @Before
47     public void startUp() {
48         DeserializerRegistry registry = new DeserializerRegistryImpl();
49         registry.init();
50         queueFactory = registry.getDeserializer(
51                 new MessageCodeKey(EncodeConstants.OF_VERSION_1_3, 23, GetQueueConfigOutput.class));
52     }
53
54     /**
55      * Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO.
56      */
57     @Test
58     public void test() {
59         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 "
60                 + "00 00 00 02 00 10 00 00 00 00 00 05 00 00 00 00 00 00");
61         GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(queueFactory, bb);
62         BufferHelper.checkHeaderV13(builtByFactory);
63         Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue());
64         Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList());
65     }
66
67     private static List<Queues> createQueuesList() {
68         final List<Queues> queuesList = new ArrayList<>();
69         queuesList.add(new QueuesBuilder()
70             .setQueueId(new QueueId(Uint32.ONE))
71             .setPort(new PortNumber(Uint32.valueOf(3)))
72             .setQueueProperty(createPropertiesList())
73             .build());
74
75         return queuesList;
76     }
77
78     private static List<QueueProperty> createPropertiesList() {
79         final List<QueueProperty> propertiesList = new ArrayList<>();
80         propertiesList.add(new QueuePropertyBuilder()
81             .setProperty(QueueProperties.forValue(2))
82             .addAugmentation(new RateQueuePropertyBuilder().setRate(Uint16.valueOf(5)).build())
83             .build());
84         return propertiesList;
85     }
86 }