2 * Copyright (c) 2013 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.factories;
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.OFSerializer;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
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;
28 * @author timotej.kubas
29 * @author michal.polkorab
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;
38 * Initializes serializer registry and stores correct factory in field
41 public void startUp() {
42 registry = new SerializerRegistryImpl();
44 tableModFactory = registry.getSerializer(
45 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, TableModInput.class));
49 * Testing of {@link TableModInputMessageFactory} for correct translation from POJO
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();
60 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
61 tableModFactory.serialize(message, out);
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());