Update MRI upstreams for Phosphorus
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / GetConfigInputMessageFactoryTest.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.GetConfigInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInputBuilder;
22
23 /**
24  * Unit tests for GetConfigInputMessageFactory.
25  *
26  * @author michal.polkorab
27  */
28 public class GetConfigInputMessageFactoryTest {
29
30     private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = 7;
31     private SerializerRegistry registry;
32     private OFSerializer<GetConfigInput> getConfigFactory;
33
34     /**
35      * Initializes serializer registry and stores correct factory in field.
36      */
37     @Before
38     public void startUp() {
39         registry = new SerializerRegistryImpl();
40         registry.init();
41         getConfigFactory = registry.getSerializer(
42                 new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3, GetConfigInput.class));
43     }
44
45     /**
46      * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO.
47      */
48     @Test
49     public void testV13() throws Exception {
50         GetConfigInputBuilder gcib = new GetConfigInputBuilder();
51         BufferHelper.setupHeader(gcib, EncodeConstants.OF13_VERSION_ID);
52         GetConfigInput gci = gcib.build();
53
54         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
55         getConfigFactory.serialize(gci, out);
56
57         BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);
58     }
59
60     /**
61      * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO.
62      */
63     @Test
64     public void testV10() throws Exception {
65         GetConfigInputBuilder gcib = new GetConfigInputBuilder();
66         BufferHelper.setupHeader(gcib, EncodeConstants.OF10_VERSION_ID);
67         GetConfigInput gci = gcib.build();
68
69         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
70         getConfigFactory.serialize(gci, out);
71
72         BufferHelper.checkHeaderV10(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);
73     }
74 }