2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
\r
11 import io.netty.buffer.ByteBuf;
\r
13 import org.junit.Assert;
\r
14 import org.junit.Test;
\r
15 import org.junit.runner.RunWith;
\r
16 import org.mockito.Matchers;
\r
17 import org.mockito.Mock;
\r
18 import org.mockito.Mockito;
\r
19 import org.mockito.runners.MockitoJUnitRunner;
\r
20 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
\r
21 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
\r
22 import org.opendaylight.openflowjava.util.ByteBufUtils;
\r
25 * @author michal.polkorab
\r
28 @RunWith(MockitoJUnitRunner.class)
\r
29 public class VendorMessageFactoryTest {
\r
31 @Mock DeserializerRegistry registry;
\r
32 @Mock ExperimenterMessageFactory deserializer;
\r
35 * Tests {@link VendorMessageFactory#deserialize(ByteBuf)}
\r
38 public void test() {
\r
39 Mockito.when(registry.getDeserializer(Matchers.any(MessageCodeKey.class))).thenReturn(deserializer);
\r
40 ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("04 04 00 10 01 02 03 04 FF FF FF FF 80 00 00 00");
\r
41 VendorMessageFactory factory = new VendorMessageFactory();
\r
42 factory.injectDeserializerRegistry(registry);
\r
43 factory.deserialize(buffer);
\r
45 Mockito.verify(deserializer, Mockito.times(1)).deserialize(buffer);
\r
46 Assert.assertEquals("Buffer index modified", 16, buffer.readableBytes());
\r