1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
\r
4 import io.netty.buffer.ByteBuf;
\r
5 import io.netty.buffer.UnpooledByteBufAllocator;
\r
7 import org.junit.Assert;
\r
8 import org.junit.Test;
\r
9 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
\r
10 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
\r
11 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;
\r
16 * @author michal.polkorab
\r
17 * @author timotej.kubas
\r
19 public class ExperimenterInputMessageFactoryTest {
\r
21 private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = ExperimenterInputMessageFactory.MESSAGE_TYPE;
\r
24 * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO
\r
25 * @throws Exception
\r
28 public void test() throws Exception {
\r
29 ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
\r
30 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
\r
31 builder.setExperimenter(0x0001020304L);
\r
32 builder.setExpType(0x0001020304L);
\r
33 builder.setData(new byte[] {0x01, 0x02, 0x03});
\r
34 ExperimenterInput message = builder.build();
\r
36 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
37 ExperimenterInputMessageFactory factory = ExperimenterInputMessageFactory.getInstance();
\r
38 factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
\r
40 BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, factory.computeLength(message));
\r
41 Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());
\r
42 Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt());
\r
43 Assert.assertArrayEquals("Wrong data", message.getData(), readData(out));
\r
46 private static byte[] readData(ByteBuf input) {
\r
47 byte[] data = new byte[input.readableBytes()];
\r
48 input.readBytes(data);
\r