2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization;
\r
11 import static org.junit.Assert.assertEquals;
\r
12 import io.netty.buffer.ByteBuf;
\r
13 import io.netty.buffer.PooledByteBufAllocator;
\r
15 import org.junit.Test;
\r
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
19 * @author michal.polkorab
\r
22 public class DeserializationFactoryTest {
\r
25 * Test deserializer lookup & deserialization
\r
28 public void test() {
\r
29 DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
\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
42 * Test deserializer lookup & deserialization
\r
44 @Test(expected=NullPointerException.class)
\r
45 public void testNotExistingDeserializer() {
\r
46 DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
\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