Bug 1277 - Move ByteBuffUtils to separate bundle
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / GetQueueConfigInputMessageFactoryTest.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 import junit.framework.Assert;
14
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
20 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInputBuilder;
26
27 /**
28  * @author timotej.kubas
29  * @author michal.polkorab
30  */
31 public class GetQueueConfigInputMessageFactoryTest {
32     private static final byte GET_QUEUE_CONFIG_INPUT_MESSAGE_CODE_TYPE = 22;
33     private static final byte PADDING_IN_QUEUE_CONFIG_INPUT_MESSAGE = 4;
34     private SerializerRegistry registry;
35     private OFSerializer<GetQueueConfigInput> getQueueFactory;
36
37     /**
38      * Initializes serializer registry and stores correct factory in field
39      */
40     @Before
41     public void startUp() {
42         registry = new SerializerRegistryImpl();
43         registry.init();
44         getQueueFactory = registry.getSerializer(
45                 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetQueueConfigInput.class));
46     }
47
48     /**
49      * Testing of {@link GetQueueConfigInputMessageFactory} for correct translation from POJO
50      * @throws Exception 
51      */
52     @Test
53     public void testGetQueueConfigInputMessage() throws Exception {
54         GetQueueConfigInputBuilder builder = new GetQueueConfigInputBuilder();
55         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
56         builder.setPort(new PortNumber(0x00010203L));
57         GetQueueConfigInput message = builder.build();
58         
59         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
60         getQueueFactory.serialize(message, out);
61
62         BufferHelper.checkHeaderV13(out, GET_QUEUE_CONFIG_INPUT_MESSAGE_CODE_TYPE, 16);
63         Assert.assertEquals("Wrong port", 0x00010203, out.readUnsignedInt());
64         out.skipBytes(PADDING_IN_QUEUE_CONFIG_INPUT_MESSAGE);
65     }
66 }