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;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.PooledByteBufAllocator;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 * @author michal.polkorab
22 public class DeserializationFactoryTest {
25 * Test deserializer lookup & deserialization
29 DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
31 DeserializationFactory factory = new DeserializationFactory();
32 factory.setRegistry(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 DeserializationFactory factory = new DeserializationFactory();
49 factory.setRegistry(registry);
50 ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
52 buffer.writeShort(EncodeConstants.OFHEADER_SIZE);
53 buffer.writeInt(1234);
54 factory.deserialize(buffer, (short) 0);