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 junit.framework.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
20 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
21 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInputBuilder;
29 * @author timotej.kubas
30 * @author michal.polkorab
32 public class TableModInputMessageFactoryTest {
33 private static final byte MESSAGE_TYPE = 17;
34 private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3;
35 private SerializerRegistry registry;
36 private OFSerializer<TableModInput> tableModFactory;
39 * Initializes serializer registry and stores correct factory in field
42 public void startUp() {
43 registry = new SerializerRegistryImpl();
45 tableModFactory = registry.getSerializer(
46 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, TableModInput.class));
50 * Testing of {@link TableModInputMessageFactory} for correct translation from POJO
54 public void testTableModInput() throws Exception {
55 TableModInputBuilder builder = new TableModInputBuilder();
56 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
57 builder.setTableId(new TableId(9L));
58 builder.setConfig(new TableConfig(true));
59 TableModInput message = builder.build();
61 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
62 tableModFactory.serialize(message, out);
64 BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16);
65 Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte());
66 out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE);
67 Assert.assertEquals("Wrong TableConfig", 8, out.readUnsignedInt());