Changed output directory for generated classes
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF13ExperimenterInputMessageFactoryTest.java
1 /*\r
2  * Copyright (c) 2013 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.impl.serialization.factories;\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.Before;\r
16 import org.junit.Test;\r
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;\r
19 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;\r
20 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;\r
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;\r
25 \r
26 /**\r
27  * @author michal.polkorab\r
28  * @author timotej.kubas\r
29  */\r
30 public class OF13ExperimenterInputMessageFactoryTest {\r
31 \r
32     private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = 4;\r
33     private SerializerRegistry registry;\r
34     private OFSerializer<ExperimenterInput> expFactory;\r
35 \r
36     /**\r
37      * Initializes serializer registry and stores correct factory in field\r
38      */\r
39     @Before\r
40     public void startUp() {\r
41         registry = new SerializerRegistryImpl();\r
42         registry.init();\r
43         expFactory = registry.getSerializer(\r
44                 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, ExperimenterInput.class));\r
45     }\r
46 \r
47     /**\r
48      * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO\r
49      * @throws Exception \r
50      */\r
51     @Test\r
52     public void test() throws Exception {\r
53         ExperimenterInputBuilder builder = new ExperimenterInputBuilder();\r
54         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);\r
55         builder.setExperimenter(0x0001020304L);\r
56         builder.setExpType(0x0001020304L);\r
57         byte[] expData = new byte[] {0, 1, 2, 3, 4, 5, 6, 7};\r
58         builder.setData(expData);\r
59         ExperimenterInput message = builder.build();\r
60         \r
61         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
62         expFactory.serialize(message, out);\r
63         \r
64         BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, 24);\r
65         Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());\r
66         Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt());\r
67         byte[] tmp = new byte[8];\r
68         out.readBytes(tmp);\r
69         Assert.assertArrayEquals("Wrong data", expData, tmp);\r
70     }\r
71     \r
72 }