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%2FEchoReplyMessageFactoryTest.java;h=801d47a6466894d337959d376aceac84d9fad3e7;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=5338ed03a0d3d7e493eab3e6252bd1302d19ff30;hpb=f7b135c5a0fab2841b445a567b27271081722984;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java index 5338ed03..801d47a6 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java @@ -1,44 +1,66 @@ -/* 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.EchoReplyMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput; - -/** - * @author michal.polkorab - * - */ -public class EchoReplyMessageFactoryTest { - - /** - * Testing {@link EchoReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithEmptyDataField() { - ByteBuf bb = BufferHelper.buildBuffer(); - EchoOutput builtByFactory = BufferHelper.decodeV13( - EchoReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - } - - /** - * Testing {@link EchoReplyMessageFactory} for correct translation into POJO - */ - @Test - public void testWithDataFieldSet() { - byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; - ByteBuf bb = BufferHelper.buildBuffer(data); - EchoOutput builtByFactory = BufferHelper.decodeV13( - EchoReplyMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertArrayEquals(builtByFactory.getData(), data); - } - -} +/* + * 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.protocol.rev130731.EchoOutput; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class EchoReplyMessageFactoryTest { + + private OFDeserializer echoFactory; + + /** + * Initializes deserializer registry and lookups correct deserializer + */ + @Before + public void startUp() { + DeserializerRegistry registry = new DeserializerRegistryImpl(); + registry.init(); + echoFactory = registry.getDeserializer( + new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 3, EchoOutput.class)); + } + + /** + * Testing {@link EchoReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithEmptyDataField() { + ByteBuf bb = BufferHelper.buildBuffer(); + EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb); + + BufferHelper.checkHeaderV13(builtByFactory); + } + + /** + * Testing {@link EchoReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testWithDataFieldSet() { + byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + ByteBuf bb = BufferHelper.buildBuffer(data); + EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + } +}