d456332b55eee37f35246b63c878a1c2870e2340
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / DeserializationFactoryTest.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.impl.deserialization;\r
10 \r
11 import static org.junit.Assert.assertEquals;\r
12 import io.netty.buffer.ByteBuf;\r
13 import io.netty.buffer.PooledByteBufAllocator;\r
14 \r
15 import org.junit.Test;\r
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
17 \r
18 /**\r
19  * @author michal.polkorab\r
20  *\r
21  */\r
22 public class DeserializationFactoryTest {\r
23 \r
24     /**\r
25      * Test deserializer lookup & deserialization\r
26      */\r
27     @Test\r
28     public void test() {\r
29         DeserializerRegistryImpl registry = new DeserializerRegistryImpl();\r
30         registry.init();\r
31         DeserializationFactory factory = new DeserializationFactory();\r
32         factory.setRegistry(registry);\r
33         ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
34         buffer.writeByte(0);\r
35         buffer.writeShort(EncodeConstants.OFHEADER_SIZE);\r
36         buffer.writeInt(1234);\r
37         factory.deserialize(buffer, EncodeConstants.OF13_VERSION_ID);\r
38         assertEquals("Deserialization failed", 0, buffer.readableBytes());\r
39     }\r
40 \r
41     /**\r
42      * Test deserializer lookup & deserialization\r
43      */\r
44     @Test(expected=NullPointerException.class)\r
45     public void testNotExistingDeserializer() {\r
46         DeserializerRegistryImpl registry = new DeserializerRegistryImpl();\r
47         registry.init();\r
48         DeserializationFactory factory = new DeserializationFactory();\r
49         factory.setRegistry(registry);\r
50         ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();\r
51         buffer.writeByte(0);\r
52         buffer.writeShort(EncodeConstants.OFHEADER_SIZE);\r
53         buffer.writeInt(1234);\r
54         factory.deserialize(buffer, (short) 0);\r
55     }\r
56 }