Extensibility support (deserialization part)
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10EchoReplyMessageFactoryTest.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.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10EchoReplyMessageFactory;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
24
25 /**
26  * @author michal.polkorab
27  * @author timotej.kubas
28  */
29 public class OF10EchoReplyMessageFactoryTest {
30
31     private OFDeserializer<EchoOutput> echoFactory;
32
33     /**
34      * Initializes deserializer registry and lookups correct deserializer
35      */
36     @Before
37     public void startUp() {
38         DeserializerRegistry registry = new DeserializerRegistryImpl();
39         registry.init();
40         echoFactory = registry.getDeserializer(
41                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 3, EchoOutput.class));
42     }
43
44     /**
45      * Testing {@link OF10EchoReplyMessageFactory} for correct translation into POJO
46      */
47     @Test
48     public void testWithEmptyDataFieldV10() {
49         ByteBuf bb = BufferHelper.buildBuffer();
50         EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb);
51
52         BufferHelper.checkHeaderV10(builtByFactory);
53     }
54     
55     /**
56      * Testing {@link OF10EchoReplyMessageFactory} for correct translation into POJO
57      */
58     @Test
59     public void testWithDataFieldSetV10() {
60         byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
61         ByteBuf bb = BufferHelper.buildBuffer(data);
62         EchoOutput builtByFactory = BufferHelper.deserialize(echoFactory, bb);
63         
64         BufferHelper.checkHeaderV10(builtByFactory);
65         Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData());
66     }
67 }