Bug 2756 - Match model update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / QueueGetConfigReplyMessageFactoryMultiTest.java
index b0ea6cb66f30554f83e23c62bf06dd087718b0e4..f8102e5fc205638acff4c132336b45025cd2f23a 100644 (file)
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;\r
-\r
-/**\r
- * @author timotej.kubas\r
- * @author michal.polkorab\r
- */\r
-public class QueueGetConfigReplyMessageFactoryMultiTest {\r
-\r
-    /**\r
-     * Testing of {@link QueueGetConfigReplyMessageFactory} for correct\r
-     * translation into POJO\r
-     */\r
-    //@Test\r
- // TODO - fix test\r
-    public void test() {\r
-        ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port\r
-                "00 00 00 00 " + // padding\r
-                "00 00 00 01 " + // queueId\r
-                "00 00 00 01 " + // port\r
-                "00 00 00 00 00 00 00 00 " + // pad\r
-                "00 01 " + // property\r
-                "00 00 00 00 00 00 " + // pad\r
-                "00 00 00 02 " + // queueId\r
-                "00 00 00 02 " + // port\r
-                "00 00 00 00 00 00 00 00 " + // pad\r
-                "00 01 " + // property\r
-                "00 00 00 00 00 00 " + // pad\r
-                "00 00 00 03 " + // queueId\r
-                "00 00 00 03 " + // port\r
-                "00 00 00 00 00 00 00 00 " + // pad\r
-                "00 01 " + // property\r
-                "00 00 00 00 00 00" // pad\r
-        );\r
-\r
-        GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(\r
-                QueueGetConfigReplyMessageFactory.getInstance(), bb);\r
-\r
-        BufferHelper.checkHeaderV13(builtByFactory);\r
-        Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue());\r
-        Assert.assertEquals("Wrong queues", builtByFactory.getQueues(),\r
-                createQueuesList());\r
-    }\r
-\r
-    private static List<Queues> createQueuesList() {\r
-        List<Queues> queuesList = new ArrayList<>();\r
-        QueuesBuilder qb = new QueuesBuilder();\r
-        for (int i = 1; i <= 3; i++) {\r
-            qb.setQueueId(new QueueId((long) i));\r
-            qb.setPort(new PortNumber((long) i));\r
-            qb.setQueueProperty(createPropertiesList());\r
-            queuesList.add(qb.build());\r
-        }\r
-        return queuesList;\r
-    }\r
-\r
-    private static List<QueueProperty> createPropertiesList() {\r
-        List<QueueProperty> propertiesList = new ArrayList<>();\r
-        QueuePropertyBuilder pb = new QueuePropertyBuilder();\r
-        pb.setProperty(QueueProperties.forValue(1));\r
-        propertiesList.add(pb.build());\r
-        return propertiesList;\r
-    }\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
+
+import io.netty.buffer.ByteBuf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.RateQueueProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.RateQueuePropertyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;
+
+/**
+ * @author timotej.kubas
+ * @author michal.polkorab
+ */
+public class QueueGetConfigReplyMessageFactoryMultiTest {
+
+    private OFDeserializer<GetQueueConfigOutput> queueFactory;
+
+    /**
+     * Initializes deserializer registry and lookups correct deserializer
+     */
+    @Before
+    public void startUp() {
+        DeserializerRegistry registry = new DeserializerRegistryImpl();
+        registry.init();
+        queueFactory = registry.getDeserializer(
+                new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 23, GetQueueConfigOutput.class));
+    }
+
+    /**
+     * Testing of {@link QueueGetConfigReplyMessageFactory} for correct
+     * translation into POJO
+     */
+    @Test
+    public void test() {
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port
+                "00 00 00 00 " + // padding
+                "00 00 00 01 " + // queueId
+                "00 00 00 01 " + // port
+                "00 20 " + // length
+                "00 00 00 00 00 00 " + // pad
+                "00 02 " + // property
+                "00 10 " + // length
+                "00 00 00 00 " + // pad
+                "00 05 " + // rate
+                "00 00 00 00 00 00 " + // pad
+                "00 00 00 02 " + // queueId
+                "00 00 00 02 " + // port
+                "00 20 " + // length
+                "00 00 00 00 00 00 " + // pad
+                "00 02 " + // property
+                "00 10 " + // length
+                "00 00 00 00 " + // pad
+                "00 05 " + // rate
+                "00 00 00 00 00 00" // pad
+        );
+
+        GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(
+                queueFactory, bb);
+
+        BufferHelper.checkHeaderV13(builtByFactory);
+        Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue());
+        Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues());
+    }
+
+    private static List<Queues> createQueuesList() {
+        List<Queues> queuesList = new ArrayList<>();
+        for (int i = 1; i < 3; i++) {
+            QueuesBuilder qb = new QueuesBuilder();
+            qb.setQueueId(new QueueId((long) i));
+            qb.setPort(new PortNumber((long) i));
+            qb.setQueueProperty(createPropertiesList());
+            queuesList.add(qb.build());
+        }
+        return queuesList;
+    }
+
+    private static List<QueueProperty> createPropertiesList() {
+        List<QueueProperty> propertiesList = new ArrayList<>();
+        QueuePropertyBuilder pb = new QueuePropertyBuilder();
+        pb.setProperty(QueueProperties.forValue(2));
+        RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
+        rateBuilder.setRate(5);
+        pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());
+        propertiesList.add(pb.build());
+        return propertiesList;
+    }
+
+}