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
8 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
19 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInputBuilder;
24 * Unit tests for GetConfigInputMessageFactory.
26 * @author michal.polkorab
28 public class GetConfigInputMessageFactoryTest {
30 private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = 7;
31 private SerializerRegistry registry;
32 private OFSerializer<GetConfigInput> getConfigFactory;
35 * Initializes serializer registry and stores correct factory in field.
38 public void startUp() {
39 registry = new SerializerRegistryImpl();
41 getConfigFactory = registry.getSerializer(
42 new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3, GetConfigInput.class));
46 * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO.
49 public void testV13() throws Exception {
50 GetConfigInputBuilder gcib = new GetConfigInputBuilder();
51 BufferHelper.setupHeader(gcib, EncodeConstants.OF13_VERSION_ID);
52 GetConfigInput gci = gcib.build();
54 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
55 getConfigFactory.serialize(gci, out);
57 BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);
61 * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO.
64 public void testV10() throws Exception {
65 GetConfigInputBuilder gcib = new GetConfigInputBuilder();
66 BufferHelper.setupHeader(gcib, EncodeConstants.OF10_VERSION_ID);
67 GetConfigInput gci = gcib.build();
69 ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
70 getConfigFactory.serialize(gci, out);
72 BufferHelper.checkHeaderV10(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);