X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=openflow-protocol-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fdeserialization%2Ffactories%2FEchoRequestMessageFactoryTest.java;h=8aff8b7553e3348f129fda7c71284f8e6f942653;hb=07de1ed897da9d7dc70c6d550f38c59339ed751e;hp=e136f5ad7a1d9c62d4ff5aeb98f6a79dce3a1a22;hpb=221d25d81c123970bcc912f0a6329a9aa45fb5f7;p=openflowjava.git diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java index e136f5ad..8aff8b75 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.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.EchoRequestMessageFactory; -import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; - -/** - * @author michal.polkorab - * - */ -public class EchoRequestMessageFactoryTest { - - /** - * Testing {@link EchoRequestMessageFactory} for correct translation into POJO - */ - @Test - public void testWithEmptyDataField() { - ByteBuf bb = BufferHelper.buildBuffer(); - EchoRequestMessage builtByFactory = BufferHelper.decodeV13( - EchoRequestMessageFactory.getInstance(), bb); - - BufferHelper.checkHeaderV13(builtByFactory); - } - - /** - * Testing {@link EchoRequestMessageFactory} 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); - EchoRequestMessage builtByFactory = BufferHelper.decodeV13( - EchoRequestMessageFactory.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.EchoRequestMessage; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class EchoRequestMessageFactoryTest { + + 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, 2, EchoRequestMessage.class)); + } + + /** + * Testing {@link EchoRequestMessageFactory} for correct translation into POJO + */ + @Test + public void testWithEmptyDataField() { + ByteBuf bb = BufferHelper.buildBuffer(); + EchoRequestMessage builtByFactory = BufferHelper.deserialize(echoFactory, bb); + + BufferHelper.checkHeaderV13(builtByFactory); + } + + /** + * Testing {@link EchoRequestMessageFactory} 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); + EchoRequestMessage builtByFactory = BufferHelper.deserialize(echoFactory, bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData()); + } +}