Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / DeserializationFactoryTest.java
1 /*
2  * Copyright (c) 2014 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;
10
11 import static org.junit.Assert.assertEquals;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.PooledByteBufAllocator;
14
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17
18 /**
19  * @author michal.polkorab
20  *
21  */
22 public class DeserializationFactoryTest {
23
24     /**
25      * Test deserializer lookup & deserialization
26      */
27     @Test
28     public void test() {
29         DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
30         registry.init();
31         DeserializationFactory factory = new DeserializationFactory();
32         factory.setRegistry(registry);
33         ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
34         buffer.writeByte(0);
35         buffer.writeShort(EncodeConstants.OFHEADER_SIZE);
36         buffer.writeInt(1234);
37         factory.deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
38         assertEquals("Deserialization failed", 0, buffer.readableBytes());
39     }
40
41     /**
42      * Test deserializer lookup & deserialization
43      */
44     @Test(expected=NullPointerException.class)
45     public void testNotExistingDeserializer() {
46         DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
47         registry.init();
48         DeserializationFactory factory = new DeserializationFactory();
49         factory.setRegistry(registry);
50         ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
51         buffer.writeByte(0);
52         buffer.writeShort(EncodeConstants.OFHEADER_SIZE);
53         buffer.writeInt(1234);
54         factory.deserialize(buffer, (short) 0);
55     }
56 }