ab4ef3a6c193a6deed04dc41343ce14805326542
[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.Before;
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
20 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
21 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
22 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
23 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
24 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;
35
36 /**
37  * @author timotej.kubas
38  * @author michal.polkorab
39  */
40 public class QueueGetConfigReplyMessageFactoryTest {
41
42     private OFDeserializer<GetQueueConfigOutput> queueFactory;
43
44     /**
45      * Initializes deserializer registry and lookups correct deserializer
46      */
47     @Before
48     public void startUp() {
49         DeserializerRegistry registry = new DeserializerRegistryImpl();
50         registry.init();
51         queueFactory = registry.getDeserializer(
52                 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 23, GetQueueConfigOutput.class));
53     }
54
55     /**
56      * Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO
57      */
58     @Test
59     public void test(){
60         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");
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         List<Queues> queuesList = new ArrayList<>();
69         QueuesBuilder qb = new QueuesBuilder();
70         qb.setQueueId(new QueueId(1L));
71         qb.setPort(new PortNumber(3L));
72         qb.setQueueProperty(createPropertiesList());
73         queuesList.add(qb.build());
74         
75         return queuesList;
76     }
77     
78     private static List<QueueProperty> createPropertiesList(){
79         List<QueueProperty> propertiesList = new ArrayList<>();
80         QueuePropertyBuilder pb = new QueuePropertyBuilder();
81         pb.setProperty(QueueProperties.forValue(2));
82         RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
83         rateBuilder.setRate(5);
84         pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());
85         propertiesList.add(pb.build());
86         return propertiesList;
87     }
88 }