Remove trailing whitespace
[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 org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
20 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
21 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
22 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
23 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
24 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder;
28
29 /**
30  * @author timotej.kubas
31  * @author michal.polkorab
32  */
33 public class RoleRequestInputMessageFactoryTest {
34     private static final byte MESSAGE_TYPE = 24;
35     private static final int MESSAGE_LENGTH = 24;
36     private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4;
37     private SerializerRegistry registry;
38     private OFSerializer<RoleRequestInput> roleFactory;
39
40     /**
41      * Initializes serializer registry and stores correct factory in field
42      */
43     @Before
44     public void startUp() {
45         registry = new SerializerRegistryImpl();
46         registry.init();
47         roleFactory = registry.getSerializer(
48                 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, RoleRequestInput.class));
49     }
50
51     /**
52      * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO
53      * @throws Exception
54      */
55     @Test
56     public void testRoleRequestInputMessage() throws Exception {
57         RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
58         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
59         builder.setRole(ControllerRole.forValue(2));
60         byte[] generationId = new byte[]{(byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
61         builder.setGenerationId(new BigInteger(1, generationId));
62         RoleRequestInput message = builder.build();
63
64         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
65         roleFactory.serialize(message, out);
66
67         BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
68         Assert.assertEquals("Wrong role", message.getRole().getIntValue(), ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue());
69         out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE);
70         byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
71         out.readBytes(genId);
72         Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));
73     }
74 }