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.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
25 * Unit tests for FeaturesReplyMessageFactory.
27 * @author michal.polkorab
28 * @author timotej.kubas
30 public class FeaturesReplyMessageFactoryTest {
32 private OFDeserializer<GetFeaturesOutput> featuresFactory;
35 * Initializes deserializer registry and lookups correct deserializer.
38 public void startUp() {
39 DeserializerRegistry registry = new DeserializerRegistryImpl();
41 featuresFactory = registry.getDeserializer(
42 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 6, GetFeaturesOutput.class));
46 * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO.
50 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"
51 + " 00 00 00 00 01 02 03");
52 GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
54 BufferHelper.checkHeaderV13(builtByFactory);
55 Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());
56 Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue());
57 Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue());
58 Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue());
59 Assert.assertEquals("Wrong capabilities", new Capabilities(false, false, false, false, false, false, false),
60 builtByFactory.getCapabilities());
61 Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue());
65 * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO
69 public void testCapabilities() {
70 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"
71 + " 00 01 6F 00 01 02 03");
72 GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
74 BufferHelper.checkHeaderV13(builtByFactory);
75 Assert.assertEquals("Wrong capabilities", new Capabilities(true, true, true, true, true, true, true),
76 builtByFactory.getCapabilities());