2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.PooledByteBufAllocator;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 * Unit tests for DeserializationFactory.
21 * @author michal.polkorab
23 public class DeserializationFactoryTest {
26 * Test deserializer lookup & deserialization.
30 DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
32 final DeserializationFactory factory = new DeserializationFactory(registry);
33 ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
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());
42 * Test deserializer lookup & deserialization.
44 @Test(expected = NullPointerException.class)
45 public void testNotExistingDeserializer() {
46 DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
48 final DeserializationFactory factory = new DeserializationFactory(registry);
49 ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
51 buffer.writeShort(EncodeConstants.OFHEADER_SIZE);
52 buffer.writeInt(1234);
53 factory.deserialize(buffer, (short) 0);