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