Allow any hello mesage and extend hello support for v1.4, v1.5
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / util / DefaultDeserializerFactoryTest.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.util;
10
11 import io.netty.buffer.ByteBuf;
12 import java.util.List;
13 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
15 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
16 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
18 import org.opendaylight.yangtools.yang.binding.DataContainer;
19
20 /**
21  * Super class for common stuff of deserialization factories tests.
22  */
23 public abstract class DefaultDeserializerFactoryTest<T extends DataContainer> {
24
25     private DeserializerRegistry registry;
26     protected OFDeserializer<T> factory;
27     private MessageCodeKey messageCodeKey;
28
29     public DefaultDeserializerFactoryTest(final MessageCodeKey key) {
30         this.registry = new DeserializerRegistryImpl();
31         this.registry.init();
32         this.messageCodeKey = key;
33         this.factory = registry.getDeserializer(key);
34     }
35
36     /**
37      * Test correct version after deserialization for all supported OF versions.
38      * @param versions supported OF versions
39      * @param buffer byte buffer to deserialze
40      */
41     protected void testHeaderVersions(final List<Byte> versions, final ByteBuf buffer) {
42         for (short version : versions) {
43             ByteBuf bb = buffer.copy();
44             OFDeserializer<T> factory = registry.getDeserializer(
45                     new MessageCodeKey(version, messageCodeKey.getMsgType(), messageCodeKey.getClazz()));
46             T builtByFactory = BufferHelper.deserialize(factory, bb);
47             BufferHelper.checkHeader((OfHeader) builtByFactory, version);
48         }
49     }
50 }