BUG-4283: experimenter msg support - deserialization part
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / VendorMessageFactoryTest.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;
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.keys.MessageCodeKey;
21 import org.opendaylight.openflowjava.util.ByteBufUtils;
22
23 /**
24  * @author michal.polkorab
25  *
26  */
27 @RunWith(MockitoJUnitRunner.class)
28 public class VendorMessageFactoryTest {
29
30     @Mock DeserializerRegistry registry;
31     @Mock ExperimenterMessageFactory deserializer;
32
33     /**
34      * Tests {@link VendorMessageFactory#deserialize(ByteBuf)}
35      */
36     @Test
37     public void test() {
38         Mockito.when(registry.getDeserializer(Matchers.<MessageCodeKey>any())).thenReturn(deserializer);
39         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("01 02 03 04 FF FF FF FF 80 00 00 00");
40         VendorMessageFactory factory = new VendorMessageFactory();
41         factory.injectDeserializerRegistry(registry);
42         factory.deserialize(buffer);
43
44         Mockito.verify(deserializer, Mockito.times(1)).deserialize(buffer);
45         Assert.assertEquals("Buffer index modified", 4, buffer.readableBytes());
46     }
47 }