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;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
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.protocol.rev130731.EchoInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;
26 * @author michal.polkorab
29 public class EchoInputMessageFactoryTest {
31 private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = 2;
32 private SerializerRegistry registry;
33 private OFSerializer<EchoInput> echoFactory;
36 * Initializes serializer registry and stores correct factory in field
39 public void startUp() {
40 registry = new SerializerRegistryImpl();
42 echoFactory = registry.getSerializer(
43 new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, EchoInput.class));
47 * Testing of {@link EchoInputMessageFactory} for correct translation from POJO
51 public void testV13() throws Exception {
52 EchoInputBuilder eib = new EchoInputBuilder();
53 BufferHelper.setupHeader(eib, EncodeConstants.OF13_VERSION_ID);
54 EchoInput ei = eib.build();
56 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
57 echoFactory.serialize(ei, out);
59 BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);
63 * Testing of {@link EchoInputMessageFactory} for correct translation from POJO
67 public void testV10() throws Exception {
68 EchoInputBuilder eib = new EchoInputBuilder();
69 BufferHelper.setupHeader(eib, EncodeConstants.OF10_VERSION_ID);
70 EchoInput ei = eib.build();
72 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
73 echoFactory.serialize(ei, out);
75 BufferHelper.checkHeaderV10(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);