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