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.Test;
16 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;
17 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
18 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInputBuilder;
25 * @author timotej.kubas
26 * @author michal.polkorab
28 public class TableModInputMessageFactoryTest {
29 private static final byte MESSAGE_TYPE = 17;
30 private static final byte PADDING_IN_TABLE_MOD_MESSAGE = 3;
33 * Testing of {@link TableModInputMessageFactory} for correct translation from POJO
37 public void testTableModInput() throws Exception {
38 TableModInputBuilder builder = new TableModInputBuilder();
39 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
40 builder.setTableId(new TableId(9L));
41 builder.setConfig(new TableConfig(true));
42 TableModInput message = builder.build();
44 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
45 TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance();
46 factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
48 BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16);
49 Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte());
50 out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE);
51 Assert.assertEquals("Wrong TableConfig", 8, out.readUnsignedInt());