-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.core;\r
-\r
-import io.netty.channel.ChannelHandlerContext;\r
-import io.netty.channel.ChannelPipeline;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.junit.runner.RunWith;\r
-import org.mockito.Matchers;\r
-import org.mockito.Mock;\r
-import org.mockito.Mockito;\r
-import org.mockito.runners.MockitoJUnitRunner;\r
-import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-\r
-/**\r
- * \r
- * @author michal.polkorab\r
- */\r
-@RunWith(MockitoJUnitRunner.class)\r
-public class OFVersionDetectorTest {\r
-\r
- @Mock\r
- ChannelHandlerContext channelHandlerContext;\r
-\r
- @Mock\r
- ChannelPipeline channelPipeline;\r
-\r
- private OFVersionDetector detector;\r
- private List<Object> list = new ArrayList<>();\r
-\r
- /**\r
- * Sets up test environment\r
- */\r
- @Before\r
- public void setUp() {\r
- Mockito.when(channelHandlerContext.pipeline()).thenReturn(\r
- channelPipeline);\r
- Mockito.when(channelPipeline.get(Matchers.anyString()))\r
- .thenReturn(null);\r
- list.clear();\r
- detector = new OFVersionDetector();\r
- }\r
-\r
- /**\r
- * Test of decode\r
- * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
- * }\r
- * \r
- * @throws Exception\r
- */\r
- @Test\r
- public void testDecode13ProtocolMessage() throws Exception {\r
- detector.decode(channelHandlerContext,\r
- ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),\r
- list);\r
-\r
- Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))\r
- .getMessageBuffer().readableBytes());\r
- verifyMockCalls(1);\r
- }\r
-\r
- /**\r
- * Test of decode\r
- * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
- * }\r
- * \r
- * @throws Exception\r
- */\r
- @Test\r
- public void testDecodeNotSupportedVersionProtocolMessage() throws Exception {\r
- detector.decode(channelHandlerContext,\r
- ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01"),\r
- list);\r
-\r
- Assert.assertEquals("List is not empty", 0, list.size());\r
- verifyMockCalls(0);\r
- }\r
-\r
- private void verifyMockCalls(int numberOfCalls) {\r
- if (numberOfCalls > 0) {\r
- Mockito.verify(channelPipeline, Mockito.times(numberOfCalls)).get(\r
- COMPONENT_NAMES.OF_DECODER.name());\r
- Mockito.verify(channelPipeline, Mockito.times(numberOfCalls))\r
- .addBefore(\r
- Matchers.eq(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER\r
- .name()),\r
- Matchers.eq(COMPONENT_NAMES.OF_DECODER.name()),\r
- Matchers.isA(OF13Decoder.class));\r
- } else {\r
- Mockito.verify(channelPipeline, Mockito.never()).get(\r
- COMPONENT_NAMES.OF_DECODER.name());\r
- Mockito.verify(channelPipeline, Mockito.never()).addBefore(\r
- Matchers.eq(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER\r
- .name()),\r
- Matchers.eq(COMPONENT_NAMES.OF_DECODER.name()),\r
- Matchers.isA(OF13Decoder.class));\r
- }\r
- }\r
+/*
+ * Copyright (c) 2013 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.core;
+
+import io.netty.channel.ChannelHandlerContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;
+
+/**
+ *
+ * @author michal.polkorab
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class OFVersionDetectorTest {
+
+ @Mock
+ ChannelHandlerContext channelHandlerContext;
+
+ private OFVersionDetector detector;
+ private List<Object> list = new ArrayList<>();
+
+ /**
+ * Sets up test environment
+ */
+ @Before
+ public void setUp() {
+ list.clear();
+ detector = new OFVersionDetector();
+ }
+
+ /**
+ * Test of decode
+ * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
+ * }
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testDecode13ProtocolMessage() throws Exception {
+ detector.decode(channelHandlerContext,
+ ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),
+ list);
+
+ Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0))
+ .getMessageBuffer().readableBytes());
+ }
+
+ /**
+ * Test of decode
+ * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
+ * }
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testDecodeNotSupportedVersionProtocolMessage() throws Exception {
+ detector.decode(channelHandlerContext,
+ ByteBufUtils.hexStringToByteBuf("02 00 00 08 00 00 00 01"),
+ list);
+
+ Assert.assertEquals("List is not empty", 0, list.size());
+ }
+
}
\ No newline at end of file