fb8fc49038760c4916d12a6a9c03ffe138582ebf
[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 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.List;
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
20 import org.opendaylight.openflowjava.protocol.impl.util.DefaultDeserializerFactoryTest;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
22
23 /**
24  * Test for {@link org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory}.
25  * @author michal.polkorab
26  * @author timotej.kubas
27  */
28 public class EchoRequestMessageFactoryTest extends DefaultDeserializerFactoryTest<EchoRequestMessage> {
29
30     /**
31      * Initializes deserializer registry and lookups OF13 deserializer.
32      */
33     public EchoRequestMessageFactoryTest() {
34         super(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 2, EchoRequestMessage.class));
35     }
36
37     /**
38      * Testing {@link EchoRequestMessageFactory} for correct header version.
39      */
40     @Test
41     public void testVersions() {
42         List<Byte> versions = new ArrayList<>(Arrays.asList(
43                 EncodeConstants.OF10_VERSION_ID,
44                 EncodeConstants.OF13_VERSION_ID,
45                 EncodeConstants.OF14_VERSION_ID,
46                 EncodeConstants.OF15_VERSION_ID
47         ));
48         ByteBuf bb = BufferHelper.buildBuffer();
49         testHeaderVersions(versions, bb);
50     }
51
52     /**
53      * Testing {@link EchoRequestMessageFactory} for correct translation into POJO.
54      */
55     @Test
56     public void testWithEmptyDataField() {
57         byte[] data = new byte[]{};
58         ByteBuf bb = BufferHelper.buildBuffer();
59         EchoRequestMessage builtByFactory = BufferHelper.deserialize(factory, bb);
60         Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData());
61
62     }
63
64     /**
65      * Testing {@link EchoRequestMessageFactory} for correct translation into POJO.
66      */
67     @Test
68     public void testWithDataFieldSet() {
69         byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
70         ByteBuf bb = BufferHelper.buildBuffer(data);
71         EchoRequestMessage builtByFactory = BufferHelper.deserialize(factory, bb);
72         Assert.assertArrayEquals("Wrong data", data, builtByFactory.getData());
73     }
74 }