Update MRI upstreams for Phosphorus
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / GetaAsyncRequestMessageFactoryTest.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 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
19 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInputBuilder;
22
23 /**
24  * Unit tests for GetaAsyncRequestMessageFactory.
25  *
26  * @author timotej.kubas
27  * @author michal.polkorab
28  */
29 public class GetaAsyncRequestMessageFactoryTest {
30     private static final byte MESSAGE_TYPE = 26;
31     private static final int MESSAGE_LENGTH = 8;
32     private SerializerRegistry registry;
33     private OFSerializer<GetAsyncInput> getAsyncFactory;
34
35     /**
36      * Initializes serializer registry and stores correct factory in field.
37      */
38     @Before
39     public void startUp() {
40         registry = new SerializerRegistryImpl();
41         registry.init();
42         getAsyncFactory = registry.getSerializer(
43                 new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3, GetAsyncInput.class));
44     }
45
46     /**
47      * Testing of {@link GetAsyncRequestMessageFactory} for correct translation from POJO.
48      */
49     @Test
50     public void testGetAsyncReques() throws Exception {
51         GetAsyncInputBuilder builder = new GetAsyncInputBuilder();
52         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
53         GetAsyncInput message = builder.build();
54
55         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
56         getAsyncFactory.serialize(message, out);
57
58         BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
59     }
60 }