/*
- * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
import io.netty.buffer.ByteBuf;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterIdDeserializerKey;
+import org.opendaylight.openflowjava.util.ByteBufUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
/**
*/
public class ExperimenterMessageFactoryTest {
+ @Mock DeserializerRegistry registry;
+ @Mock OFDeserializer<ExperimenterMessage> deserializer;
+ @Mock ExperimenterMessage message;
+
+ /**
+ * Initializes mocks
+ */
+ @Before
+ public void startUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
/**
- * Testing {@link ExperimenterMessageFactory} for correct translation into POJO
+ * Test deserializer lookup correctness
*/
@Test
public void test() {
- ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04 01 02 03 04");
- ExperimenterMessage builtByFactory = BufferHelper.decodeV13(
- ExperimenterMessageFactory.getInstance(), bb);
+ when(registry.getDeserializer(any(ExperimenterIdDeserializerKey.class))).thenReturn(deserializer);
+ when(deserializer.deserialize(any(ByteBuf.class))).thenReturn(message);
- BufferHelper.checkHeaderV13(builtByFactory);
- Assert.assertEquals("Wrong experimenter", 0x01020304L, builtByFactory.getExperimenter().longValue());
- Assert.assertEquals("Wrong expType", 0x01020304L, builtByFactory.getExpType().longValue());
+ ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 02 03 00 00 00 10");
+ ExperimenterMessageFactory factory = new ExperimenterMessageFactory();
+ factory.injectDeserializerRegistry(registry);
+ ExperimenterMessage deserializedMessage = factory.deserialize(buffer);
+ Assert.assertEquals("Wrong return value", message, deserializedMessage);
+ Assert.assertEquals("ByteBuf index moved", 0, buffer.readerIndex());
}
-
-}
+}
\ No newline at end of file