Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10QueueGetConfigReplyMessageFactoryTest.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 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.RateQueueProperty;
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
27 /**
28  * @author michal.polkorab
29  *
30  */
31 public class OF10QueueGetConfigReplyMessageFactoryTest {
32
33     private OFDeserializer<GetQueueConfigOutput> queueFactory;
34
35     /**
36      * Initializes deserializer registry and lookups correct deserializer
37      */
38     @Before
39     public void startUp() {
40         DeserializerRegistry registry = new DeserializerRegistryImpl();
41         registry.init();
42         queueFactory = registry.getDeserializer(
43                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 21, GetQueueConfigOutput.class));
44     }
45
46     /**
47      * Testing of {@link OF10QueueGetConfigReplyMessageFactory} for correct
48      * translation into POJO
49      */
50     @Test
51     public void test() {
52         ByteBuf bb = BufferHelper.buildBuffer("00 01 00 00 00 00 00 00 "
53                 + "00 00 00 08 00 10 00 00 00 00 00 08 00 00 00 00 "
54                 + "00 00 00 02 00 28 00 00 00 01 00 10 00 00 00 00 00 20 00 00 00 00 00 00 "
55                 + "00 01 00 10 00 00 00 00 00 30 00 00 00 00 00 00");
56         GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(
57                 queueFactory, bb);
58
59         BufferHelper.checkHeaderV10(builtByFactory);
60         Assert.assertEquals("Wrong port", 1, builtByFactory.getPort().getValue().intValue());
61         Assert.assertEquals("Wrong queues size", 2, builtByFactory.getQueues().size());
62         Queues queue1 = builtByFactory.getQueues().get(0);
63         Queues queue2 = builtByFactory.getQueues().get(1);
64         Assert.assertEquals("Wrong queueId", 8, queue1.getQueueId().getValue().intValue());
65         Assert.assertEquals("Wrong queue - # properties", 1, queue1.getQueueProperty().size());
66         Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTNONE,
67                 queue1.getQueueProperty().get(0).getProperty());
68         Assert.assertEquals("Wrong queueId", 2, queue2.getQueueId().getValue().intValue());
69         Assert.assertEquals("Wrong queue - # properties", 2, queue2.getQueueProperty().size());
70         Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTMINRATE,
71                 queue2.getQueueProperty().get(0).getProperty());
72         Assert.assertEquals("Wrong queue - wrong property", QueueProperties.OFPQTMINRATE,
73                 queue2.getQueueProperty().get(1).getProperty());
74         RateQueueProperty rate1 = queue2.getQueueProperty().get(0).getAugmentation(RateQueueProperty.class);
75         RateQueueProperty rate2 = queue2.getQueueProperty().get(1).getAugmentation(RateQueueProperty.class);
76         Assert.assertEquals("Wrong queue - wrong property rate", 32, rate1.getRate().intValue());
77         Assert.assertEquals("Wrong queue - wrong property rate", 48, rate2.getRate().intValue());
78     }
79 }