added new serialization factories and their tests
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / RoleRequestInputMessageFactoryTest.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 import io.netty.buffer.UnpooledByteBufAllocator;\r
6 \r
7 import java.math.BigInteger;\r
8 \r
9 import junit.framework.Assert;\r
10 \r
11 import org.junit.Test;\r
12 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
13 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder;\r
17 \r
18 /**\r
19  * @author timotej.kubas\r
20  * @author michal.polkorab\r
21  */\r
22 public class RoleRequestInputMessageFactoryTest {\r
23     private static final byte MESSAGE_TYPE = 24;\r
24     private static final int MESSAGE_LENGTH = 24;\r
25     private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4;\r
26     \r
27     /**\r
28      * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO\r
29      * @throws Exception \r
30      */\r
31     @Test\r
32     public void testRoleRequestInputMessage() throws Exception {\r
33         RoleRequestInputBuilder builder = new RoleRequestInputBuilder();\r
34         BufferHelper.setupHeader(builder);\r
35         builder.setRole(ControllerRole.forValue(2));\r
36         byte[] generationId = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};\r
37         builder.setGenerationId(new BigInteger(generationId));\r
38         RoleRequestInput message = builder.build();\r
39         \r
40         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
41         RoleRequestInputMessageFactory factory = RoleRequestInputMessageFactory.getInstance();\r
42         factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);\r
43         \r
44         BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);\r
45         Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue());\r
46         out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE);\r
47         Assert.assertEquals("Wrong generation ID", message.getGenerationId().longValue(), out.readLong());\r
48     }\r
49 }\r