5cc956ac4dd03f89eb8aa97c05dd8e472e3ebb8f
[openflowjava.git] / 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
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 org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
19 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInputBuilder;
24
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.OF13_VERSION_ID, GetAsyncInput.class));
44     }
45
46     /**
47      * Testing of {@link GetAsyncRequestMessageFactory} for correct translation from POJO
48      * @throws Exception 
49      */
50     @Test
51     public void testGetAsyncReques() throws Exception {
52         GetAsyncInputBuilder builder = new GetAsyncInputBuilder();
53         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
54         GetAsyncInput message = builder.build();
55         
56         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
57         getAsyncFactory.serialize(message, out);
58         
59         BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
60     }
61 }