Bugfixed factories
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / PacketInMessageFactoryTest.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 \r
6 import org.junit.Assert;\r
7 import org.junit.Test;\r
8 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
9 import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;\r
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;\r
13 import org.slf4j.Logger;\r
14 import org.slf4j.LoggerFactory;\r
15 \r
16 /**\r
17  * @author timotej.kubas\r
18  *\r
19  */\r
20 public class PacketInMessageFactoryTest {\r
21 \r
22     private static final Logger LOGGER = LoggerFactory\r
23             .getLogger(PacketInMessageFactoryTest.class);\r
24     \r
25     /**\r
26      * Testing {@link PacketInMessageFactory} for correct translation into POJO\r
27      */\r
28     @Test\r
29     public void test(){\r
30         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 01 00 0C"\r
31                 + " 80 00 02 04 00 00 00 01 00 00 00 00 00 00 01 02 03 04");\r
32         PacketInMessage builtByFactory = BufferHelper.decodeV13(PacketInMessageFactory.getInstance(), bb); \r
33         \r
34         BufferHelper.checkHeaderV13(builtByFactory);\r
35         \r
36         Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());\r
37         Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue());\r
38         Assert.assertEquals("Wrong reason", PacketInReason.OFPRACTION, builtByFactory.getReason());\r
39         Assert.assertEquals("Wrong tableID", new TableId(4L), builtByFactory.getTableId());\r
40         Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());\r
41         Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());\r
42     }\r
43 }\r