Copyright update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / RoleRequestInputMessageFactoryTest.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
13
14 import java.math.BigInteger;
15
16 import junit.framework.Assert;
17
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder;
25
26 /**
27  * @author timotej.kubas
28  * @author michal.polkorab
29  */
30 public class RoleRequestInputMessageFactoryTest {
31     private static final byte MESSAGE_TYPE = 24;
32     private static final int MESSAGE_LENGTH = 24;
33     private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4;
34     
35     /**
36      * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO
37      * @throws Exception 
38      */
39     @Test
40     public void testRoleRequestInputMessage() throws Exception {
41         RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
42         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
43         builder.setRole(ControllerRole.forValue(2));
44         byte[] generationId = new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
45         builder.setGenerationId(new BigInteger(generationId));
46         RoleRequestInput message = builder.build();
47         
48         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
49         RoleRequestInputMessageFactory factory = RoleRequestInputMessageFactory.getInstance();
50         factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
51         
52         BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
53         Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue());
54         out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE);
55         Assert.assertEquals("Wrong generation ID", message.getGenerationId().longValue(), out.readLong());
56     }
57 }