2 * Copyright (c) 2015 NetIDE Consortium 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
8 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import java.math.BigInteger;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
19 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
20 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
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.RoleRequestOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder;
27 * Unit tests for RoleReplyMessageFactory.
29 * @author giuseppex.petralia@intel.com
31 public class RoleReplyMessageFactoryTest {
32 private OFSerializer<RoleRequestOutput> factory;
33 private static final byte MESSAGE_TYPE = 25;
34 private static final byte PADDING = 4;
37 public void startUp() {
38 SerializerRegistry registry = new SerializerRegistryImpl();
41 .getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, RoleRequestOutput.class));
45 public void testSerialize() throws Exception {
46 RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
47 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
48 builder.setRole(ControllerRole.forValue(0));
49 builder.setGenerationId(BigInteger.valueOf(1L));
50 RoleRequestOutput message = builder.build();
52 ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
53 factory.serialize(message, serializedBuffer);
54 BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24);
55 Assert.assertEquals("Wrong role", message.getRole().getIntValue(),
56 ControllerRole.forValue((int) serializedBuffer.readUnsignedInt()).getIntValue());
57 serializedBuffer.skipBytes(PADDING);
58 byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
59 serializedBuffer.readBytes(genId);
60 Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));