2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
14 import java.math.BigInteger;
16 import junit.framework.Assert;
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;
27 * @author timotej.kubas
28 * @author michal.polkorab
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;
36 * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO
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();
48 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
49 RoleRequestInputMessageFactory factory = RoleRequestInputMessageFactory.getInstance();
50 factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
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());