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.util.BufferHelper;
\r
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;
\r
27 * @author michal.polkorab
\r
28 * @author timotej.kubas
\r
30 public class OF13ExperimenterInputMessageFactoryTest {
\r
32 private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = 4;
\r
33 private SerializerRegistry registry;
\r
34 private OFSerializer<ExperimenterInput> expFactory;
\r
37 * Initializes serializer registry and stores correct factory in field
\r
40 public void startUp() {
\r
41 registry = new SerializerRegistryImpl();
\r
43 expFactory = registry.getSerializer(
\r
44 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, ExperimenterInput.class));
\r
48 * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO
\r
49 * @throws Exception
\r
52 public void test() throws Exception {
\r
53 ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
\r
54 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
\r
55 builder.setExperimenter(0x0001020304L);
\r
56 builder.setExpType(0x0001020304L);
\r
57 byte[] expData = new byte[] {0, 1, 2, 3, 4, 5, 6, 7};
\r
58 builder.setData(expData);
\r
59 ExperimenterInput message = builder.build();
\r
61 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
62 expFactory.serialize(message, out);
\r
64 BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, 24);
\r
65 Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());
\r
66 Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt());
\r
67 byte[] tmp = new byte[8];
\r
69 Assert.assertArrayEquals("Wrong data", expData, tmp);
\r