Add method to register listener for unknown msg
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10HelloMessageFactoryTest.java
1 /*
2  * Copyright (c) 2013 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.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
18 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
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.HelloMessage;
23
24 /**
25  * @author michal.polkorab
26  */
27 public class OF10HelloMessageFactoryTest {
28
29     private OFDeserializer<HelloMessage> helloFactory;
30
31     /**
32      * Initializes deserializer registry and lookups correct deserializer
33      */
34     @Before
35     public void startUp() {
36         DeserializerRegistry registry = new DeserializerRegistryImpl();
37         registry.init();
38         helloFactory = registry.getDeserializer(
39                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 0, HelloMessage.class));
40     }
41
42     /**
43      * Testing {@link OF10HelloMessageFactory} for correct translation into POJO
44      */
45     @Test
46     public void testWithoutElements() {
47         ByteBuf bb = BufferHelper.buildBuffer();
48         HelloMessage builtByFactory = BufferHelper.deserialize(
49                 helloFactory, bb);
50
51         BufferHelper.checkHeaderV10(builtByFactory);
52         Assert.assertNull("Wrong elements", builtByFactory.getElements());
53     }
54
55         /**
56      * Testing {@link OF10HelloMessageFactory} for correct translation into POJO
57      */
58     @Test
59     public void testWithElements() {
60         ByteBuf bb = BufferHelper.buildBuffer("00 01 " // type
61                                             + "00 0c " // length
62                                             + "00 00 00 11 " // bitmap 1
63                                             + "00 00 00 00 " // bitmap 2
64                                             + "00 00 00 00"  // padding
65                 );
66         HelloMessage builtByFactory = BufferHelper.deserialize(
67                 helloFactory, bb);
68
69         BufferHelper.checkHeaderV10(builtByFactory);
70         Assert.assertNull("Wrong elements", builtByFactory.getElements());
71     }
72
73 }