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.serialization;
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.extensibility.SerializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;
21 * @author michal.polkorab
24 public class SerializationFactoryTest {
27 * Test serializer lookup & serialization
31 SerializerRegistry registry = new SerializerRegistryImpl();
33 SerializationFactory factory = new SerializationFactory();
34 factory.setSerializerTable(registry);
35 ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
36 HelloInputBuilder helloBuilder = new HelloInputBuilder();
37 helloBuilder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
38 helloBuilder.setXid(123456L);
39 helloBuilder.setElements(null);
40 factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, buffer, helloBuilder.build());
41 assertEquals("Serialization failed", EncodeConstants.OFHEADER_SIZE, buffer.readableBytes());
45 * Test serializer not found scenario
47 @Test(expected=IllegalStateException.class)
48 public void testNotExistingSerializer() {
49 SerializerRegistry registry = new SerializerRegistryImpl();
51 SerializationFactory factory = new SerializationFactory();
52 factory.setSerializerTable(registry);
53 ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
54 HelloInputBuilder helloBuilder = new HelloInputBuilder();
55 helloBuilder.setVersion((short) EncodeConstants.OF10_VERSION_ID);
56 helloBuilder.setXid(123456L);
57 helloBuilder.setElements(null);
58 factory.messageToBuffer((short) 0, buffer, helloBuilder.build());