Fix checkstyle violations in openflow-protocol-impl - part 9
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10PacketInMessageFactoryTest.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.deserialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
19 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
20 import org.opendaylight.openflowjava.util.ByteBufUtils;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
23
24 /**
25  * Unit tests for OF10PacketInMessageFactory.
26  *
27  * @author michal.polkorab
28  */
29 public class OF10PacketInMessageFactoryTest {
30
31     private OFDeserializer<PacketInMessage> packetInFactory;
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         packetInFactory = registry.getDeserializer(
41                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 10, PacketInMessage.class));
42     }
43
44     /**
45      * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO.
46      */
47     @Test
48     public void test() {
49         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00 01 02 03 04");
50         PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb);
51
52         BufferHelper.checkHeaderV10(builtByFactory);
53         Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());
54         Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue());
55         Assert.assertEquals("Wrong inPort", 0x0102, builtByFactory.getInPort().intValue());
56         Assert.assertEquals("Wrong reason", PacketInReason.OFPRNOMATCH, builtByFactory.getReason());
57         Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());
58     }
59
60     /**
61      * Testing {@link OF10PacketInMessageFactory} for correct translation into POJO.
62      */
63     @Test
64     public void testWithNoAdditionalData() {
65         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 02 00 00");
66         PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb);
67
68         Assert.assertNull("Wrong data", builtByFactory.getData());
69     }
70 }