04fa4ddb4c30103b2df3ad04c5edba2177bcd285
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / EchoRequestMessageFactoryTest.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.util.BufferHelper;
21 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
23
24 /**
25  * @author michal.polkorab
26  * @author timotej.kubas
27  */
28 public class EchoRequestMessageFactoryTest {
29
30     private OFDeserializer<EchoRequestMessage> echoFactory;
31
32     /**
33      * Initializes deserializer registry and lookups correct deserializer
34      */
35     @Before
36     public void startUp() {
37         DeserializerRegistry registry = new DeserializerRegistryImpl();
38         registry.init();
39         echoFactory = registry.getDeserializer(
40                 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 2, EchoRequestMessage.class));
41     }
42
43     /**
44      * Testing {@link EchoRequestMessageFactory} for correct translation into POJO
45      */
46     @Test
47     public void testWithEmptyDataField() {
48         ByteBuf bb = BufferHelper.buildBuffer();
49         EchoRequestMessage builtByFactory = BufferHelper.deserialize(echoFactory, bb);
50
51         BufferHelper.checkHeaderV13(builtByFactory);
52     }
53     
54     /**
55      * Testing {@link EchoRequestMessageFactory} for correct translation into POJO
56      */
57     @Test
58     public void testWithDataFieldSet() {
59         byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
60         ByteBuf bb = BufferHelper.buildBuffer(data);
61         EchoRequestMessage builtByFactory = BufferHelper.deserialize(echoFactory, bb);
62
63         BufferHelper.checkHeaderV13(builtByFactory);
64         Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData());
65     }
66 }