Default experimenter bundle migrated to ConfigSubsystem
[openflowjava.git] / openflow-protocol-ext / src / test / java / org / opendaylight / openflowjava / protocol / ext / serialization / OF10VendorInputMessageFactoryTest.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.ext.serialization;\r
10 \r
11 import io.netty.buffer.ByteBuf;\r
12 import io.netty.buffer.UnpooledByteBufAllocator;\r
13 \r
14 import org.junit.Assert;\r
15 import org.junit.Test;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;\r
18 \r
19 /**\r
20  * @author michal.polkorab\r
21  *\r
22  */\r
23 public class OF10VendorInputMessageFactoryTest {\r
24 \r
25     /**\r
26      * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO\r
27      * @throws Exception \r
28      */\r
29     @Test\r
30     public void test() throws Exception {\r
31         ExperimenterInputBuilder builder = new ExperimenterInputBuilder();\r
32         builder.setVersion((short) 1);\r
33         builder.setXid(1024L);\r
34         builder.setExperimenter(0x0001020304L);\r
35         byte[] data = new byte[]{5, 6, 7, 8};\r
36         builder.setData(data);\r
37         ExperimenterInput message = builder.build();\r
38         \r
39         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
40         OF10VendorInputMessageFactory vendorFactory = new OF10VendorInputMessageFactory();\r
41         vendorFactory.serialize(message, out);\r
42         \r
43         Assert.assertEquals("Wrong version", 1, out.readUnsignedByte());\r
44         Assert.assertEquals("Wrong type", 4, out.readUnsignedByte());\r
45         Assert.assertEquals("Wrong length", 16, out.readUnsignedShort());\r
46         Assert.assertEquals("Wrong xid", 1024, out.readUnsignedInt());\r
47         Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());\r
48         byte[] expData = new byte[4];\r
49         out.readBytes(expData);\r
50         Assert.assertArrayEquals("Wrong data", data, expData);\r
51         Assert.assertTrue("Unexpected data", out.readableBytes() == 0);\r
52     }\r
53 \r
54     /**\r
55      * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO\r
56      * @throws Exception \r
57      */\r
58     @Test\r
59     public void testWithoutData() throws Exception {\r
60         ExperimenterInputBuilder builder = new ExperimenterInputBuilder();\r
61         builder.setVersion((short) 1);\r
62         builder.setXid(1024L);\r
63         builder.setExperimenter(0x0001020304L);\r
64         ExperimenterInput message = builder.build();\r
65         \r
66         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
67         OF10VendorInputMessageFactory vendorFactory = new OF10VendorInputMessageFactory();\r
68         vendorFactory.serialize(message, out);\r
69         \r
70         Assert.assertEquals("Wrong version", 1, out.readUnsignedByte());\r
71         Assert.assertEquals("Wrong type", 4, out.readUnsignedByte());\r
72         Assert.assertEquals("Wrong length", 12, out.readUnsignedShort());\r
73         Assert.assertEquals("Wrong xid", 1024, out.readUnsignedInt());\r
74         Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());\r
75         Assert.assertTrue("Unexpected data", out.readableBytes() == 0);\r
76     }\r
77 }