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
6 import junit.framework.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.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder;
\r
16 * @author timotej.kubas
\r
19 public class PacketOutInputMessageFactoryTest {
\r
20 private static final byte MESSAGE_TYPE = 13;
\r
21 private static final int MESSAGE_LENGTH = 30;
\r
22 private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;
\r
25 * Testing of {@link PacketOutInputMessageFactory} for correct translation from POJO
\r
26 * @throws Exception
\r
29 public void testPacketOutInputMessage() throws Exception {
\r
30 PacketOutInputBuilder builder = new PacketOutInputBuilder();
\r
31 BufferHelper.setupHeader(builder);
\r
32 builder.setBufferId(256L);
\r
33 builder.setInPort(new PortNumber(256L));
\r
34 PacketOutInput message = builder.build();
\r
36 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
37 PacketOutInputMessageFactory factory = PacketOutInputMessageFactory.getInstance();
\r
38 factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
\r
40 BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
\r
41 Assert.assertEquals("Wrong BufferId", message.getBufferId().longValue(), out.readUnsignedInt());
\r
42 Assert.assertEquals("Wrong PortNumber", message.getInPort().getValue().longValue(), out.readUnsignedInt());
\r
43 // TODO make test for actions after its implementation in factory
\r
45 out.skipBytes(PADDING_IN_PACKET_OUT_MESSAGE);
\r