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%2FFeaturesReplyMessageFactoryTest.java;h=ad4ccc596979047ae0df7d46e4fcf039735ae7bd;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=7f158c99c04d3ed6d8033e2f8530c9452e5f1fe4;hpb=4f4c0761fb641e1aed76a1e8c4ede5c968c86256;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java index 7f158c99..ad4ccc59 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java @@ -1,39 +1,75 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import io.netty.buffer.ByteBuf; - -import org.junit.Assert; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; - -/** - * @author michal.polkorab - * - */ -public class FeaturesReplyMessageFactoryTest { - - /** - * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO - */ - @Test - public void test() { - byte[] data = new byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x00, 0x01, 0x02, 0x03, 0x01, 0x01, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03 }; - ByteBuf bb = BufferHelper.buildBuffer(data); - GetFeaturesOutput builtByFactory = FeaturesReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED); - - Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED); - Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L); - Assert.assertTrue(builtByFactory.getTables() == 1); - Assert.assertTrue(builtByFactory.getAuxiliaryId() == 1); - Assert.assertEquals(66051L, builtByFactory.getBuffers().longValue()); - Assert.assertEquals(66051L, builtByFactory.getCapabilities().longValue()); - Assert.assertEquals(66051L, builtByFactory.getReserved().longValue()); - Assert.assertTrue(builtByFactory.getDatapathId().longValue() == 283686952306183L); - } - -} +/* + * 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 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.MessageCodeKey; +import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer; +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class FeaturesReplyMessageFactoryTest { + + private OFDeserializer featuresFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + featuresFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 6, GetFeaturesOutput.class)); + } + + /** + * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO + */ + @Test + public void test() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00" + + " 00 00 00 00 01 02 03"); + GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue()); + Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue()); + Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue()); + Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue()); + Assert.assertEquals("Wrong capabilities", new Capabilities(false, false, false, false, false, false, false), builtByFactory.getCapabilities()); + Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue()); + } + + /** + * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO + * (capabilities set) + */ + @Test + public void testCapabilities() { + ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00" + + " 00 01 6F 00 01 02 03"); + GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong capabilities", new Capabilities(true, true, true, true, true, true, true), builtByFactory.getCapabilities()); + } +} \ No newline at end of file