d547f064285c8509c0899b7f26c89a7df456b02b
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / TableModInputMessageFactoryTest.java
1 /*
2  * Copyright (c) 2013 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.factories;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
19 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInputBuilder;
26
27 /**
28  * @author timotej.kubas
29  * @author michal.polkorab
30  */
31 public class TableModInputMessageFactoryTest {
32     private static final byte MESSAGE_TYPE = 17;
33     private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3;
34     private SerializerRegistry registry;
35     private OFSerializer<TableModInput> tableModFactory;
36
37     /**
38      * Initializes serializer registry and stores correct factory in field
39      */
40     @Before
41     public void startUp() {
42         registry = new SerializerRegistryImpl();
43         registry.init();
44         tableModFactory = registry.getSerializer(
45                 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, TableModInput.class));
46     }
47
48     /**
49      * Testing of {@link TableModInputMessageFactory} for correct translation from POJO
50      * @throws Exception 
51      */
52     @Test
53     public void testTableModInput() throws Exception {
54         TableModInputBuilder builder = new TableModInputBuilder();
55         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
56         builder.setTableId(new TableId(9L));
57         builder.setConfig(new TableConfig(true));
58         TableModInput message = builder.build();
59         
60         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
61         tableModFactory.serialize(message, out);
62         
63         BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16);
64         Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte());
65         out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE);
66         Assert.assertEquals("Wrong TableConfig", 8, out.readUnsignedInt());
67     }
68     
69 }