Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / PacketInMessageFactoryTest.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.util.ByteBufUtils;
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PacketInReason;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
26
27 /**
28  * @author timotej.kubas
29  *
30  */
31 public class PacketInMessageFactoryTest {
32
33     private OFDeserializer<PacketInMessage> packetInFactory;
34
35     /**
36      * Initializes deserializer registry and lookups correct deserializer
37      */
38     @Before
39     public void startUp() {
40         DeserializerRegistry registry = new DeserializerRegistryImpl();
41         registry.init();
42         packetInFactory = registry.getDeserializer(
43                 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 10, PacketInMessage.class));
44     }
45
46     /**
47      * Testing {@link PacketInMessageFactory} for correct translation into POJO
48      */
49     @Test
50     public void test(){
51         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 01 00 0C"
52                 + " 80 00 02 04 00 00 00 01 00 00 00 00 00 00 01 02 03 04");
53         PacketInMessage builtByFactory = BufferHelper.deserialize(packetInFactory, bb);
54
55         BufferHelper.checkHeaderV13(builtByFactory);
56
57         Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());
58         Assert.assertEquals("Wrong totalLength", 0x0102, builtByFactory.getTotalLen().intValue());
59         Assert.assertEquals("Wrong reason", PacketInReason.OFPRACTION, builtByFactory.getReason());
60         Assert.assertEquals("Wrong tableID", new TableId(4L), builtByFactory.getTableId());
61         Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());
62         Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());
63     }
64 }