Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / SerializationFactoryTest.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.serialization;
10
11 import static org.junit.Assert.assertEquals;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.PooledByteBufAllocator;
14
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;
19
20 /**
21  * @author michal.polkorab
22  *
23  */
24 public class SerializationFactoryTest {
25
26     /**
27      * Test serializer lookup & serialization
28      */
29     @Test
30     public void test() {
31         SerializerRegistry registry = new SerializerRegistryImpl();
32         registry.init();
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());
42     }
43
44     /**
45      * Test serializer not found scenario
46      */
47     @Test(expected=IllegalStateException.class)
48     public void testNotExistingSerializer() {
49         SerializerRegistry registry = new SerializerRegistryImpl();
50         registry.init();
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());
59     }
60 }