2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
\r
11 import io.netty.buffer.ByteBuf;
\r
12 import io.netty.buffer.UnpooledByteBufAllocator;
\r
14 import org.junit.Assert;
\r
15 import org.junit.Before;
\r
16 import org.junit.Test;
\r
17 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
\r
18 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
\r
19 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
\r
20 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
\r
21 import org.opendaylight.openflowjava.protocol.impl.serialization.experimenters.OF10VendorInputMessageFactory;
\r
22 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
\r
23 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;
\r
28 * @author michal.polkorab
\r
31 public class OF10VendorInputMessageFactoryTest {
\r
33 private SerializerRegistry registry;
\r
34 private OFSerializer<ExperimenterInput> vendorFactory;
\r
37 * Initializes serializer registry and stores correct factory in field
\r
40 public void startUp() {
\r
41 registry = new SerializerRegistryImpl();
\r
43 vendorFactory = registry.getSerializer(
\r
44 new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, ExperimenterInput.class));
\r
49 * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO
\r
50 * @throws Exception
\r
53 public void test() throws Exception {
\r
54 ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
\r
55 BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
\r
56 builder.setExperimenter(0x0001020304L);
\r
57 builder.setData(new byte[] {0x01, 0x02, 0x03, 0x04});
\r
58 ExperimenterInput message = builder.build();
\r
60 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
61 vendorFactory.serialize(message, out);
\r
63 BufferHelper.checkHeaderV10(out, (byte) 4, 16);
\r
64 Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());
\r
65 byte[] data = new byte[4];
\r
66 out.readBytes(data);
\r
67 Assert.assertArrayEquals("Wrong data", message.getData(), data);
\r
68 Assert.assertTrue("Unread data", out.readableBytes() == 0);
\r