X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fdeserialization%2Ffactories%2FQueueGetConfigReplyMessageFactoryTest.java;h=cc2f4eabcf4f6df5edc87a21f336ca21043b6ac5;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=74c9a378a5787787296c36d3289a8206e3543bdc;hpb=1e439a51ce35e34f6203a64dba532aba9b5999af;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java index 74c9a378..cc2f4eab 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java @@ -1,89 +1,88 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -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.QueueProperty; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.Properties; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.PropertiesBuilder; -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 com.google.common.collect.ComparisonChain; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class QueueGetConfigReplyMessageFactoryTest { - - @Test - public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00"); - GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb); - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertTrue("Wrong port",66051L == builtByFactory.getPort().getValue()); - Assert.assertTrue("Wrong queues", true == compareLists(builtByFactory.getQueues(), createQueuesList())); - } - - public List createQueuesList(){ - final byte PADDING_IN_PACKET_QUEUE_HEADER = 6; - List queuesList = new ArrayList(); - QueuesBuilder qb = new QueuesBuilder(); - qb.setQueueId(new QueueId((long) 1)); - qb.setPort(new PortNumber((long) 1)); - qb.setProperties(createPropertiesList()); - queuesList.add(qb.build()); - - return queuesList; - } - - public List createPropertiesList(){ - final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4; - List propertiesList = new ArrayList(); - PropertiesBuilder pb = new PropertiesBuilder(); - pb.setProperty(QueueProperty.values()[2]); - propertiesList.add(pb.build()); - - return propertiesList; - } - - public boolean compareLists(List originalList, List testList){ - boolean decision = false; - int originalListLength = originalList.size(); - int testListLength = testList.size(); - - for(int i=0; i 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 {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test(){ + 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"); + GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(queueFactory, bb); + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue()); + Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList()); + } + + private static List createQueuesList(){ + List queuesList = new ArrayList<>(); + QueuesBuilder qb = new QueuesBuilder(); + qb.setQueueId(new QueueId(1L)); + qb.setPort(new PortNumber(3L)); + qb.setQueueProperty(createPropertiesList()); + queuesList.add(qb.build()); + + return queuesList; + } + + private static List createPropertiesList(){ + List 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; + } +}