Add method to register listener for unknown msg
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / multipart / MultipartReplyExperimenterTest.java
1 /*
2  * Copyright (c) 2014 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.multipart;
10
11 import io.netty.buffer.ByteBuf;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.Matchers;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
20 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
21 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
22 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;
23 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
26
27 /**
28  * @author michal.polkorab
29  *
30  */
31 @RunWith(MockitoJUnitRunner.class)
32 public class MultipartReplyExperimenterTest {
33
34     @Mock DeserializerRegistry registry;
35
36     private MultipartReplyMessageFactory factory = new MultipartReplyMessageFactory();
37     @Mock
38     private OFDeserializer<ExperimenterDataOfChoice> vendorDeserializer;
39
40     /**
41      * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO
42      */
43     @Test
44     public void testMultipartReplyExperimenter() {
45         Mockito.when(registry.getDeserializer(Matchers.<MessageCodeKey>any())).thenReturn(vendorDeserializer);
46         factory.injectDeserializerRegistry(registry);
47         ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "
48                                             + "00 00 00 01 00 00 00 02"); // expID, expType
49         MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
50
51         BufferHelper.checkHeaderV13(builtByFactory);
52         Assert.assertEquals("Wrong type", 65535, builtByFactory.getType().getIntValue());
53         Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
54
55         Mockito.verify(vendorDeserializer).deserialize(bb);
56     }
57 }