Fix checkstyle violations in openflow-protocol-impl - part 8 89/67389/2
authorTom Pantelis <tompantelis@gmail.com>
Sun, 21 Jan 2018 00:22:57 +0000 (19:22 -0500)
committerTom Pantelis <tompantelis@gmail.com>
Sat, 27 Jan 2018 02:30:25 +0000 (21:30 -0500)
Many violations - more to follow

Change-Id: Ie7aac9d6bc6b1372ff425b89d83cf44b617f7751
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
35 files changed:
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandlerTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/DummyDecoder.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/IdleHandlerTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDatagramPacketDecoderTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDatagramPacketEncoderTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDatagramPacketHandlerTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoderStatisticsTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoderTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoderStatisticsTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoderTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializerFactoryTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializerTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/SslContextFactoryTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/SslKeyStoreTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandlerTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/UdpConnectionMapTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/VersionMessageUdpWrapperTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ChannelOutboundQueue02Test.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ChannelOutboundQueueTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterFactoryImplTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImp02lTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImpl02Test.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionConfigurationImpl.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/MessageListenerWrapperTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueEntryTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ResponseExpectedRpcListenerTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/RpcResponseKeyTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SimpleRpcListenerTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImpl02Test.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/SwitchConnectionProviderImplTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/UdpHandlerTest.java
openflowjava/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/UdpMessageListenerWrapperTest.java

index 27aac9ce0ac00e6746f50c2ba77b032c8c8aac7b..c323569a923ab2282de67c3424dfcdc3ce4f88f2 100644 (file)
@@ -11,8 +11,8 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import io.netty.channel.ChannelHandlerContext;
 
+import io.netty.channel.ChannelHandlerContext;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -21,18 +21,20 @@ import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsum
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
+ * Unit tests for DelegatingInboundHandler.
+ *
  * @author jameshall
  */
 public class DelegatingInboundHandlerTest {
 
-    @Mock ChannelHandlerContext mockChHndlrCtx ;
-    @Mock MessageConsumer mockMsgConsumer ;
+    @Mock ChannelHandlerContext mockChHndlrCtx;
+    @Mock MessageConsumer mockMsgConsumer;
     @Mock DataObject mockDataObject ;
 
-    DelegatingInboundHandler dih ;
+    DelegatingInboundHandler dih;
 
     /**
-     * Sets up test environment
+     * Sets up test environment.
      */
     @Before
     public void setUp() {
@@ -40,33 +42,25 @@ public class DelegatingInboundHandlerTest {
         dih = new DelegatingInboundHandler(mockMsgConsumer) ;
     }
 
-    /**
-     *
-     */
     @Test
     public void testChannelReadSuccess()   {
         dih.channelRead(mockChHndlrCtx, mockDataObject) ;
 
         // Verify that the message buf was released...
-        verify( mockMsgConsumer, times(1)).consume(mockDataObject);
+        verify(mockMsgConsumer, times(1)).consume(mockDataObject);
     }
-    /**
-     *
-     */
+
     @Test
     public void testChannelInactive()   {
         dih.channelInactive(mockChHndlrCtx);
 
-        verify( mockMsgConsumer, times(1)).consume(any(DataObject.class));
+        verify(mockMsgConsumer, times(1)).consume(any(DataObject.class));
     }
 
-    /**
-     * ChannelUnregistered
-     */
     @Test
     public void testChannelUnregistered()   {
         dih.channelUnregistered(mockChHndlrCtx);
 
-        verify( mockMsgConsumer, times(1)).consume(any(DataObject.class));
+        verify(mockMsgConsumer, times(1)).consume(any(DataObject.class));
     }
 }
index 55ebf43d1f79e6fd9766404d4b766d36e6a8019e..f62880066e1462b257c44af0473d6158dbd1c68b 100644 (file)
@@ -11,20 +11,18 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.ByteToMessageDecoder;
-
 import java.util.List;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * @author michal.polkorab
+ * Dummy DelegatingInboundHandlerTest.
  *
+ * @author michal.polkorab
  */
 public class DummyDecoder extends ByteToMessageDecoder {
 
-    private static final Logger LOG = LoggerFactory
-            .getLogger(DummyDecoder.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DummyDecoder.class);
 
     @Override
     protected void decode(ChannelHandlerContext ctx, ByteBuf in,
@@ -32,5 +30,4 @@ public class DummyDecoder extends ByteToMessageDecoder {
         LOG.debug("decoding");
         ctx.fireChannelReadComplete();
     }
-
 }
index b3462e98eafe16cb6d3cd1676f8ff9130f934da2..83cf468643da1d91a142b58fa4a9b1fa6c537273 100644 (file)
@@ -11,11 +11,9 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import io.netty.channel.ChannelHandlerContext;
 
+import io.netty.channel.ChannelHandlerContext;
 import java.util.concurrent.TimeUnit;
-
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -23,6 +21,7 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
 
 /**
+ * Unit tests for IdleHandler.
  *
  * @author jameshall
  */
@@ -33,78 +32,60 @@ public class IdleHandlerTest {
     IdleHandler idleHandler ;
 
     /**
-     * Sets up test environment
-     *
+     * Sets up test environment.
      */
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        idleHandler = new IdleHandler(60L, TimeUnit.MINUTES ) ;
+        idleHandler = new IdleHandler(60L, TimeUnit.MINUTES);
     }
 
     /**
-     * Test message passing on channel read
+     * Test message passing on channel read.
      */
     @Test
-    public void testChannelRead() {
-        try {
-            idleHandler.channelRead(mockChHndlrCtx, new Object() );
-        } catch (Exception e) {
-            Assert.fail();
-        }
+    public void testChannelRead() throws Exception {
+        idleHandler.channelRead(mockChHndlrCtx, new Object());
 
         // Verify that a read was fired for the next handler ...
         verify(mockChHndlrCtx, times(1)).fireChannelRead(any(SwitchIdleEvent.class)) ;
     }
 
     /**
-     * Test channel read timeout
+     * Test channel read timeout.
      */
     @Test
-    public void testReadTimedOut() {
-        try {
-            idleHandler.readTimedOut( mockChHndlrCtx );
-        } catch (Exception e) {
-            Assert.fail();
-        }
+    public void testReadTimedOut() throws Exception {
+        idleHandler.readTimedOut(mockChHndlrCtx);
 
         // Verify a read was fired for the next handler to process ...
         verify(mockChHndlrCtx, times(1)).fireChannelRead(any(SwitchIdleEvent.class)) ;
     }
 
     /**
-     * Test only one timeout notification
+     * Test only one timeout notification.
      */
     @Test
-    public void testReadTimedOutNoOpNotFirst() {
-        try {
-            idleHandler.readTimedOut(mockChHndlrCtx);
-            idleHandler.readTimedOut(mockChHndlrCtx);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+    public void testReadTimedOutNoOpNotFirst() throws Exception {
+        idleHandler.readTimedOut(mockChHndlrCtx);
+        idleHandler.readTimedOut(mockChHndlrCtx);
 
         // Verify that only one notification was sent to the next handler ...
         verify(mockChHndlrCtx, times(1)).fireChannelRead(any(Object.class)) ;
     }
 
     /**
-     * Test two timeout notifications
+     * Test two timeout notifications.
      */
     @Test
-    public void testReadTimedOutTwice() {
-        try {
-            idleHandler.readTimedOut(mockChHndlrCtx);
-            verify(mockChHndlrCtx, times(1)).fireChannelRead(any(Object.class)) ;
-
-            idleHandler.channelRead(mockChHndlrCtx, new String() );
-            verify(mockChHndlrCtx, times(2)).fireChannelRead(any(Object.class)) ;
-
-            idleHandler.readTimedOut(mockChHndlrCtx);
-            verify(mockChHndlrCtx, times(3)).fireChannelRead(any(Object.class)) ;
-        } catch (Exception e) {
-            Assert.fail();
-        }
-    }
+    public void testReadTimedOutTwice() throws Exception {
+        idleHandler.readTimedOut(mockChHndlrCtx);
+        verify(mockChHndlrCtx, times(1)).fireChannelRead(any(Object.class));
+
+        idleHandler.channelRead(mockChHndlrCtx, new String());
+        verify(mockChHndlrCtx, times(2)).fireChannelRead(any(Object.class));
 
+        idleHandler.readTimedOut(mockChHndlrCtx);
+        verify(mockChHndlrCtx, times(3)).fireChannelRead(any(Object.class));
+    }
 }
index 683a89abf8ffb90952c4044cdb12ee5104be5de2..f5ddbd8b53029d22923cec3104e1b5e63216a813 100644 (file)
@@ -9,12 +9,10 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
-
 import java.net.InetSocketAddress;
-
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -23,8 +21,9 @@ import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;
 
 /**
- * @author madamjak
+ * Unit tests for OFDatagramPacketDecoder.
  *
+ * @author madamjak
  */
 public class OFDatagramPacketDecoderTest {
     @Mock DeserializationFactory deserializationFactory;
@@ -34,20 +33,18 @@ public class OFDatagramPacketDecoderTest {
     private VersionMessageUdpWrapper msgWrapper;
 
     @Before
-    public void startUp(){
+    public void startUp() {
         MockitoAnnotations.initMocks(this);
     }
 
     @Test
-    public void test() {
+    public void test() throws Exception {
         OFDatagramPacketDecoder decoder = new OFDatagramPacketDecoder();
         decoder.setDeserializationFactory(deserializationFactory);
-        msgWrapper = new VersionMessageUdpWrapper(EncodeConstants.OF13_VERSION_ID, messageBufferMock, new InetSocketAddress("10.0.0.1", 6653));
-        try {
-            decoder.channelRead0(ctx, msgWrapper);
-        } catch (Exception e) {
-            Assert.fail("Exception occured");
-        }
+        msgWrapper = new VersionMessageUdpWrapper(EncodeConstants.OF13_VERSION_ID, messageBufferMock,
+                new InetSocketAddress("10.0.0.1", 6653));
+
+        decoder.channelRead0(ctx, msgWrapper);
         verify(messageBufferMock, times(1)).release();
     }
 }
index 7ab8bfcc758f75700a97237d662c88e7886548e4..7a477103c1ecb1820ae31743b111e1c804401615 100644 (file)
@@ -10,14 +10,13 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
-
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -29,8 +28,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;
 
 /**
- * @author michal.polkorab
+ * Unit tests for OFDatagramPacketEncoder.
  *
+ * @author michal.polkorab
  */
 public class OFDatagramPacketEncoderTest {
 
@@ -39,11 +39,12 @@ public class OFDatagramPacketEncoderTest {
     @Mock SerializationFactory factory;
 
     private UdpMessageListenerWrapper wrapper;
-    private InetSocketAddress address = new InetSocketAddress("10.0.0.1", 6653);
+    private final InetSocketAddress address = new InetSocketAddress("10.0.0.1", 6653);
     private List<Object> out;
 
     /**
-     * Initializes mocks and other objects
+     * Initializes mocks and other objects.
+     *
      * @param version openflow protocol wire version
      */
     public void startUp(Short version) {
@@ -56,24 +57,21 @@ public class OFDatagramPacketEncoderTest {
     }
 
     /**
-     * Tests encoding
+     * Tests encoding.
      */
     @Test
-    public void testCorrectEncode() {
+    public void testCorrectEncode() throws Exception {
         startUp((short) EncodeConstants.OF13_VERSION_ID);
         OFDatagramPacketEncoder encoder = new OFDatagramPacketEncoder();
         encoder.setSerializationFactory(factory);
-        try {
-            encoder.encode(ctx, wrapper, out);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+        encoder.encode(ctx, wrapper, out);
     }
 
     /**
-     * Tests encoding
+     * Tests encoding.
      */
     @Test
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void testIncorrectEncode() {
         startUp(null);
         OFDatagramPacketEncoder encoder = new OFDatagramPacketEncoder();
@@ -85,4 +83,4 @@ public class OFDatagramPacketEncoderTest {
             Assert.assertEquals("List should be empty", 0, out.size());
         }
     }
-}
\ No newline at end of file
+}
index a3f5befc84443aa4d5576994957f742a49c0d264..30ba96a2c3c79977f48a72131ce416228fd7d06f 100644 (file)
@@ -8,15 +8,14 @@
 package org.opendaylight.openflowjava.protocol.impl.core;
 
 import static org.mockito.Mockito.when;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.socket.DatagramPacket;
-
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -28,8 +27,9 @@ import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsum
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 
 /**
- * @author madamjak
+ * Unit tests for OFDatagramPacketHandler.
  *
+ * @author madamjak
  */
 public class OFDatagramPacketHandlerTest {
     @Mock ChannelHandlerContext ctxMock;
@@ -38,16 +38,16 @@ public class OFDatagramPacketHandlerTest {
     @Mock Channel channelMock;
 
     @Before
-    public void startUp(){
+    public void startUp() {
         MockitoAnnotations.initMocks(this);
         when(ctxMock.channel()).thenReturn(channelMock);
     }
 
     /**
-     * Test {@link OFDatagramPacketHandler}
+     * Test {@link OFDatagramPacketHandler}.
      */
     @Test
-    public void test(){
+    public void test() throws Exception {
         OFDatagramPacketHandler handler = new OFDatagramPacketHandler(switchConnHandler);
         byte version = EncodeConstants.OF13_VERSION_ID;
         ByteBuf messageBuffer = ByteBufUtils.hexStringToByteBuf("04 02 00 08 01 02 03 04");
@@ -56,15 +56,14 @@ public class OFDatagramPacketHandlerTest {
         DatagramPacket datagramPacket = new DatagramPacket(messageBuffer, recipientISA, senderISA);
         UdpConnectionMap.addConnection(datagramPacket.sender(), consumerMock);
         List<Object> outList = new ArrayList<>();
-        try {
-            handler.decode(ctxMock, datagramPacket, outList);
-        } catch (Exception e) {
-            Assert.fail("Wrong - Unexcepted exception occurred");
-        }
+
+        handler.decode(ctxMock, datagramPacket, outList);
+
         VersionMessageUdpWrapper versionUdpWrapper = (VersionMessageUdpWrapper) outList.get(0);
         Assert.assertEquals("Wrong - incorrect version has been decoded",version, versionUdpWrapper.getVersion());
         Assert.assertEquals("Wrong - sender addresses are different", senderISA, versionUdpWrapper.getAddress());
         messageBuffer.readerIndex(1);
-        Assert.assertEquals("Wrong - undecoded part of input ByteBuff is differnt to output",0, messageBuffer.compareTo(versionUdpWrapper.getMessageBuffer()));
+        Assert.assertEquals("Wrong - undecoded part of input ByteBuff is differnt to output", 0,
+                messageBuffer.compareTo(versionUdpWrapper.getMessageBuffer()));
     }
 }
index 409e475d4603b6e07673e32dfa757c137fb14057..9a454f0d8b53286860e4e174f7d8525cd7bd7de3 100644 (file)
@@ -10,12 +10,11 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyShort;
 import static org.mockito.Mockito.when;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -30,10 +29,9 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
  * Test to count decoder events (counters US_DECODE_SUCCESS, US_DECODE_FAIL and
- * US_RECEIVED_IN_OFJAVA have to be enabled)
+ * US_RECEIVED_IN_OFJAVA have to be enabled).
  *
  * @author madamjak
- *
  */
 public class OFDecoderStatisticsTest {
 
@@ -48,8 +46,7 @@ public class OFDecoderStatisticsTest {
     private StatisticsCounters statCounters;
 
     /**
-     * Sets up test environment Start counting and reset counters before each
-     * test
+     * Sets up test environment Start counting and reset counters before each test.
      */
     @Before
     public void setUp() {
@@ -62,7 +59,7 @@ public class OFDecoderStatisticsTest {
     }
 
     /**
-     * Stop counting after each test
+     * Stop counting after each test.
      */
     @After
     public void tierDown() {
@@ -70,10 +67,10 @@ public class OFDecoderStatisticsTest {
     }
 
     /**
-     * Test decode success counter
+     * Test decode success counter.
      */
     @Test
-    public void testDecodeSuccesfullCounter() {
+    public void testDecodeSuccesfullCounter() throws Exception {
         if (!statCounters.isCounterEnabled(CounterEventTypes.US_DECODE_SUCCESS)) {
             Assert.fail("Counter " + CounterEventTypes.US_DECODE_SUCCESS + " is not enable");
         }
@@ -86,15 +83,13 @@ public class OFDecoderStatisticsTest {
         }
         int count = 4;
         when(mockDeserializationFactory.deserialize(any(ByteBuf.class),anyShort())).thenReturn(mockDataObject);
-        try {
-            for (int i = 0; i < count; i++) {
-                writeObj = ByteBufUtils.hexStringToByteBuf("16 03 01 00");
-                inMsg = new VersionMessageWrapper((short) 8, writeObj);
-                ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
-            }
-        } catch (Exception e) {
-            Assert.fail();
+
+        for (int i = 0; i < count; i++) {
+            writeObj = ByteBufUtils.hexStringToByteBuf("16 03 01 00");
+            inMsg = new VersionMessageWrapper((short) 8, writeObj);
+            ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
         }
+
         Assert.assertEquals("Wrong - bad counter value for OFEncoder encode succesfully ",
                 count,statCounters.getCounter(CounterEventTypes.US_DECODE_SUCCESS).getCounterValue());
         Assert.assertEquals(
@@ -105,10 +100,10 @@ public class OFDecoderStatisticsTest {
     }
 
     /**
-     * Test fail decode counter
+     * Test fail decode counter.
      */
     @Test
-    public void testDecodeFailCounter() {
+    public void testDecodeFailCounter() throws Exception {
         if (!statCounters.isCounterEnabled(CounterEventTypes.US_DECODE_SUCCESS)) {
             Assert.fail("Counter " + CounterEventTypes.US_DECODE_SUCCESS + " is not enable");
         }
@@ -119,16 +114,15 @@ public class OFDecoderStatisticsTest {
             Assert.fail("Counter " + CounterEventTypes.US_RECEIVED_IN_OFJAVA + " is not enable");
         }
         int count = 2;
-        when( mockDeserializationFactory.deserialize(any(ByteBuf.class),anyShort())).thenThrow(new IllegalArgumentException());
-        try {
-            for (int i = 0; i < count; i++) {
-                writeObj = ByteBufUtils.hexStringToByteBuf("16 03 01 00");
-                inMsg = new VersionMessageWrapper((short) 8, writeObj);
-                ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
-            }
-        } catch (Exception e) {
-            Assert.fail();
+        when(mockDeserializationFactory.deserialize(any(ByteBuf.class),anyShort()))
+            .thenThrow(new IllegalArgumentException());
+
+        for (int i = 0; i < count; i++) {
+            writeObj = ByteBufUtils.hexStringToByteBuf("16 03 01 00");
+            inMsg = new VersionMessageWrapper((short) 8, writeObj);
+            ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
         }
+
         Assert.assertEquals(
                 "Wrong - bad counter value for OFEncoder encode succesfully ",
                 count, statCounters.getCounter(CounterEventTypes.US_DECODE_FAIL).getCounterValue());
index 917f9b920f30543a5405529c30c34210d2b0a7ec..ab0b2272816a2f069baebc41b1021e22b32bc5b4 100644 (file)
@@ -12,13 +12,11 @@ import static org.junit.Assert.assertEquals;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyShort;
 import static org.mockito.Mockito.when;
+
 import io.netty.buffer.ByteBuf;
 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.mockito.Mock;
@@ -28,6 +26,7 @@ import org.opendaylight.openflowjava.util.ByteBufUtils;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
+ * Unit tests for OFDecoder.
  *
  * @author jameshall
  */
@@ -43,71 +42,49 @@ public class OFDecoderTest {
     private List<Object> outList;
 
     /**
-     * Sets up test environment
-     *
+     * Sets up test environment.
      */
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
-        ofDecoder = new OFDecoder() ;
-        ofDecoder.setDeserializationFactory( mockDeserializationFactory ) ;
+        ofDecoder = new OFDecoder();
+        ofDecoder.setDeserializationFactory(mockDeserializationFactory);
         writeObj = ByteBufUtils.hexStringToByteBuf("16 03 01 00");
-        inMsg = new VersionMessageWrapper( (short)8, writeObj );
+        inMsg = new VersionMessageWrapper((short) 8, writeObj);
         outList = new ArrayList<>();
     }
 
-    /**
-     *
-     */
     @Test
-    public void testDecode() {
-        when(mockDeserializationFactory.deserialize( any(ByteBuf.class), anyShort() )).thenReturn(mockDataObject);
-        try {
-            ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+    public void testDecode() throws Exception {
+        when(mockDeserializationFactory.deserialize(any(ByteBuf.class), anyShort())).thenReturn(mockDataObject);
+
+        ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
 
         // Verify that the message buf was released...
-        assertEquals( mockDataObject, outList.get(0) ) ;
-        assertEquals( 0, writeObj.refCnt() ) ;
+        assertEquals(mockDataObject, outList.get(0));
+        assertEquals(0, writeObj.refCnt());
     }
 
-    /**
-     *
-     */
     @Test
-    public void testDecodeDeserializeException() {
-        when(mockDeserializationFactory.deserialize( any(ByteBuf.class), anyShort() ))
-        .thenThrow(new IllegalArgumentException()) ;
+    public void testDecodeDeserializeException() throws Exception {
+        when(mockDeserializationFactory.deserialize(any(ByteBuf.class), anyShort()))
+                .thenThrow(new IllegalArgumentException());
 
-        try {
-            ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+        ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
 
         // Verify that the message buf was released...
-        assertEquals( 0, outList.size() ) ;
-        assertEquals( 0, writeObj.refCnt() ) ;
+        assertEquals(0, outList.size());
+        assertEquals(0, writeObj.refCnt());
     }
 
-    /**
-     *
-     */
     @Test
-    public void testDecodeDeserializeNull() {
-        when(mockDeserializationFactory.deserialize( any(ByteBuf.class), anyShort() ))
-        .thenReturn(null) ;
+    public void testDecodeDeserializeNull() throws Exception {
+        when(mockDeserializationFactory.deserialize(any(ByteBuf.class), anyShort())).thenReturn(null);
 
-        try {
-            ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+        ofDecoder.decode(mockChHndlrCtx, inMsg, outList);
 
         // Verify that the message buf was released...
-        assertEquals( 0, outList.size() ) ;
-        assertEquals( 0, writeObj.refCnt() ) ;
+        assertEquals(0, outList.size());
+        assertEquals(0, writeObj.refCnt());
     }
 }
index cfafe99450c95ca297375ba6cf6add566c958b32..d13274b5c7fb9e50690eb8341ab45d2d79e0a9fe 100644 (file)
@@ -11,11 +11,11 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyShort;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.when;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
-
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -32,9 +32,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
- * Test counters for encoding (at least DS_ENCODE_SUCCESS, DS_ENCODE_FAIL and DS_FLOW_MODS_SENT counters have to be enabled)
- * @author madamjak
+ * Test counters for encoding (at least DS_ENCODE_SUCCESS, DS_ENCODE_FAIL and DS_FLOW_MODS_SENT counters have to
+ * be enabled).
  *
+ * @author madamjak
  */
 public class OFEncoderStatisticsTest {
 
@@ -51,10 +52,10 @@ public class OFEncoderStatisticsTest {
     private OFEncoder ofEncoder;
 
     /**
-     * Initialize tests, start and reset counters before each test
+     * Initialize tests, start and reset counters before each test.
      */
     @Before
-    public void initTlest(){
+    public void initTlest() {
         MockitoAnnotations.initMocks(this);
         ofEncoder = new OFEncoder() ;
         ofEncoder.setSerializationFactory(mockSerializationFactory) ;
@@ -63,80 +64,80 @@ public class OFEncoderStatisticsTest {
     }
 
     /**
-     * Stop counting after each test
+     * Stop counting after each test.
      */
     @After
-    public void tierDown(){
+    public void tierDown() {
         statCounters.stopCounting();
     }
 
     /**
-     * Test counting of success encode (counter DS_ENCODE_SUCCESS has to be enabled)
+     * Test counting of success encode (counter DS_ENCODE_SUCCESS has to be enabled).
      */
     @Test
-    public void testEncodeSuccessCounter() {
+    public void testEncodeSuccessCounter() throws Exception {
         CounterEventTypes cet = CounterEventTypes.DS_ENCODE_SUCCESS;
-        if(! statCounters.isCounterEnabled(cet)){
+        if (!statCounters.isCounterEnabled(cet)) {
             Assert.fail("Counter " + cet + " is not enabled.");
         }
-        int count = 4;
+
         when(mockOut.readableBytes()).thenReturn(1);
         when(wrapper.getMsg()).thenReturn(mockMsg);
         when(wrapper.getMsg().getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID);
-        try {
-            for(int i = 0; i< count; i++){
-                ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
-            }
-        } catch (Exception e) {
-            Assert.fail();
+
+        int count = 4;
+        for (int i = 0; i < count; i++) {
+            ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
         }
-        Assert.assertEquals("Wrong - bad counter value for OFEncoder encode succesfully ", count, statCounters.getCounter(cet).getCounterValue());
+
+        Assert.assertEquals("Wrong - bad counter value for OFEncoder encode succesfully ", count,
+                statCounters.getCounter(cet).getCounterValue());
     }
 
     /**
-     * Test counting of flow-mod sent (counter DS_FLOW_MODS_SENT has to be enabled)
+     * Test counting of flow-mod sent (counter DS_FLOW_MODS_SENT has to be enabled).
      */
     @Test
-    public void testFlowModSentCounter() {
+    public void testFlowModSentCounter() throws Exception {
         CounterEventTypes cet = CounterEventTypes.DS_FLOW_MODS_SENT;
-        if(! statCounters.isCounterEnabled(cet)){
+        if (!statCounters.isCounterEnabled(cet)) {
             Assert.fail("Counter " + cet + " is not enabled.");
         }
-        int count = 4;
         when(mockOut.readableBytes()).thenReturn(1);
         when(wrapper.getMsg()).thenReturn(mockFlowModInput);
         when(wrapper.getMsg().getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID);
-        try {
-            for(int i = 0; i< count; i++){
-                ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
-            }
-        } catch (Exception e) {
-            Assert.fail();
+
+        int count = 4;
+        for (int i = 0; i < count; i++) {
+            ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
         }
-        Assert.assertEquals("Wrong - bad counter value for OFEncoder flow-mod sent", count, statCounters.getCounter(cet).getCounterValue());
+
+        Assert.assertEquals("Wrong - bad counter value for OFEncoder flow-mod sent", count,
+                statCounters.getCounter(cet).getCounterValue());
     }
+
     /**
-     * Test counting of encode fail (counter DS_ENCODE_FAIL has to be enabled)
+     * Test counting of encode fail (counter DS_ENCODE_FAIL has to be enabled).
      */
-
     @Test
-    public void testEncodeEncodeFailCounter() {
+    public void testEncodeEncodeFailCounter() throws Exception {
         CounterEventTypes cet = CounterEventTypes.DS_ENCODE_FAIL;
-        if(! statCounters.isCounterEnabled(cet)){
+        if (!statCounters.isCounterEnabled(cet)) {
             Assert.fail("Counter " + cet + " is not enabled.");
         }
-        int count = 2;
+
         when(wrapper.getMsg()).thenReturn(mockMsg);
         when(wrapper.getListener()).thenReturn(listener);
         when(wrapper.getMsg().getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID);
-        doThrow(new IllegalArgumentException()).when(mockSerializationFactory).messageToBuffer(anyShort(),any(ByteBuf.class), any(DataObject.class));
-        try {
-            for(int i = 0; i< count; i++){
-                ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
-            }
-        } catch (Exception e) {
-            Assert.fail();
+        doThrow(new IllegalArgumentException()).when(mockSerializationFactory).messageToBuffer(anyShort(),
+                any(ByteBuf.class), any(DataObject.class));
+
+        int count = 2;
+        for (int i = 0; i < count; i++) {
+            ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
         }
-        Assert.assertEquals("Wrong - bad counter value for OFEncoder fail encode", count, statCounters.getCounter(cet).getCounterValue());
+
+        Assert.assertEquals("Wrong - bad counter value for OFEncoder fail encode", count,
+                statCounters.getCounter(cet).getCounterValue());
     }
 }
index e05fbd98766bdbc73934b23a4990cfdf268a65b3..fc6477ea2a042debcb43e6e3ae206feaab2e57c2 100644 (file)
@@ -14,12 +14,11 @@ import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
-
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -31,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
+ * Unit tests for OFEncoder.
  *
  * @author jameshall
  */
@@ -47,69 +47,61 @@ public class OFEncoderTest {
     OFEncoder ofEncoder = new OFEncoder() ;
 
     /**
-     * Sets up test environment
+     * Sets up test environment.
      */
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         ofEncoder = new OFEncoder() ;
-        ofEncoder.setSerializationFactory( mockSerializationFactory ) ;
+        ofEncoder.setSerializationFactory(mockSerializationFactory);
     }
 
     /**
-     * Test successful write (no clear)
+     * Test successful write (no clear).
      */
     @Test
-    public void testEncodeSuccess() {
+    public void testEncodeSuccess() throws Exception {
         when(mockOut.readableBytes()).thenReturn(1);
         when(wrapper.getMsg()).thenReturn(mockMsg);
         when(wrapper.getMsg().getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID);
-        try {
-            ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+
+        ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
 
         // Verify that the channel was flushed after the ByteBuf was retained.
         verify(mockOut, times(0)).clear();
     }
 
     /**
-     * Test Bytebuf clearing after serialization failure
+     * Test Bytebuf clearing after serialization failure.
      */
     @Test
-    public void testEncodeSerializationException() {
+    public void testEncodeSerializationException() throws Exception {
         when(wrapper.getMsg()).thenReturn(mockMsg);
         when(wrapper.getListener()).thenReturn(listener);
         when(wrapper.getMsg().getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID);
-        doThrow(new IllegalArgumentException()).when(mockSerializationFactory).messageToBuffer(anyShort(),any(ByteBuf.class), any(DataObject.class));
-        try {
-            ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+        doThrow(new IllegalArgumentException()).when(mockSerializationFactory).messageToBuffer(anyShort(),
+                any(ByteBuf.class), any(DataObject.class));
+
+        ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
 
         // Verify that the output message buf was cleared...
         verify(mockOut, times(1)).clear();
     }
 
     /**
-     * Test no action on empty bytebuf
+     * Test no action on empty bytebuf.
      */
     @Test
-    public void testEncodeSerializesNoBytes() {
+    public void testEncodeSerializesNoBytes() throws Exception {
         when(mockOut.readableBytes()).thenReturn(0);
         when(wrapper.getMsg()).thenReturn(mockMsg);
         when(wrapper.getMsg().getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID);
-        try {
-            ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+
+        ofEncoder.encode(mockChHndlrCtx, wrapper, mockOut);
 
         // Verify that the output message buf was cleared...
         verify(mockOut, times(0)).clear();
         verify(mockChHndlrCtx, times(0)).writeAndFlush(mockOut);
         verify(mockOut, times(0)).retain();
     }
-}
\ No newline at end of file
+}
index 41d692c820820f0c49c22c6ece46d558174c8d8b..b21f1a16c3f490387d4721f626235dbd168ad83c 100644 (file)
@@ -9,12 +9,11 @@
 package org.opendaylight.openflowjava.protocol.impl.core;
 
 import static org.junit.Assert.assertEquals;
+
 import io.netty.buffer.ByteBuf;
 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;
@@ -26,7 +25,7 @@ import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFac
 import org.opendaylight.openflowjava.util.ByteBufUtils;
 
 /**
- * Testing class of {@link OFFrameDecoder}
+ * Testing class of {@link OFFrameDecoder}.
  *
  * @author michal.polkorab
  */
@@ -39,10 +38,10 @@ public class OFFrameDecoderTest {
     @Mock
     ConnectionFacade connectionFacade;
     private OFFrameDecoder decoder;
-    private List<Object> list = new ArrayList<>();
+    private final List<Object> list = new ArrayList<>();
 
     /**
-     * Sets up tests
+     * Sets up tests.
      */
     @Before
     public void setUp() {
@@ -54,34 +53,26 @@ public class OFFrameDecoderTest {
 
     /**
      * Test of decoding
-     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
+     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}.
      */
     @Test
-    public void testDecode8BMessage() {
-        try {
-            decoder.decode(channelHandlerContext,
+    public void testDecode8BMessage() throws Exception {
+        decoder.decode(channelHandlerContext,
                     ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),
                     list);
-        } catch (Exception e) {
-            Assert.fail();
-        }
-
         assertEquals(8, ((ByteBuf) list.get(0)).readableBytes());
     }
 
     /**
      * Test of decoding
-     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
+     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}.
      */
     @Test
-    public void testDecode16BMessage() {
+    public void testDecode16BMessage() throws Exception {
         ByteBuf byteBuffer = ByteBufUtils
                 .hexStringToByteBuf("04 00 00 10 00 00 00 00 00 00 00 00 00 00 00 42");
-        try {
-            decoder.decode(channelHandlerContext, byteBuffer, list);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+
+        decoder.decode(channelHandlerContext, byteBuffer, list);
 
         assertEquals(16, ((ByteBuf) list.get(0)).readableBytes());
         assertEquals(0, byteBuffer.readableBytes());
@@ -89,16 +80,13 @@ public class OFFrameDecoderTest {
 
     /**
      * Test of decoding
-     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
+     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}.
      */
     @Test
-    public void testDecode5BIncompleteMessage() {
+    public void testDecode5BIncompleteMessage() throws Exception {
         ByteBuf byteBuffer = ByteBufUtils.hexStringToByteBuf("04 00 00 08 00");
-        try {
-            decoder.decode(channelHandlerContext, byteBuffer, list);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+
+        decoder.decode(channelHandlerContext, byteBuffer, list);
 
         Assert.assertEquals("List is not empty", 0, list.size());
         assertEquals(5, byteBuffer.readableBytes());
@@ -106,17 +94,14 @@ public class OFFrameDecoderTest {
 
     /**
      * Test of decoding
-     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
+     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}.
      */
     @Test
-    public void testDecode16BIncompleteMessage() {
+    public void testDecode16BIncompleteMessage() throws Exception {
         ByteBuf byteBuffer = ByteBufUtils
                 .hexStringToByteBuf("04 00 00 11 00 00 00 00 00 00 00 00 00 00 00 42");
-        try {
-            decoder.decode(channelHandlerContext, byteBuffer, list);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+
+        decoder.decode(channelHandlerContext, byteBuffer, list);
 
         Assert.assertEquals("List is not empty", 0, list.size());
         assertEquals(16, byteBuffer.readableBytes());
@@ -124,17 +109,14 @@ public class OFFrameDecoderTest {
 
     /**
      * Test of decoding
-     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
+     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}.
      */
     @Test
-    public void testDecodeCompleteAndPartialMessage() {
+    public void testDecodeCompleteAndPartialMessage() throws Exception {
         ByteBuf byteBuffer = ByteBufUtils
                 .hexStringToByteBuf("04 00 00 08 00 00 00 01 04 00 00 08 00");
-        try {
-            decoder.decode(channelHandlerContext, byteBuffer, list);
-        } catch (Exception e) {
-            Assert.fail();
-        }
+
+        decoder.decode(channelHandlerContext, byteBuffer, list);
 
         Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes());
         Assert.assertEquals(1, list.size());
@@ -149,18 +131,15 @@ public class OFFrameDecoderTest {
 
     /**
      * Test of decoding
-     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}
+     * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}.
      */
     @Test
-    public void testDecode8BMessageWithTls() {
+    public void testDecode8BMessageWithTls() throws Exception {
         decoder = new OFFrameDecoder(connectionFacade, true);
-        try {
-            decoder.decode(channelHandlerContext,
+
+        decoder.decode(channelHandlerContext,
                     ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"),
                     list);
-        } catch (Exception e) {
-            Assert.fail();
-        }
 
         assertEquals(8, ((ByteBuf) list.get(0)).readableBytes());
     }
index 486972401b3d23d2356bc5897d0b1e5856a02f47..cc856beb5aca7d4d22b7e48462ecaa16ebfd0fc0 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 
 import static org.junit.Assert.assertNotNull;
 
+import com.google.common.collect.Lists;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -22,9 +23,8 @@ import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFa
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
 
-import com.google.common.collect.Lists;
-
 /**
+ * Unit tests for ChannelInitializerFactory.
  *
  * @author jameshall
  */
@@ -38,7 +38,7 @@ public class PublishingChannelInitializerFactoryTest {
     @Mock DeserializationFactory deserializationFactory ;
 
     /**
-     * Sets up test environment
+     * Sets up test environment.
      */
     @Before
     public void setUp() {
@@ -55,11 +55,11 @@ public class PublishingChannelInitializerFactoryTest {
     }
 
     /**
-     * Test {@link TcpChannelInitializer} creation
+     * Test {@link TcpChannelInitializer} creation.
      */
     @Test
     public void testCreatePublishingChannelInitializer() {
         TcpChannelInitializer initializer = factory.createPublishingChannelInitializer() ;
-        assertNotNull( initializer );
+        assertNotNull(initializer);
     }
-}
\ No newline at end of file
+}
index 140c247d3751ddcf16891d35c2ccb884dbc96a5d..e1cfa0c006bc1f4e64c0b33ac5eaa0b11563126c 100644 (file)
@@ -41,6 +41,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.K
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
 
 /**
+ * Unit tests for ChannelInitializer.
  *
  * @author james.hall
  */
@@ -63,26 +64,24 @@ public class PublishingChannelInitializerTest {
     TcpChannelInitializer pubChInitializer  ;
 
     /**
-     * Sets up test environment
-     * @throws Exception
+     * Sets up test environment.
      */
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-        pubChInitializer= new TcpChannelInitializer(mockChGrp, mockConnAdaptorFactory) ;
+        pubChInitializer = new TcpChannelInitializer(mockChGrp, mockConnAdaptorFactory) ;
         pubChInitializer.setSerializationFactory(mockSerializationFactory);
         pubChInitializer.setDeserializationFactory(mockDeserializationFactory);
         pubChInitializer.setSwitchIdleTimeout(1) ;
         pubChInitializer.getConnectionIterator() ;
         pubChInitializer.setUseBarrier(true);
 
-        when( mockChGrp.size()).thenReturn(1) ;
-        pubChInitializer.setSwitchConnectionHandler( mockSwConnHandler ) ;
+        when(mockChGrp.size()).thenReturn(1);
+        pubChInitializer.setSwitchConnectionHandler(mockSwConnHandler);
 
-        inetSockAddr = new InetSocketAddress(InetAddress.getLocalHost(), 8675 ) ;
+        inetSockAddr = new InetSocketAddress(InetAddress.getLocalHost(), 8675);
 
-        when(mockConnAdaptorFactory.createConnectionFacade(mockSocketCh, null, true))
-        .thenReturn(mockConnFacade);
+        when(mockConnAdaptorFactory.createConnectionFacade(mockSocketCh, null, true)).thenReturn(mockConnFacade);
         when(mockSocketCh.remoteAddress()).thenReturn(inetSockAddr) ;
         when(mockSocketCh.localAddress()).thenReturn(inetSockAddr) ;
         when(mockSocketCh.remoteAddress()).thenReturn(inetSockAddr) ;
@@ -96,7 +95,7 @@ public class PublishingChannelInitializerTest {
 
 
     /**
-     * Test channel initialization with encryption config set
+     * Test channel initialization with encryption config set.
      */
     @Test
     public void testinitChannelEncryptionSet()  {
@@ -108,7 +107,7 @@ public class PublishingChannelInitializerTest {
     }
 
     /**
-     * Test channel initialization with null encryption config
+     * Test channel initialization with null encryption config.
      */
     @Test
     public void testinitChannelEncryptionSetNullTls()  {
@@ -120,7 +119,7 @@ public class PublishingChannelInitializerTest {
     }
 
     /**
-     * Test channel initialization without setting the encryption
+     * Test channel initialization without setting the encryption.
      */
     @Test
     public void testinitChannelEncryptionNotSet()  {
@@ -131,8 +130,7 @@ public class PublishingChannelInitializerTest {
     }
 
     /**
-     * Test disconnect on new connection rejected
-     * @throws UnknownHostException
+     * Test disconnect on new connection rejected.
      */
     @Test
     public void testinitChannelNoEncryptionAcceptFails() throws UnknownHostException  {
@@ -140,31 +138,33 @@ public class PublishingChannelInitializerTest {
         pubChInitializer.initChannel(mockSocketCh) ;
 
         verify(mockSocketCh, times(1)).disconnect();
-        verify(mockChPipeline, times(0))
-        .addLast( any(String.class), any(ChannelHandler.class) ) ;
+        verify(mockChPipeline, times(0)).addLast(any(String.class), any(ChannelHandler.class));
     }
 
     /**
-     * Test channel close on exception during initialization
+     * Test channel close on exception during initialization.
      */
     @Test
     public void testExceptionThrown() {
         doThrow(new IllegalArgumentException()).when(mockSocketCh).pipeline() ;
         pubChInitializer.initChannel(mockSocketCh);
 
-        verify( mockSocketCh, times(1)).close() ;
+        verify(mockSocketCh, times(1)).close();
     }
 
     /**
-     * All paths should install these six handlers:
+     * All paths should install these six handlers.
      */
     private void verifyCommonHandlers() {
         verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.IDLE_HANDLER.name()),any(IdleHandler.class)) ;
         verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.OF_DECODER.name()),any(OFDecoder.class)) ;
         verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.OF_ENCODER.name()),any(OFEncoder.class)) ;
-        verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.OF_FRAME_DECODER.name()),any(OFFrameDecoder.class)) ;
-        verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.OF_VERSION_DETECTOR.name()),any(OFVersionDetector.class)) ;
-        verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.DELEGATING_INBOUND_HANDLER.name()),any(DelegatingInboundHandler.class));
+        verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.OF_FRAME_DECODER.name()),
+                any(OFFrameDecoder.class));
+        verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.OF_VERSION_DETECTOR.name()),
+                any(OFVersionDetector.class));
+        verify(mockChPipeline, times(1)).addLast(eq(PipelineHandlers.DELEGATING_INBOUND_HANDLER.name()),
+                any(DelegatingInboundHandler.class));
         assertEquals(1, pubChInitializer.size()) ;
     }
 }
index 862e0ca56e6f27c29e35370b79ddcc4675fbbab4..0057f0a3c4a1f30e4018cf085a9025102ba5a622 100644 (file)
@@ -10,8 +10,8 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 
 import static org.junit.Assert.assertNotNull;
 
+import com.google.common.collect.Lists;
 import javax.net.ssl.SSLContext;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.MockitoAnnotations;
@@ -20,9 +20,8 @@ import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImp
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
 
-import com.google.common.collect.Lists;
-
 /**
+ * Unit tests for SslContextFactory.
  *
  * @author jameshall
  */
@@ -32,7 +31,7 @@ public class SslContextFactoryTest {
     TlsConfiguration tlsConfiguration ;
 
     /**
-     * Sets up test environment
+     * Sets up test environment.
      */
     @Before
     public void setUp() {
@@ -43,14 +42,10 @@ public class SslContextFactoryTest {
         sslContextFactory = new SslContextFactory(tlsConfiguration);
     }
 
-    /**
-     * @throws Exception
-     */
     @Test
     public void testGetServerContext() throws Exception {
         SSLContext context  = sslContextFactory.getServerContext() ;
 
-        assertNotNull( context );
+        assertNotNull(context);
     }
-
 }
index c2a13df8a1b546f7adf242a7f3684d08aa7b351a..e864bad4ac6f435dc320532054cf76fcc254b429 100644 (file)
@@ -11,20 +11,20 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 import static org.junit.Assert.assertNotNull;
 
 import java.io.InputStream;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
 
 /**
+ * Unit tests for SslKeyStore.
  *
  * @author jameshall
  */
 public class SslKeyStoreTest {
 
     /**
-     * Sets up test environment
+     * Sets up test environment.
      */
     @Before
     public void setUp() {
@@ -32,24 +32,22 @@ public class SslKeyStoreTest {
     }
 
     /**
-     * Test keystore file access - via classpath
-     * @throws Exception
+     * Test keystore file access - via classpath.
      */
     @Test
     public void testAsInputStream() throws Exception {
         InputStream inputStream = SslKeyStore.asInputStream("/key.bin", PathType.CLASSPATH);
-        assertNotNull( inputStream );
+        assertNotNull(inputStream);
         inputStream.close();
     }
 
     /**
-     * Test keystore file access - via relative path
-     * @throws Exception
+     * Test keystore file access - via relative path.
      */
     @Test
     public void testAsInputStream2() throws Exception {
         InputStream inputStream = SslKeyStore.asInputStream("src/test/resources/key.bin", PathType.PATH);
-        assertNotNull( inputStream );
+        assertNotNull(inputStream);
         inputStream.close();
     }
 }
index 6faad908f01cf60d798a67d6e263376561a0d583..3e284dd55181bb33db7fbd662640f82fffdf2164 100644 (file)
@@ -9,17 +9,17 @@
 package org.opendaylight.openflowjava.protocol.impl.core;
 
 import static org.junit.Assert.assertEquals;
-import io.netty.channel.ChannelHandlerContext;
+import static org.junit.Assert.fail;
 
+import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.unix.Errors;
 import java.io.IOException;
 import java.net.BindException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.util.concurrent.ExecutionException;
-
-import io.netty.channel.unix.Errors;
-import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -27,15 +27,14 @@ import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHan
 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;
 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory;
 
-import com.google.common.util.concurrent.ListenableFuture;
-
 /**
+ * Unit tests for TcpHandler.
  *
  * @author jameshall
  */
 public class TcpHandlerTest {
 
-    private InetAddress serverAddress = InetAddress.getLoopbackAddress() ;
+    private final InetAddress serverAddress = InetAddress.getLoopbackAddress() ;
     @Mock ChannelHandlerContext mockChHndlrCtx ;
     @Mock TcpChannelInitializer mockChannelInitializer;
     @Mock SwitchConnectionHandler mockSwitchConnHndler ;
@@ -45,17 +44,14 @@ public class TcpHandlerTest {
     TcpHandler tcpHandler ;
 
     /**
-     * Initialize mocks
+     * Initialize mocks.
      */
     public TcpHandlerTest() {
         MockitoAnnotations.initMocks(this);
     }
 
     /**
-     * Test run with null address set
-     * @throws IOException
-     * @throws InterruptedException
-     * @throws ExecutionException
+     * Test run with null address set.
      */
     @Test
     public void testRunWithNullAddress() throws IOException, InterruptedException, ExecutionException  {
@@ -69,10 +65,7 @@ public class TcpHandlerTest {
     }
 
     /**
-     * Test run with null address set on Epoll native transport
-     * @throws IOException
-     * @throws InterruptedException
-     * @throws ExecutionException
+     * Test run with null address set on Epoll native transport.
      */
     @Test
     public void testRunWithNullAddressOnEpoll() throws IOException, InterruptedException, ExecutionException  {
@@ -87,10 +80,7 @@ public class TcpHandlerTest {
     }
 
     /**
-     * Test run with address set
-     * @throws IOException
-     * @throws InterruptedException
-     * @throws ExecutionException
+     * Test run with address set.
      */
     @Test
     public void testRunWithAddress() throws IOException, InterruptedException, ExecutionException  {
@@ -104,10 +94,7 @@ public class TcpHandlerTest {
     }
 
     /**
-     * Test run with address set on Epoll native transport
-     * @throws IOException
-     * @throws InterruptedException
-     * @throws ExecutionException
+     * Test run with address set on Epoll native transport.
      */
     @Test
     public void testRunWithAddressOnEpoll() throws IOException, InterruptedException, ExecutionException  {
@@ -122,10 +109,7 @@ public class TcpHandlerTest {
     }
 
     /**
-     * Test run with encryption
-     * @throws InterruptedException
-     * @throws IOException
-     * @throws ExecutionException
+     * Test run with encryption.
      */
     @Test
     public void testRunWithEncryption() throws InterruptedException, IOException, ExecutionException {
@@ -133,10 +117,10 @@ public class TcpHandlerTest {
         tcpHandler = new TcpHandler(serverAddress, serverPort);
         tcpHandler.setChannelInitializer(mockChannelInitializer);
 
-        assertEquals( "failed to start server", true, startupServer(false));
-        assertEquals( "wrong connection count", 0, tcpHandler.getNumberOfConnections());
-        assertEquals( "wrong port", serverPort, tcpHandler.getPort());
-        assertEquals( "wrong address", serverAddress.getHostAddress(), tcpHandler.getAddress());
+        assertEquals("failed to start server", true, startupServer(false));
+        assertEquals("wrong connection count", 0, tcpHandler.getNumberOfConnections());
+        assertEquals("wrong port", serverPort, tcpHandler.getPort());
+        assertEquals("wrong address", serverAddress.getHostAddress(), tcpHandler.getAddress());
 
         assertEquals("failed to connect client", true, clientConnection(tcpHandler.getPort()));
 
@@ -144,10 +128,7 @@ public class TcpHandlerTest {
     }
 
     /**
-     * Test run with encryption on Epoll native transport
-     * @throws InterruptedException
-     * @throws IOException
-     * @throws ExecutionException
+     * Test run with encryption on Epoll native transport.
      */
     @Test
     public void testRunWithEncryptionOnEpoll() throws InterruptedException, IOException, ExecutionException {
@@ -156,10 +137,10 @@ public class TcpHandlerTest {
         tcpHandler.setChannelInitializer(mockChannelInitializer);
 
         //Use Epoll native transport
-        assertEquals( "failed to start server", true, startupServer(true));
-        assertEquals( "wrong connection count", 0, tcpHandler.getNumberOfConnections());
-        assertEquals( "wrong port", serverPort, tcpHandler.getPort());
-        assertEquals( "wrong address", serverAddress.getHostAddress(), tcpHandler.getAddress());
+        assertEquals("failed to start server", true, startupServer(true));
+        assertEquals("wrong connection count", 0, tcpHandler.getNumberOfConnections());
+        assertEquals("wrong port", serverPort, tcpHandler.getPort());
+        assertEquals("wrong address", serverAddress.getHostAddress(), tcpHandler.getAddress());
 
         assertEquals("failed to connect client", true, clientConnection(tcpHandler.getPort()));
 
@@ -167,77 +148,59 @@ public class TcpHandlerTest {
     }
 
     /**
-     * Test run on already used port
-     * @throws IOException
+     * Test run on already used port.
      */
-    @Test
+    @Test(expected = BindException.class)
     public void testSocketAlreadyInUse() throws IOException {
         int serverPort = 28001;
         Socket firstBinder = new Socket();
-        boolean exceptionThrown = false;
+
         try {
             firstBinder.bind(new InetSocketAddress(serverAddress, serverPort));
-        } catch (Exception e) {
-            Assert.fail("Test precondition failed - not able to bind socket to port " + serverPort);
-        }
-        try {
             tcpHandler = new TcpHandler(serverAddress, serverPort);
             tcpHandler.setChannelInitializer(mockChannelInitializer);
             tcpHandler.initiateEventLoopGroups(null, false);
             tcpHandler.run();
-        } catch (Exception e) {
-            if (e instanceof BindException) {
-                exceptionThrown = true;
-            }
+        } finally {
+            firstBinder.close();
         }
-        firstBinder.close();
-        Assert.assertTrue("Expected BindException has not been thrown", exceptionThrown == true);
     }
 
     /**
-     * Test run on already used port
-     * @throws IOException
+     * Test run on already used port.
      */
     @Test
     public void testSocketAlreadyInUseOnEpoll() throws IOException {
         int serverPort = 28001;
         Socket firstBinder = new Socket();
-        boolean exceptionThrown = false;
+
         try {
             firstBinder.bind(new InetSocketAddress(serverAddress, serverPort));
-        } catch (Exception e) {
-            Assert.fail("Test precondition failed - not able to bind socket to port " + serverPort);
-        }
-        try {
+
             tcpHandler = new TcpHandler(serverAddress, serverPort);
             tcpHandler.setChannelInitializer(mockChannelInitializer);
             //Use Epoll native transport
             tcpHandler.initiateEventLoopGroups(null, true);
             tcpHandler.run();
-        } catch (Exception e) {
-            if (e instanceof BindException || e instanceof Errors.NativeIoException) {
-                exceptionThrown = true;
-            }
+            fail("Expected BindException or Errors.NativeIoException");
+        } catch (BindException | Errors.NativeIoException e) {
+            // expected
+        } finally {
+            firstBinder.close();
         }
-        firstBinder.close();
-        Assert.assertTrue("Expected BindException has not been thrown", exceptionThrown == true);
     }
 
     /**
-     * Trigger the server shutdown and wait 2 seconds for completion
+     * Trigger the server shutdown and wait 2 seconds for completion.
      */
     private void shutdownServer() throws InterruptedException, ExecutionException {
         ListenableFuture<Boolean> shutdownRet = tcpHandler.shutdown() ;
-        while ( shutdownRet.isDone() != true )
+        while (shutdownRet.isDone() != true) {
             Thread.sleep(100) ;
+        }
         assertEquals("shutdown failed", true, shutdownRet.get());
     }
 
-    /**
-     * @throws InterruptedException
-     * @throws IOException
-     * @throws ExecutionException
-     */
     private Boolean startupServer(boolean isEpollEnabled) throws InterruptedException, IOException, ExecutionException {
         ListenableFuture<Boolean> online = tcpHandler.getIsOnlineFuture();
         /**
@@ -245,19 +208,17 @@ public class TcpHandlerTest {
          * Else use Nio based transport.
          */
         tcpHandler.initiateEventLoopGroups(null, isEpollEnabled);
-            (new Thread(tcpHandler)).start();
-            int retry = 0;
-            while (online.isDone() != true && retry++ < 20) {
-                Thread.sleep(100);
-            }
+        new Thread(tcpHandler).start();
+        int retry = 0;
+        while (online.isDone() != true && retry++ < 20) {
+            Thread.sleep(100);
+        }
         return online.isDone() ;
     }
-    /**
-     * @throws IOException
-     */
+
     private static Boolean clientConnection(int port) throws IOException {
         // Connect, and disconnect
-        Socket socket = new Socket(InetAddress.getLoopbackAddress(), port );
+        Socket socket = new Socket(InetAddress.getLoopbackAddress(), port);
         Boolean result = socket.isConnected();
         socket.close() ;
         return result ;
index 624aef088261d2ba7faae2ac21ce483f90224017..8b1bb5027aa6dbba801b8416cf918a325058c654 100644 (file)
@@ -9,9 +9,7 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.socket.DatagramPacket;
-
 import java.net.InetSocketAddress;
-
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -20,24 +18,25 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer;
 
 /**
- * @author madamjak
+ * Unit tests for UdpConnectionMap.
  *
+ * @author madamjak
  */
 public class UdpConnectionMapTest {
 
     @Mock MessageConsumer consumerMock;
-    @Mock  ByteBuf messageBuffer;
+    @Mock ByteBuf messageBuffer;
 
     @Before
-    public void startUp(){
+    public void startUp() {
         MockitoAnnotations.initMocks(this);
     }
 
     /**
-     * Test {@link UdpConnectionMap} - sender address is not null
+     * Test {@link UdpConnectionMap} - sender address is not null.
      */
     @Test
-    public void testWithSenderAddress(){
+    public void testWithSenderAddress() {
         InetSocketAddress recipientISA = InetSocketAddress.createUnresolved("localhost", 9876);
         InetSocketAddress senderISA = InetSocketAddress.createUnresolved("192.168.15.2", 21021);
         DatagramPacket datagramPacket = new DatagramPacket(messageBuffer, recipientISA, senderISA);
@@ -50,26 +49,26 @@ public class UdpConnectionMapTest {
     }
 
     /**
-     * Test {@link UdpConnectionMap} - sender address is null to add connection
+     * Test {@link UdpConnectionMap} - sender address is null to add connection.
      */
     @Test(expected = IllegalArgumentException.class)
-    public void testWithoutSenderAddressOnAdd(){
+    public void testWithoutSenderAddressOnAdd() {
         UdpConnectionMap.addConnection(null, consumerMock);
     }
 
     /**
-     * Test {@link UdpConnectionMap} - sender address is not null to get message consumer
+     * Test {@link UdpConnectionMap} - sender address is not null to get message consumer.
      */
     @Test(expected = IllegalArgumentException.class)
-    public void testWithoutSenderAddressOnGet(){
+    public void testWithoutSenderAddressOnGet() {
         UdpConnectionMap.getMessageConsumer(null);
     }
 
     /**
-     * Test {@link UdpConnectionMap} - sender address is not null to remove connection
+     * Test {@link UdpConnectionMap} - sender address is not null to remove connection.
      */
     @Test(expected = IllegalArgumentException.class)
-    public void testWithoutSenderAddressOnRemove(){
+    public void testWithoutSenderAddressOnRemove() {
         UdpConnectionMap.removeConnection(null);
     }
 }
index be61603037c0187bebba000022c82034ce3e3265..a85b21b4dc954bb704f787cfc34d42a1c4a498fe 100644 (file)
@@ -10,31 +10,31 @@ package org.opendaylight.openflowjava.protocol.impl.core;
 
 import io.netty.buffer.ByteBuf;
 import java.net.InetSocketAddress;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.Assert;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
 /**
+ * Unit tests for VersionMessageUdpWrapper.
  *
  * @author madamjak
- *
  */
-
 public class VersionMessageUdpWrapperTest {
 
     @Mock ByteBuf byteBuff;
+
     @Before
-    public void startUp(){
+    public void startUp() {
         MockitoAnnotations.initMocks(this);
     }
 
     @Test
-    public void test(){
+    public void test() {
         short version = 35;
         int port = 9876;
-        String host ="localhost";
+        String host = "localhost";
         InetSocketAddress inetSockAddr = InetSocketAddress.createUnresolved(host, port);
         VersionMessageUdpWrapper wrapper = new VersionMessageUdpWrapper(version,byteBuff,inetSockAddr);
 
index 5f080dc571e6032e4ed2015158d792f4bf515ac2..5270f18e97bcdf20910f6dece377a422f2799ea0 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
@@ -30,20 +29,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
 
 /**
- * @author madamjak
+ * Unit tests for ChannelOutboundQueue02.
  *
+ * @author madamjak
  */
 public class ChannelOutboundQueue02Test {
     private static int counter;
     private static final int RPC_RESPONSE_EXPIRATION = 1;
     private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =
-            new RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>>() {
-        @Override
-        public void onRemoval(
-                final RemovalNotification<RpcResponseKey, ResponseExpectedRpcListener<?>> notification) {
-            notification.getValue().discard();
-        }
-    };
+        notification -> notification.getValue().discard();
 
     @Mock EchoInput echoInput;
     @Mock BarrierInput barrierInput;
@@ -51,61 +45,63 @@ public class ChannelOutboundQueue02Test {
     @Mock ExperimenterInput experimenterInput;
     private ConnectionAdapterImpl adapter;
     private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> cache;
+
     /**
-     * Initialize mocks
+     * Initialize mocks.
      */
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
     }
+
     /**
-     * Disconnect adapter after each test
+     * Disconnect adapter after each test.
      */
     @After
-    public void tierDown(){
+    public void tierDown() {
         if (adapter != null && adapter.isAlive()) {
             adapter.disconnect();
         }
     }
 
     /**
-     * Test write to closed / opened channel
-     * @throws Exception
+     * Test write to closed / opened channel.
      */
     @Test
     public void test01() throws Exception {
         final EmbeddedChannel ec = new EmbeddedChannel(new EmbededChannelHandler());
         adapter = new ConnectionAdapterImpl(ec, InetSocketAddress.createUnresolved("localhost", 9876), true);
-        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
-                .removalListener(REMOVAL_LISTENER).build();
+        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(
+                RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES).removalListener(REMOVAL_LISTENER).build();
         adapter.setResponseCache(cache);
         final ChannelOutboundQueue cq = (ChannelOutboundQueue) ec.pipeline().last();
-        counter=0;
+        counter = 0;
         adapter.barrier(barrierInput);
         adapter.echo(echoInput);
         cq.channelInactive(ec.pipeline().lastContext());
         ec.runPendingTasks();
         Assert.assertEquals("Wrong - ChannelOutboundHandlerAdapter.write was invoked on closed channel",0, counter);
         cq.channelActive(ec.pipeline().lastContext());
-        counter=0;
+        counter = 0;
         adapter.barrier(barrierInput);
         adapter.experimenter(experimenterInput);
         ec.runPendingTasks();
-        Assert.assertEquals("Wrong - ChannelOutboundHandlerAdapter.write has not been invoked on opened channel",2, counter);
+        Assert.assertEquals("Wrong - ChannelOutboundHandlerAdapter.write has not been invoked on opened channel",
+                2, counter);
     }
 
     /**
-     * Test write to read only / writable channel
+     * Test write to read only / writable channel.
      */
     @Test
-    public void test02(){
+    public void test02() {
         final ChangeWritableEmbededChannel ec = new ChangeWritableEmbededChannel(new EmbededChannelHandler());
         adapter = new ConnectionAdapterImpl(ec, InetSocketAddress.createUnresolved("localhost", 9876), true);
-        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
-                .removalListener(REMOVAL_LISTENER).build();
+        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(
+                RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES) .removalListener(REMOVAL_LISTENER).build();
         adapter.setResponseCache(cache);
         ec.setReadOnly();
-        counter=0;
+        counter = 0;
         adapter.barrier(barrierInput);
         adapter.echo(echoInput);
         ec.runPendingTasks();
@@ -118,28 +114,27 @@ public class ChannelOutboundQueue02Test {
     }
 
     /**
-     * Channel Handler for testing
+     * Channel Handler for testing.
      * @author madamjak
-     *
      */
     private class EmbededChannelHandler extends ChannelOutboundHandlerAdapter {
         @Override
         public void write(final ChannelHandlerContext ctx, final Object msg,
                 final ChannelPromise promise) throws Exception {
-            if(msg instanceof MessageListenerWrapper){
+            if (msg instanceof MessageListenerWrapper) {
                 counter++;
             }
         }
     }
 
     /**
-     * Class for testing - channel can change state to read only or writable
+     * Class for testing - channel can change state to read only or writable.
      * @author madamjak
-     *
      */
-    private class ChangeWritableEmbededChannel extends EmbeddedChannel {
+    private static class ChangeWritableEmbededChannel extends EmbeddedChannel {
         private boolean isWrittable;
-        public ChangeWritableEmbededChannel(final ChannelHandler channelHandler){
+
+        ChangeWritableEmbededChannel(final ChannelHandler channelHandler) {
             super(channelHandler);
             setReadOnly();
         }
@@ -149,11 +144,11 @@ public class ChannelOutboundQueue02Test {
             return isWrittable;
         }
 
-        public void setWritable(){
+        public void setWritable() {
             isWrittable = true;
         }
 
-        public void setReadOnly(){
+        public void setReadOnly() {
             isWrittable = false;
         }
     }
index 0b001d9b3c202b428a008b6c3dc226e3cffa33b0..56e33e7c4f63532fb37bb4d7abb6f5fb5d9dd14b 100644 (file)
@@ -9,39 +9,37 @@
 package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
 import io.netty.channel.Channel;
-
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ChannelOutboundQueue;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.SimpleRpcListener;
 
 /**
- * @author michal.polkorab
+ * UNit tests for ChannelOutboundQueue.
  *
+ * @author michal.polkorab
  */
 public class ChannelOutboundQueueTest {
 
     @Mock Channel channel;
 
     /**
-     * Initialize mocks
+     * Initialize mocks.
      */
     public ChannelOutboundQueueTest() {
         MockitoAnnotations.initMocks(this);
     }
 
     /**
-     * Test incorrect queue creation handling
+     * Test incorrect queue creation handling.
      */
-    @Test(expected=IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testIncorrectQueueCreation() {
         new ChannelOutboundQueue(channel, 0, null);
     }
 
     /**
-     * Test correct enqueue handling
+     * Test correct enqueue handling.
      */
     @Test
     public void testEnqueue() {
@@ -52,4 +50,4 @@ public class ChannelOutboundQueueTest {
         enqueued = queue.enqueue(new SimpleRpcListener("INPUT", "Failed to send INPUT"));
         Assert.assertFalse("Enqueue problem", enqueued);
     }
-}
\ No newline at end of file
+}
index e3317e32a7b921e7df8e2afa77cc4d7033b8be4d..6825e22d2b84e1d136f90af8ac24f3a8e5fca22c 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
 import static org.mockito.Mockito.when;
+
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelPipeline;
 import java.net.InetSocketAddress;
@@ -16,10 +17,11 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+
 /**
+ * Unit tests for ConnectionAdapterFactoryImpl.
  *
  * @author madamjak
- *
  */
 public class ConnectionAdapterFactoryImplTest {
 
@@ -28,16 +30,17 @@ public class ConnectionAdapterFactoryImplTest {
     @Mock InetSocketAddress address;
 
     @Before
-    public void startUp(){
+    public void startUp() {
         MockitoAnnotations.initMocks(this);
         when(channel.pipeline()).thenReturn(channnelPipe);
     }
 
     @Test
-    public void test(){
+    public void test() {
         final ConnectionAdapterFactoryImpl connAdapterFactory = new ConnectionAdapterFactoryImpl();
         final ConnectionFacade connFacade = connAdapterFactory.createConnectionFacade(channel, address, true);
         Assert.assertNotNull("Wrong - ConnectionFacade has not created.", connFacade);
-        Assert.assertEquals("Wrong - diffrence between channel.isOpen() and ConnectionFacade.isAlive()", channel.isOpen(), connFacade.isAlive());
+        Assert.assertEquals("Wrong - diffrence between channel.isOpen() and ConnectionFacade.isAlive()",
+                channel.isOpen(), connFacade.isAlive());
     }
 }
index 0909547cb57f0f5dcac55cef5951b19e58651cbd..b6ff68fab8b31c0653bca68a679a286463f0b5e6 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
 import io.netty.channel.ChannelPromise;
@@ -45,19 +44,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
 
 /**
+ * Unit tests for ConnectionAdapterImp02l.
+ *
  * @author madamjak
  * @author michal.polkorab
  */
 public class ConnectionAdapterImp02lTest {
     private static final int RPC_RESPONSE_EXPIRATION = 1;
     private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =
-            new RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>>() {
-        @Override
-        public void onRemoval(
-                final RemovalNotification<RpcResponseKey, ResponseExpectedRpcListener<?>> notification) {
-            notification.getValue().discard();
-        }
-    };
+        notification -> notification.getValue().discard();
 
     @Mock EchoInput echoInput;
     @Mock BarrierInput barrierInput;
@@ -81,31 +76,34 @@ public class ConnectionAdapterImp02lTest {
     private ConnectionAdapterImpl adapter;
     private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> cache;
     private OfHeader responseOfCall;
+
     /**
-     * Initialize mocks
+     * Initialize mocks.
      */
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
     }
+
     /**
-     * Disconnect adapter
+     * Disconnect adapter.
      */
     @After
-    public void tierDown(){
+    public void tierDown() {
         if (adapter != null && adapter.isAlive()) {
             adapter.disconnect();
         }
     }
+
     /**
-     * Test Rpc Calls
+     * Test Rpc Calls.
      */
     @Test
     public void testRcp() {
         final EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
         adapter = new ConnectionAdapterImpl(embChannel, InetSocketAddress.createUnresolved("localhost", 9876), true);
-        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
-                .removalListener(REMOVAL_LISTENER).build();
+        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(
+                RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES).removalListener(REMOVAL_LISTENER).build();
         adapter.setResponseCache(cache);
         // -- barrier
         adapter.barrier(barrierInput);
@@ -187,16 +185,15 @@ public class ConnectionAdapterImp02lTest {
     }
 
     /**
-     * Channel Handler for testing
+     * Channel Handler for testing.
      * @author madamjak
-     *
      */
     private class EmbededChannelHandler extends ChannelOutboundHandlerAdapter {
         @Override
         public void write(final ChannelHandlerContext ctx, final Object msg,
                 final ChannelPromise promise) throws Exception {
             responseOfCall = null;
-            if(msg instanceof MessageListenerWrapper){
+            if (msg instanceof MessageListenerWrapper) {
                 final MessageListenerWrapper listener = (MessageListenerWrapper) msg;
                 final OfHeader ofHeader = listener.getMsg();
                 responseOfCall = ofHeader;
index 0786009553b9b24d661a77470786aec33cf7f4b9..27259cff335d4d26143ed980f9adf8be03583fbf 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
 import io.netty.channel.ChannelPromise;
@@ -45,19 +44,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
 
 /**
+ * Unit tests for ConnectionAdapterImpl02.
+ *
  * @author madamjak
  * @author michal.polkorab
  */
 public class ConnectionAdapterImpl02Test {
     private static final int RPC_RESPONSE_EXPIRATION = 1;
     private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =
-            new RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>>() {
-        @Override
-        public void onRemoval(
-                final RemovalNotification<RpcResponseKey, ResponseExpectedRpcListener<?>> notification) {
-            notification.getValue().discard();
-        }
-    };
+        notification -> notification.getValue().discard();
 
     @Mock EchoInput echoInput;
     @Mock BarrierInput barrierInput;
@@ -81,31 +76,34 @@ public class ConnectionAdapterImpl02Test {
     private ConnectionAdapterImpl adapter;
     private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> cache;
     private OfHeader responseOfCall;
+
     /**
-     * Initialize mocks
+     * Initialize mocks.
      */
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
     }
+
     /**
-     * Disconnect adapter
+     * Disconnect adapter.
      */
     @After
-    public void tierDown(){
+    public void tierDown() {
         if (adapter != null && adapter.isAlive()) {
             adapter.disconnect();
         }
     }
+
     /**
-     * Test Rpc Calls
+     * Test Rpc Calls.
      */
     @Test
     public void testRcp() {
         final EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
         adapter = new ConnectionAdapterImpl(embChannel, InetSocketAddress.createUnresolved("localhost", 9876), true);
-        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
-                .removalListener(REMOVAL_LISTENER).build();
+        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(
+                RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES).removalListener(REMOVAL_LISTENER).build();
         adapter.setResponseCache(cache);
         // -- barrier
         adapter.barrier(barrierInput);
@@ -187,16 +185,15 @@ public class ConnectionAdapterImpl02Test {
     }
 
     /**
-     * Channel Handler for testing
+     * Channel Handler for testing.
      * @author madamjak
-     *
      */
     private class EmbededChannelHandler extends ChannelOutboundHandlerAdapter {
         @Override
         public void write(final ChannelHandlerContext ctx, final Object msg,
                 final ChannelPromise promise) throws Exception {
             responseOfCall = null;
-            if(msg instanceof MessageListenerWrapper){
+            if (msg instanceof MessageListenerWrapper) {
                 final MessageListenerWrapper listener = (MessageListenerWrapper) msg;
                 final OfHeader ofHeader = listener.getMsg();
                 responseOfCall = ofHeader;
index 706c624e7cd5c341343704059daf45d875179d8f..2be700704b195cbd91338344675ebac0aaf897a4 100644 (file)
@@ -12,7 +12,6 @@ import static org.mockito.Mockito.when;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
 import io.netty.channel.ChannelPipeline;
@@ -61,21 +60,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.S
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
- * Test counters in ConnectionAdapter (at least DS_ENTERED_OFJAVA, DS_FLOW_MODS_ENTERED and US_MESSAGE_PASS counters have to be enabled)
- * @author madamjak
+ * Test counters in ConnectionAdapter (at least DS_ENTERED_OFJAVA, DS_FLOW_MODS_ENTERED and US_MESSAGE_PASS counters
+ * have to be enabled).
  *
+ * @author madamjak
  */
 public class ConnectionAdapterImplStatisticsTest {
 
     private static final int RPC_RESPONSE_EXPIRATION = 1;
     private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =
-            new RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>>() {
-        @Override
-        public void onRemoval(
-                final RemovalNotification<RpcResponseKey, ResponseExpectedRpcListener<?>> notification) {
-            notification.getValue().discard();
-        }
-    };
+        notification -> notification.getValue().discard();
 
     @Mock SystemNotificationsListener systemListener;
     @Mock ConnectionReadyListener readyListener;
@@ -108,8 +102,8 @@ public class ConnectionAdapterImplStatisticsTest {
     private StatisticsCounters statCounters;
 
     /**
-     * Initialize mocks
-     * Start counting and reset counters before each test
+     * Initialize mocks.
+     * Start counting and reset counters before each test.
      */
     @Before
     public void setUp() {
@@ -119,11 +113,11 @@ public class ConnectionAdapterImplStatisticsTest {
     }
 
     /**
-     * Disconnect adapter
-     * Stop counting after each test
+     * Disconnect adapter.
+     * Stop counting after each test.
      */
     @After
-    public void tierDown(){
+    public void tierDown() {
         if (adapter != null && adapter.isAlive()) {
             adapter.disconnect();
         }
@@ -131,20 +125,21 @@ public class ConnectionAdapterImplStatisticsTest {
     }
 
     /**
-     * Test statistic counter for all rpc calls (counters DS_ENTERED_OFJAVA and DS_FLOW_MODS_ENTERED have to be enabled)
+     * Test statistic counter for all rpc calls (counters DS_ENTERED_OFJAVA and DS_FLOW_MODS_ENTERED have to be
+     * enabled).
      */
     @Test
     public void testEnterOFJavaCounter() {
-        if(!statCounters.isCounterEnabled(CounterEventTypes.DS_ENTERED_OFJAVA)){
+        if (!statCounters.isCounterEnabled(CounterEventTypes.DS_ENTERED_OFJAVA)) {
             Assert.fail("Counter " + CounterEventTypes.DS_ENTERED_OFJAVA + " is not enabled");
         }
-        if(!statCounters.isCounterEnabled(CounterEventTypes.DS_FLOW_MODS_ENTERED)){
+        if (!statCounters.isCounterEnabled(CounterEventTypes.DS_FLOW_MODS_ENTERED)) {
             Assert.fail("Counter " + CounterEventTypes.DS_FLOW_MODS_ENTERED + " is not enabled");
         }
         final EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
         adapter = new ConnectionAdapterImpl(embChannel, InetSocketAddress.createUnresolved("localhost", 9876), true);
-        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
-                .removalListener(REMOVAL_LISTENER).build();
+        cache = CacheBuilder.newBuilder().concurrencyLevel(1)
+                .expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES).removalListener(REMOVAL_LISTENER).build();
         adapter.setResponseCache(cache);
         adapter.barrier(barrierInput);
         embChannel.runPendingTasks();
@@ -184,17 +179,19 @@ public class ConnectionAdapterImplStatisticsTest {
         embChannel.runPendingTasks();
         adapter.setAsync(setAsyncInput);
         embChannel.runPendingTasks();
-        Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl rpc methods", 19, statCounters.getCounter(CounterEventTypes.DS_ENTERED_OFJAVA).getCounterValue());
-        Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl flow-mod entered", 1, statCounters.getCounter(CounterEventTypes.DS_FLOW_MODS_ENTERED).getCounterValue());
+        Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl rpc methods", 19,
+                statCounters.getCounter(CounterEventTypes.DS_ENTERED_OFJAVA).getCounterValue());
+        Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl flow-mod entered", 1,
+                statCounters.getCounter(CounterEventTypes.DS_FLOW_MODS_ENTERED).getCounterValue());
         adapter.disconnect();
     }
 
     /**
-     * Test counter for pass messages to consumer (counter US_MESSAGE_PASS has to be enabled)
+     * Test counter for pass messages to consumer (counter US_MESSAGE_PASS has to be enabled).
      */
     @Test
     public void testMessagePassCounter() {
-        if(!statCounters.isCounterEnabled(CounterEventTypes.US_MESSAGE_PASS)){
+        if (!statCounters.isCounterEnabled(CounterEventTypes.US_MESSAGE_PASS)) {
             Assert.fail("Counter " + CounterEventTypes.US_MESSAGE_PASS + " is not enabled");
         }
         when(channel.pipeline()).thenReturn(pipeline);
@@ -202,8 +199,8 @@ public class ConnectionAdapterImplStatisticsTest {
         adapter.setMessageListener(messageListener);
         adapter.setSystemListener(systemListener);
         adapter.setConnectionReadyListener(readyListener);
-        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
-                .removalListener(REMOVAL_LISTENER).build();
+        cache = CacheBuilder.newBuilder().concurrencyLevel(1)
+                .expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES).removalListener(REMOVAL_LISTENER).build();
         adapter.setResponseCache(cache);
         when(channel.disconnect()).thenReturn(channelFuture);
         DataObject message = new EchoRequestMessageBuilder().build();
@@ -224,14 +221,14 @@ public class ConnectionAdapterImplStatisticsTest {
         adapter.consume(message);
         message = new EchoRequestMessageBuilder().build();
         adapter.consume(message);
-        Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl consume method", 9, statCounters.getCounter(CounterEventTypes.US_MESSAGE_PASS).getCounterValue());
+        Assert.assertEquals("Wrong - bad counter value for ConnectionAdapterImpl consume method", 9,
+                statCounters.getCounter(CounterEventTypes.US_MESSAGE_PASS).getCounterValue());
         adapter.disconnect();
     }
 
     /**
-     * Empty channel Handler for testing
+     * Empty channel Handler for testing.
      * @author madamjak
-     *
      */
     private class EmbededChannelHandler extends ChannelOutboundHandlerAdapter {
         // no operation need to test
index 0859a34f31537ca90f97e9d318d017a787d7d1bf..884b326c02cb7cb5838204f6ada351cbd250afe9 100644 (file)
@@ -12,10 +12,10 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelPipeline;
 import io.netty.channel.socket.SocketChannel;
@@ -58,21 +58,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.S
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
+ * Unit test for ConnectionAdapterImpl.
+ *
  * @author michal.polkorab
  * @author madamjak
- *
  */
 public class ConnectionAdapterImplTest {
 
     private static final int RPC_RESPONSE_EXPIRATION = 1;
     private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =
-            new RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>>() {
-        @Override
-        public void onRemoval(
-                final RemovalNotification<RpcResponseKey, ResponseExpectedRpcListener<?>> notification) {
-            notification.getValue().discard();
-        }
-    };
+        notification -> notification.getValue().discard();
 
     @Mock SocketChannel channel;
     @Mock ChannelPipeline pipeline;
@@ -86,7 +81,7 @@ public class ConnectionAdapterImplTest {
     private Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> cache;
 
     /**
-     * Initializes ConnectionAdapter
+     * Initializes ConnectionAdapter.
      */
     @Before
     public void setUp() {
@@ -96,14 +91,14 @@ public class ConnectionAdapterImplTest {
         adapter.setMessageListener(messageListener);
         adapter.setSystemListener(systemListener);
         adapter.setConnectionReadyListener(readyListener);
-        cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
-                .removalListener(REMOVAL_LISTENER).build();
+        cache = CacheBuilder.newBuilder().concurrencyLevel(1)
+                .expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES).removalListener(REMOVAL_LISTENER).build();
         adapter.setResponseCache(cache);
         when(channel.disconnect()).thenReturn(channelFuture);
     }
 
     /**
-     * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with notifications
+     * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with notifications.
      */
     @Test
     public void testConsume() {
@@ -143,7 +138,7 @@ public class ConnectionAdapterImplTest {
     }
 
     /**
-     * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with unexpected rpc
+     * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with unexpected rpc.
      */
     @Test
     public void testConsume2() {
@@ -156,7 +151,7 @@ public class ConnectionAdapterImplTest {
     }
 
     /**
-     * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with expected rpc
+     * Tests {@link ConnectionAdapterImpl#consume(DataObject)} with expected rpc.
      */
     @Test
     public void testConsume3() {
@@ -164,7 +159,8 @@ public class ConnectionAdapterImplTest {
         inputBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
         inputBuilder.setXid(42L);
         final BarrierInput barrierInput = inputBuilder.build();
-        final RpcResponseKey key = new RpcResponseKey(42L, "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput");
+        final RpcResponseKey key = new RpcResponseKey(42L,
+                "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput");
         final ResponseExpectedRpcListener<OfHeader> listener = new ResponseExpectedRpcListener<>(barrierInput,
                 "failure", mockCache, key);
         cache.put(key, listener);
@@ -175,28 +171,30 @@ public class ConnectionAdapterImplTest {
         final ResponseExpectedRpcListener<?> ifPresent = cache.getIfPresent(key);
         Assert.assertNull("Listener was not discarded", ifPresent);
     }
+
     /**
-     * Test IsAlive method
+     * Test IsAlive method.
      */
     @Test
-    public void testIsAlive(){
+    public void testIsAlive() {
         final int port = 9876;
-        final String host ="localhost";
+        final String host = "localhost";
         final InetSocketAddress inetSockAddr = InetSocketAddress.createUnresolved(host, port);
         final ConnectionAdapterImpl connAddapter = new ConnectionAdapterImpl(channel, inetSockAddr, true);
-        Assert.assertEquals("Wrong - diffrence between channel.isOpen() and ConnectionAdapterImpl.isAlive()", channel.isOpen(), connAddapter.isAlive());
+        Assert.assertEquals("Wrong - diffrence between channel.isOpen() and ConnectionAdapterImpl.isAlive()",
+                channel.isOpen(), connAddapter.isAlive());
 
         connAddapter.disconnect();
         Assert.assertFalse("Wrong - ConnectionAdapterImpl can not be alive after disconnet.", connAddapter.isAlive());
     }
 
     /**
-     * Test throw exception if no listeners are present
+     * Test throw exception if no listeners are present.
      */
     @Test(expected = java.lang.IllegalStateException.class)
-    public void testMissingListeners(){
+    public void testMissingListeners() {
         final int port = 9876;
-        final String host ="localhost";
+        final String host = "localhost";
         final InetSocketAddress inetSockAddr = InetSocketAddress.createUnresolved(host, port);
         final ConnectionAdapterImpl connAddapter = new ConnectionAdapterImpl(channel, inetSockAddr, true);
         connAddapter.setSystemListener(null);
index 3efb2504e3d35a398393f97744c0c93cf66251c7..faa43ae4f06d18f05fc0584419511c93951ac587 100644 (file)
@@ -15,8 +15,9 @@ import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
 
 /**
- * @author michal.polkorab
+ * Test implementation for ConnectionConfiguration.
  *
+ * @author michal.polkorab
  */
 public class ConnectionConfigurationImpl implements ConnectionConfiguration {
 
@@ -30,13 +31,7 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
     private final boolean isGroupAddModEnabled;
 
     /**
-     * Creates {@link ConnectionConfigurationImpl}
-     *
-     * @param address
-     * @param port
-     * @param tlsConfig
-     * @param switchIdleTimeout
-     * @param useBarrier
+     * Creates {@link ConnectionConfigurationImpl}.
      */
     public ConnectionConfigurationImpl(final InetAddress address, final int port, final TlsConfiguration tlsConfig,
             final long switchIdleTimeout, final boolean useBarrier, final boolean isGroupAddModEnabled) {
@@ -64,8 +59,7 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
     }
 
     /**
-     * Used for testing - sets transport protocol
-     * @param protocol
+     * Used for testing - sets transport protocol.
      */
     public void setTransferProtocol(final TransportProtocol protocol) {
         this.transferProtocol = protocol;
@@ -93,10 +87,12 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
     }
 
     /**
-     * @param threadConfig thread model configuration (configures threads used)
+     * Sets the ThreadConfiguration.
+     *
+     * @param config thread model configuration (configures threads used)
      */
-    public void setThreadConfiguration(final ThreadConfiguration threadConfig) {
-        this.threadConfig = threadConfig;
+    public void setThreadConfiguration(final ThreadConfiguration config) {
+        this.threadConfig = config;
     }
 
     @Override
@@ -108,4 +104,4 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration {
     public boolean isGroupAddModEnabled() {
         return isGroupAddModEnabled;
     }
-}
\ No newline at end of file
+}
index 3be4ba4f38bbb42ad991d536d6850cbeb673d5c1..155af98d8302f82defb9cf3b9609c7a30c091f7e 100644 (file)
@@ -10,19 +10,18 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
 import org.junit.Assert;
 import org.junit.Test;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageListenerWrapper;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.SimpleRpcListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;
 
 /**
- * @author michal.polkorab
+ * UNit tests for MessageListenerWrapper.
  *
+ * @author michal.polkorab
  */
 public class MessageListenerWrapperTest {
 
     /**
-     * Test MessageListenerWrapper creation
+     * Test MessageListenerWrapper creation.
      */
     @Test
     public void test() {
@@ -33,4 +32,4 @@ public class MessageListenerWrapperTest {
         Assert.assertEquals("Wrong message", hello, wrapper.getMsg());
         Assert.assertEquals("Wrong listener", listener, wrapper.getListener());
     }
-}
\ No newline at end of file
+}
index 08c98c415d2dd879899f6632ba47b1022f2d74c1..aba2d152478376ba813d900131720f531f3c6006 100644 (file)
@@ -27,7 +27,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * {@link OutboundQueueEntry} class test
+ * {@link OutboundQueueEntry} class test.
  */
 @RunWith(MockitoJUnitRunner.class)
 public class OutboundQueueEntryTest {
@@ -47,8 +47,8 @@ public class OutboundQueueEntryTest {
     private final OutboundQueueEntry outboundQueueEntry = new OutboundQueueEntry();
     private final OfHeader barrierInput = new BarrierInputBuilder().setVersion(VERSION).setXid(VALUE).build();
     private final OfHeader packetOutInput = new PacketOutInputBuilder().setVersion(VERSION).setXid(VALUE).build();
-    private final OfHeader multipartReplyMessage =
-            new MultipartReplyMessageBuilder().setVersion(VERSION).setXid(VALUE).setFlags(new MultipartRequestFlags(false)).build();
+    private final OfHeader multipartReplyMessage = new MultipartReplyMessageBuilder().setVersion(VERSION).setXid(VALUE)
+            .setFlags(new MultipartRequestFlags(false)).build();
     private final OfHeader flowModInput = new FlowModInputBuilder().setVersion(VERSION).setXid(VALUE).build();
     private final OfHeader flowRemoved = new FlowRemovedMessageBuilder().setVersion(VERSION).setXid(VALUE).build();
 
@@ -109,20 +109,18 @@ public class OutboundQueueEntryTest {
     @Test
     public void test() throws Exception {
 
-        final FutureCallback<OfHeader> result =
-                new FutureCallback<OfHeader>() {
+        final FutureCallback<OfHeader> result = new FutureCallback<OfHeader>() {
+            @Override
+            public void onSuccess(@Nullable OfHeader header) {
+                LOG.info("onSuccess: xid: {}", header.getXid());
+            }
 
-                    @Override
-                    public void onSuccess(@Nullable OfHeader ofHeader) {
-                        LOG.info("onSuccess: xid: {}", ofHeader.getXid());
-                    }
-
-                    @Override
-                    public void onFailure(Throwable throwable) {
-                        LOG.info("onFailure! Error: {}", throwable);
-                        LOG.info("Failure called {} time", increaseFailCounter());
-                    }
-                };
+            @Override
+            public void onFailure(Throwable throwable) {
+                LOG.info("onFailure! Error: {}", throwable);
+                LOG.info("Failure called {} time", increaseFailCounter());
+            }
+        };
 
         /** This scenario creates entry with XID 1 then commit it, fail it and again commit it */
         /** Simulates behavior when entry is committed after fail */
@@ -143,5 +141,4 @@ public class OutboundQueueEntryTest {
 
         Assert.assertTrue(this.failCounter == 1);
     }
-
 }
index e6d1fff2e4d3746ac0603505234949440c01a726..f6c1b9ac05dac1101b0437e6d699f22ea711f949 100644 (file)
@@ -9,10 +9,10 @@
 package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
 import static org.junit.Assert.fail;
+
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -28,19 +28,14 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
 /**
- * @author michal.polkorab
+ * Unit tests for ResponseExpectedRpcListener.
  *
+ * @author michal.polkorab
  */
 public class ResponseExpectedRpcListenerTest {
 
     private static final RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>> REMOVAL_LISTENER =
-            new RemovalListener<RpcResponseKey, ResponseExpectedRpcListener<?>>() {
-        @Override
-        public void onRemoval(
-                final RemovalNotification<RpcResponseKey, ResponseExpectedRpcListener<?>> notification) {
-            notification.getValue().discard();
-        }
-    };
+        notification -> notification.getValue().discard();
     private static final int RPC_RESPONSE_EXPIRATION = 1;
     private final Cache<RpcResponseKey, ResponseExpectedRpcListener<?>> responseCache  = CacheBuilder.newBuilder()
             .concurrencyLevel(1)
@@ -48,24 +43,24 @@ public class ResponseExpectedRpcListenerTest {
             .removalListener(REMOVAL_LISTENER).build();
 
     /**
-     * Test object creation
+     * Test object creation.
      */
-    @Test(expected=NullPointerException.class)
+    @Test(expected = NullPointerException.class)
     public void testCreation() {
         RpcResponseKey key = new RpcResponseKey(12345L, BarrierOutput.class.getName());
         new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", null, key);
     }
 
     /**
-     * Test object creation
+     * Test object creation.
      */
-    @Test(expected=NullPointerException.class)
+    @Test(expected = NullPointerException.class)
     public void testCreation2() {
         new ResponseExpectedRpcListener<>("MESSAGE", "Failed to send message", responseCache, null);
     }
 
     /**
-     * Test object creation
+     * Test object creation.
      */
     @Test
     public void testDiscard() {
@@ -88,7 +83,7 @@ public class ResponseExpectedRpcListenerTest {
     }
 
     /**
-     * Test object creation
+     * Test object creation.
      */
     @Test
     public void testCompleted() {
@@ -110,7 +105,7 @@ public class ResponseExpectedRpcListenerTest {
     }
 
     /**
-     * Test object creation
+     * Test object creation.
      */
     @Test
     public void testOperationSuccessful() {
@@ -121,4 +116,4 @@ public class ResponseExpectedRpcListenerTest {
         ResponseExpectedRpcListener<?> present = responseCache.getIfPresent(key);
         Assert.assertEquals(present, listener);
     }
-}
\ No newline at end of file
+}
index 2ef9cb82618cb8f1dc51c15034fcf0da6a9b9e2d..d8b8177b9e3d628213ad24ab1f52dd24d7a54346 100644 (file)
@@ -8,26 +8,25 @@
 
 package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
-import org.junit.Test;
 import org.junit.Assert;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.RpcResponseKey;
+import org.junit.Test;
 
 /**
+ * Unit tests for RpcResponseKey.
  *
  * @author madamjak
- *
  */
 public class RpcResponseKeyTest {
 
     /**
-     * Test equals (xid is not tested)
+     * Test equals (xid is not tested).
      */
     @Test
-    public void testEquals(){
+    public void testEquals() {
 
         long xid1 = 12L;
         long xid2 = 66L;
-        String outputClazz1 = "Clazz01";
+        final String outputClazz1 = "Clazz01";
         String outputClazz2 = "Clazz02";
         RpcResponseKey key1 = new RpcResponseKey(xid1, null);
         RpcResponseKey key2 = new RpcResponseKey(xid2, outputClazz2);
@@ -46,10 +45,10 @@ public class RpcResponseKeyTest {
     }
 
     /**
-     * Test getters
+     * Test getters.
      */
     @Test
-    public void testGetters(){
+    public void testGetters() {
 
         long xid1 = 12L;
         String outputClazz1 = "Clazz01";
index 7726000532b4d5bfa57af446982ec375c20a16df..51c99dcc967e69e466a94fcd9bca7a3a873ddb0d 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.fail;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+
 import com.google.common.util.concurrent.SettableFuture;
 import io.netty.util.concurrent.Future;
 import java.util.concurrent.ExecutionException;
@@ -24,15 +25,16 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 
 /**
- * @author michal.polkorab
+ * UNit tests for SimpleRpcListener.
  *
+ * @author michal.polkorab
  */
 public class SimpleRpcListenerTest {
 
     @Mock Future<Void> future;
 
     /**
-     * Initializes mocks
+     * Initializes mocks.
      */
     @Before
     public void startUp() {
@@ -40,7 +42,7 @@ public class SimpleRpcListenerTest {
     }
 
     /**
-     * Test SimpleRpcListener creation
+     * Test SimpleRpcListener creation.
      */
     @Test
     public void test() {
@@ -50,7 +52,7 @@ public class SimpleRpcListenerTest {
     }
 
     /**
-     * Test rpc success
+     * Test rpc success.
      */
     @Test
     public void testSuccessfulRpc() {
@@ -68,7 +70,7 @@ public class SimpleRpcListenerTest {
     }
 
     /**
-     * Test rpc success
+     * Test rpc success.
      */
     @Test
     public void testOperationComplete() {
@@ -84,7 +86,7 @@ public class SimpleRpcListenerTest {
     }
 
     /**
-     * Test rpc success
+     * Test rpc success.
      */
     @Test
     public void testOperationComplete2() {
@@ -99,4 +101,4 @@ public class SimpleRpcListenerTest {
             Assert.fail();
         }
     }
-}
\ No newline at end of file
+}
index af3b418231dbc6bd0444380ade01daeba9e796f8..23b8902fcc96b5e958f59242a23de7455bad94cb 100755 (executable)
@@ -9,6 +9,8 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -49,10 +51,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
 /**
+ * Unit tests for SwitchConnectionProviderImpl02.
+ *
  * @author madamjak
  * @author michal.polkorab
  */
@@ -70,15 +71,15 @@ public class SwitchConnectionProviderImpl02Test {
     @Mock OFSerializer<MeterBandExperimenterCase> serializerMeterBandExpCase;
     @Mock ConnectionConfigurationImpl config;
     private static final int SWITCH_IDLE_TIMEOUT = 2000;
-    private InetAddress startupAddress;
     private TlsConfiguration tlsConfiguration;
     private SwitchConnectionProviderImpl provider;
 
     /**
-     * Creates new {@link SwitchConnectionProvider} instance for each test
+     * Creates new {@link SwitchConnectionProvider} instance for each test.
+     *
      * @param protocol communication protocol
      */
-    public void startUp(final TransportProtocol protocol) {
+    public void startUp(final TransportProtocol protocol) throws UnknownHostException {
         MockitoAnnotations.initMocks(this);
         config = null;
         if (protocol != null) {
@@ -87,12 +88,9 @@ public class SwitchConnectionProviderImpl02Test {
         provider = new SwitchConnectionProviderImpl(config);
     }
 
-    private void createConfig(final TransportProtocol protocol) {
-        try {
-            startupAddress = InetAddress.getLocalHost();
-        } catch (final UnknownHostException e) {
-            e.printStackTrace();
-        }
+    private void createConfig(final TransportProtocol protocol) throws UnknownHostException {
+        InetAddress startupAddress = InetAddress.getLocalHost();
+
         tlsConfiguration = null;
         if (protocol.equals(TransportProtocol.TLS)) {
             tlsConfiguration = new TlsConfigurationImpl(KeystoreType.JKS,
@@ -106,10 +104,10 @@ public class SwitchConnectionProviderImpl02Test {
 
 
     /**
-     * Test getServerFacade
+     * Test getServerFacade.
      */
     @Test
-    public void testServerFacade(){
+    public void testServerFacade() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         final ListenableFuture<Boolean> future = provider.startup();
         final ServerFacade serverFacade = provider.getServerFacade();
@@ -117,18 +115,19 @@ public class SwitchConnectionProviderImpl02Test {
     }
 
     /**
-     * Test shutdown on unconfigured provider
+     * Test shutdown on unconfigured provider.
      */
     @Test(expected = IllegalStateException.class)
-    public void testShutdownUnconfigured(){
+    public void testShutdownUnconfigured() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         provider.shutdown();
     }
+
     /**
-     * Test unregister by wrong key
+     * Test unregister by wrong key.
      */
     @Test
-    public void testUnregisterWrongKeys(){
+    public void testUnregisterWrongKeys() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         final ExperimenterInstructionSerializerKey testSerKey
             = new ExperimenterInstructionSerializerKey(EncodeConstants.OF10_VERSION_ID,42L);
@@ -139,107 +138,127 @@ public class SwitchConnectionProviderImpl02Test {
     }
 
     /**
-     * Test register and unregister method
+     * Test register and unregister method.
      */
     @Test
-    public void testUnregisterExistingKeys(){
+    public void testUnregisterExistingKeys() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         // -- registerActionSerializer
         final ExperimenterActionSerializerKey key1
             = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);
         provider.registerActionSerializer(key1, serializer);
         Assert.assertTrue("Wrong -- unregister ActionSerializer", provider.unregisterSerializer(key1));
-        Assert.assertFalse("Wrong -- unregister ActionSerializer by not existing key", provider.unregisterSerializer(key1));
+        Assert.assertFalse("Wrong -- unregister ActionSerializer by not existing key",
+                provider.unregisterSerializer(key1));
         // -- registerActionDeserializer
         final ExperimenterActionDeserializerKey key2
             = new ExperimenterActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L);
         provider.registerActionDeserializer(key2, deserializer);
         Assert.assertTrue("Wrong -- unregister ActionDeserializer", provider.unregisterDeserializer(key2));
-        Assert.assertFalse("Wrong -- unregister ActionDeserializer by not existing key", provider.unregisterDeserializer(key2));
+        Assert.assertFalse("Wrong -- unregister ActionDeserializer by not existing key",
+                provider.unregisterDeserializer(key2));
         // -- registerInstructionSerializer
         final ExperimenterInstructionSerializerKey key3
             = new ExperimenterInstructionSerializerKey(EncodeConstants.OF10_VERSION_ID,42L);
         provider.registerInstructionSerializer(key3, serializer);
         Assert.assertTrue("Wrong -- unregister InstructionSerializer", provider.unregisterSerializer(key3));
-        Assert.assertFalse("Wrong -- unregister InstructionSerializer by not existing key", provider.unregisterSerializer(key3));
+        Assert.assertFalse("Wrong -- unregister InstructionSerializer by not existing key",
+                provider.unregisterSerializer(key3));
         // -- registerInstructionDeserializer
         final ExperimenterInstructionDeserializerKey key4
             = new ExperimenterInstructionDeserializerKey(EncodeConstants.OF10_VERSION_ID,42L);
         provider.registerInstructionDeserializer(key4, deserializer);
         Assert.assertTrue("Wrong -- unregister InstructionDeserializer", provider.unregisterDeserializer(key4));
-        Assert.assertFalse("Wrong -- unregister InstructionDeserializer by not existing key", provider.unregisterDeserializer(key4));
+        Assert.assertFalse("Wrong -- unregister InstructionDeserializer by not existing key",
+                provider.unregisterDeserializer(key4));
         // -- registerMatchEntryDeserializer
         final MatchEntryDeserializerKey key5
             = new MatchEntryDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0x8000, 42);
         provider.registerMatchEntryDeserializer(key5, deserializer);
         Assert.assertTrue("Wrong -- unregister MatchEntryDeserializer", provider.unregisterDeserializer(key5));
-        Assert.assertFalse("Wrong -- unregister MatchEntryDeserializer by not existing key", provider.unregisterDeserializer(key5));
+        Assert.assertFalse("Wrong -- unregister MatchEntryDeserializer by not existing key",
+                provider.unregisterDeserializer(key5));
         // -- registerErrorDeserializer
         final ExperimenterIdDeserializerKey key6
             = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, ErrorMessage.class);
         provider.registerErrorDeserializer(key6, deserializerError);
         Assert.assertTrue("Wrong -- unregister ErrorDeserializer", provider.unregisterDeserializer(key6));
-        Assert.assertFalse("Wrong -- unregister ErrorDeserializer by not existing key", provider.unregisterDeserializer(key6));
+        Assert.assertFalse("Wrong -- unregister ErrorDeserializer by not existing key",
+                provider.unregisterDeserializer(key6));
         // -- registerExperimenterMessageDeserializer
         final ExperimenterIdDeserializerKey key7
             = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterMessage.class);
         provider.registerExperimenterMessageDeserializer(key7, deserializerExpMsg);
         Assert.assertTrue("Wrong -- unregister ExperimenterMessageDeserializer", provider.unregisterDeserializer(key7));
-        Assert.assertFalse("Wrong -- unregister ExperimenterMessageDeserializer by not existing key", provider.unregisterDeserializer(key7));
+        Assert.assertFalse("Wrong -- unregister ExperimenterMessageDeserializer by not existing key",
+                provider.unregisterDeserializer(key7));
         // -- registerMultipartReplyMessageDeserializer
         final ExperimenterIdDeserializerKey key8
             = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MultipartReplyMessage.class);
         provider.registerMultipartReplyMessageDeserializer(key8, deserializerMultipartRplMsg);
-        Assert.assertTrue("Wrong -- unregister MultipartReplyMessageDeserializer", provider.unregisterDeserializer(key8));
-        Assert.assertFalse("Wrong -- unregister MultipartReplyMessageDeserializer by not existing key", provider.unregisterDeserializer(key8));
+        Assert.assertTrue("Wrong -- unregister MultipartReplyMessageDeserializer",
+                provider.unregisterDeserializer(key8));
+        Assert.assertFalse("Wrong -- unregister MultipartReplyMessageDeserializer by not existing key",
+                provider.unregisterDeserializer(key8));
         // -- registerMultipartReplyTFDeserializer
         final ExperimenterIdDeserializerKey key9 =
                 new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MultipartReplyMessage.class);
         provider.registerMultipartReplyTFDeserializer(key9, deserializer);
         Assert.assertTrue("Wrong -- unregister MultipartReplyTFDeserializer", provider.unregisterDeserializer(key9));
-        Assert.assertFalse("Wrong -- unregister MultipartReplyTFDeserializer by non existing key", provider.unregisterDeserializer(key9));
+        Assert.assertFalse("Wrong -- unregister MultipartReplyTFDeserializer by non existing key",
+                provider.unregisterDeserializer(key9));
         // -- registerQueuePropertyDeserializer
         final ExperimenterIdDeserializerKey key10
             = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, QueueProperty.class);
         provider.registerQueuePropertyDeserializer(key10, deserializerQueueProperty);
         Assert.assertTrue("Wrong -- unregister QueuePropertyDeserializer", provider.unregisterDeserializer(key10));
-        Assert.assertFalse("Wrong -- unregister QueuePropertyDeserializer by not existing key", provider.unregisterDeserializer(key10));
+        Assert.assertFalse("Wrong -- unregister QueuePropertyDeserializer by not existing key",
+                provider.unregisterDeserializer(key10));
         // -- registerMeterBandDeserializer
         final ExperimenterIdDeserializerKey key11
             = new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MeterBandExperimenterCase.class);
         provider.registerMeterBandDeserializer(key11, deserializerMeterBandExpCase);
         Assert.assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11));
-        Assert.assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key", provider.unregisterDeserializer(key11));
+        Assert.assertFalse("Wrong -- unregister MeterBandDeserializer by not existing key",
+                provider.unregisterDeserializer(key11));
         // -- registerExperimenterMessageSerializer
         ExperimenterIdSerializerKey<ExperimenterDataOfChoice> key12
-                = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterDataOfChoice.class);
+                = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L,
+                        ExperimenterDataOfChoice.class);
         provider.registerExperimenterMessageSerializer(key12, serializerExperimenterInput);
         Assert.assertTrue("Wrong -- unregister ExperimenterMessageSerializer", provider.unregisterSerializer(key12));
-        Assert.assertFalse("Wrong -- unregister ExperimenterMessageSerializer by not existing key", provider.unregisterSerializer(key12));
+        Assert.assertFalse("Wrong -- unregister ExperimenterMessageSerializer by not existing key",
+                provider.unregisterSerializer(key12));
         //registerMultipartRequestSerializer
         ExperimenterIdSerializerKey<ExperimenterDataOfChoice> key13
-                = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterDataOfChoice.class);
+                = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID, 42L,
+                        ExperimenterDataOfChoice.class);
         provider.registerMultipartRequestSerializer(key13, serializerMultipartRequestExpCase);
         Assert.assertTrue("Wrong -- unregister MultipartRequestSerializer", provider.unregisterSerializer(key13));
-        Assert.assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key", provider.unregisterSerializer(key13));
+        Assert.assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key",
+                provider.unregisterSerializer(key13));
         // -- registerMultipartRequestTFSerializer
         final ExperimenterIdSerializerKey<TableFeatureProperties> key14
             = new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,TableFeatureProperties.class);
         provider.registerMultipartRequestTFSerializer(key14, serializer);
         Assert.assertTrue("Wrong -- unregister MultipartRequestTFSerializer", provider.unregisterSerializer(key14));
-        Assert.assertFalse("Wrong -- unregister MultipartRequestTFSerializer by not existing key", provider.unregisterSerializer(key14));
+        Assert.assertFalse("Wrong -- unregister MultipartRequestTFSerializer by not existing key",
+                provider.unregisterSerializer(key14));
         // -- registerMeterBandSerializer
         final ExperimenterIdMeterSubTypeSerializerKey<MeterBandExperimenterCase> key15
-            = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,MeterBandExperimenterCase.class,null);
+            = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,
+                    MeterBandExperimenterCase.class,null);
         provider.registerMeterBandSerializer(key15, serializerMeterBandExpCase);
         Assert.assertTrue("Wrong -- unregister MeterBandSerializer", provider.unregisterSerializer(key15));
-        Assert.assertFalse("Wrong -- unregister MeterBandSerializer by not existing key", provider.unregisterSerializer(key15));
+        Assert.assertFalse("Wrong -- unregister MeterBandSerializer by not existing key",
+                provider.unregisterSerializer(key15));
         // -- registerMatchEntrySerializer
         final MatchEntrySerializerKey<OpenflowBasicClass, InPort> key16
             = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
         provider.registerMatchEntrySerializer(key16, serializer);
         Assert.assertTrue("Wrong -- unregister MatchEntrySerializer", provider.unregisterSerializer(key16));
-        Assert.assertFalse("Wrong -- unregister MatchEntrySerializer by not existing key", provider.unregisterSerializer(key15));
+        Assert.assertFalse("Wrong -- unregister MatchEntrySerializer by not existing key",
+                provider.unregisterSerializer(key15));
         // -- registerSerializer
         final MessageTypeKey key17 = new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, TestSubType.class);
         provider.registerSerializer(key17, serializer);
index 7a8add5072e8c44ea7652760784fe3d0347ad9be..9674f4fd079b8822ecf112872643be1f407dc932 100644 (file)
@@ -27,10 +27,12 @@ import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionPro
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
+import org.slf4j.LoggerFactory;
 
 /**
- * @author michal.polkorab
+ * Unit tests for SwitchConnectionProviderImpl.
  *
+ * @author michal.polkorab
  */
 public class SwitchConnectionProviderImplTest {
 
@@ -38,16 +40,15 @@ public class SwitchConnectionProviderImplTest {
 
     private static final int SWITCH_IDLE_TIMEOUT = 2000;
     private static final int WAIT_TIMEOUT = 2000;
-    private InetAddress startupAddress;
     private TlsConfiguration tlsConfiguration;
     private SwitchConnectionProviderImpl provider;
     private ConnectionConfigurationImpl config;
 
     /**
-     * Creates new {@link SwitchConnectionProvider} instance for each test
+     * Creates new {@link SwitchConnectionProvider} instance for each test.
      * @param protocol communication protocol
      */
-    public void startUp(final TransportProtocol protocol) {
+    public void startUp(final TransportProtocol protocol) throws UnknownHostException {
         MockitoAnnotations.initMocks(this);
         config = null;
         if (protocol != null) {
@@ -56,12 +57,9 @@ public class SwitchConnectionProviderImplTest {
         provider = new SwitchConnectionProviderImpl(config);
     }
 
-    private void createConfig(final TransportProtocol protocol) {
-        try {
-            startupAddress = InetAddress.getLocalHost();
-        } catch (final UnknownHostException e) {
-            e.printStackTrace();
-        }
+    private void createConfig(final TransportProtocol protocol) throws UnknownHostException {
+        InetAddress startupAddress = InetAddress.getLocalHost();
+
         tlsConfiguration = null;
         if (protocol.equals(TransportProtocol.TLS)) {
             tlsConfiguration = new TlsConfigurationImpl(KeystoreType.JKS,
@@ -74,7 +72,7 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests provider startup - without configuration and {@link SwitchConnectionHandler}
+     * Tests provider startup - without configuration and {@link SwitchConnectionHandler}.
      */
     @Test
     public void testStartup1() {
@@ -88,10 +86,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests provider startup - without configuration
+     * Tests provider startup - without configuration.
      */
     @Test
-    public void testStartup2() {
+    public void testStartup2() throws UnknownHostException {
         startUp(null);
         provider.setSwitchConnectionHandler(handler);
         final ListenableFuture<Boolean> future = provider.startup();
@@ -103,10 +101,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests provider startup - without {@link SwitchConnectionHandler}
+     * Tests provider startup - without {@link SwitchConnectionHandler}.
      */
     @Test
-    public void testStartup3() {
+    public void testStartup3() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         final ListenableFuture<Boolean> future = provider.startup();
         try {
@@ -118,10 +116,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests correct provider startup - over TCP
+     * Tests correct provider startup - over TCP.
      */
     @Test
-    public void testStartup4() {
+    public void testStartup4() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         provider.setSwitchConnectionHandler(handler);
         try {
@@ -132,10 +130,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests correct provider startup - over TLS
+     * Tests correct provider startup - over TLS.
      */
     @Test
-    public void testStartup5() {
+    public void testStartup5() throws UnknownHostException {
         startUp(TransportProtocol.TLS);
         provider.setSwitchConnectionHandler(handler);
         try {
@@ -146,10 +144,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests correct provider startup - over UDP
+     * Tests correct provider startup - over UDP.
      */
     @Test
-    public void testStartup6() {
+    public void testStartup6() throws UnknownHostException {
         startUp(TransportProtocol.UDP);
         provider.setSwitchConnectionHandler(handler);
         try {
@@ -157,21 +155,21 @@ public class SwitchConnectionProviderImplTest {
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             Assert.fail();
         }
-        }
+    }
 
     /**
-     * Tests correct provider shutdown
+     * Tests correct provider shutdown.
      */
     @Test
-    public void testShutdown() {
+    public void testShutdown() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         provider.setSwitchConnectionHandler(handler);
         try {
             Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
             Assert.assertTrue("Failed to stop", provider.shutdown().get(5 * WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
-            e.printStackTrace();
+            LoggerFactory.getLogger(SwitchConnectionProviderImplTest.class).error("Unexpected error", e);
         }
     }
 
-}
\ No newline at end of file
+}
index 72bbe8e08151a571de51050662fea80628d41c7c..b22530b91bf7f0e7d7dba6b9d337db92d196ebf4 100644 (file)
@@ -24,8 +24,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * @author madamjak
+ * Unit tests for UdpHandler.
  *
+ * @author madamjak
  */
 public class UdpHandlerTest {
 
@@ -34,8 +35,9 @@ public class UdpHandlerTest {
     @Mock
     private UdpChannelInitializer udpChannelInitializerMock;
     private UdpHandler udpHandler;
+
     /**
-     * Mock init
+     * Mock init.
      */
     @Before
     public void startUp() {
@@ -43,10 +45,7 @@ public class UdpHandlerTest {
     }
 
     /**
-     * Test to create UdpHandler with empty address and zero port
-     * @throws InterruptedException
-     * @throws ExecutionException
-     * @throws IOException
+     * Test to create UdpHandler with empty address and zero port.
      */
     @Test
     public void testWithEmptyAddress() throws Exception {
@@ -63,10 +62,7 @@ public class UdpHandlerTest {
     }
 
     /**
-     * Test to create UdpHandler with empty address and zero port on Epoll native transport
-     * @throws InterruptedException
-     * @throws ExecutionException
-     * @throws IOException
+     * Test to create UdpHandler with empty address and zero port on Epoll native transport.
      */
     @Test
     public void testWithEmptyAddressOnEpoll() throws Exception {
@@ -83,13 +79,10 @@ public class UdpHandlerTest {
     }
 
     /**
-     * Test to create UdpHandler with fill address and given port
-     * @throws InterruptedException
-     * @throws ExecutionException
-     * @throws IOException
+     * Test to create UdpHandler with fill address and given port.
      */
     @Test
-    public void testWithAddressAndPort() throws Exception{
+    public void testWithAddressAndPort() throws Exception {
         int port = 9874;
         udpHandler = new UdpHandler(InetAddress.getLocalHost(), port);
         udpHandler.setChannelInitializer(udpChannelInitializerMock);
@@ -104,10 +97,7 @@ public class UdpHandlerTest {
     }
 
     /**
-     * Test to create UdpHandler with fill address and given port on Epoll native transport
-     * @throws InterruptedException
-     * @throws ExecutionException
-     * @throws IOException
+     * Test to create UdpHandler with fill address and given port on Epoll native transport.
      */
     @Test
     public void testWithAddressAndPortOnEpoll() throws Exception {
@@ -124,18 +114,18 @@ public class UdpHandlerTest {
         shutdownServer();
     }
 
-    private Boolean startupServer(final boolean isEpollEnabled) throws InterruptedException, IOException, ExecutionException {
+    private Boolean startupServer(final boolean isEpollEnabled)
+            throws InterruptedException, IOException, ExecutionException {
         ListenableFuture<Boolean> online = udpHandler.getIsOnlineFuture();
         /**
          * Test EPoll based native transport if isEpollEnabled is true.
          * Else use Nio based transport.
          */
         udpHandler.initiateEventLoopGroups(null, isEpollEnabled);
-        (new Thread(udpHandler)).start();
+        new Thread(udpHandler).start();
 
-        boolean startedSuccessfully = false;
         try {
-            startedSuccessfully = online.get(10, TimeUnit.SECONDS);
+            online.get(10, TimeUnit.SECONDS);
         } catch (TimeoutException e) {
             LOG.warn("Timeout while waiting for UDP handler to start", e);
         }
index df4c7e980a7543b851c29b81b494c4acba014820..b9e854e88b04da0fa544278d4641dde40c5f62ac 100644 (file)
@@ -10,21 +10,18 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection;
 
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
-
 import java.net.InetSocketAddress;
-
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.UdpMessageListenerWrapper;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 
 /**
+ * Unit tests for UdpMessageListenerWrapper.
  *
  * @author madamjak
- *
  */
 public class UdpMessageListenerWrapperTest {
 
@@ -32,16 +29,17 @@ public class UdpMessageListenerWrapperTest {
     @Mock OfHeader msg;
 
     @Before
-    public void startUp(){
+    public void startUp() {
         MockitoAnnotations.initMocks(this);
     }
+
     /**
-     * Getters test
+     * Getters test.
      */
     @Test
-    public void test(){
+    public void test() {
         int port = 9876;
-        String host ="localhost";
+        String host = "localhost";
         InetSocketAddress inetSockAddr = InetSocketAddress.createUnresolved(host, port);
         UdpMessageListenerWrapper wrapper = new UdpMessageListenerWrapper(msg,listener,inetSockAddr);
 
@@ -49,5 +47,4 @@ public class UdpMessageListenerWrapperTest {
         Assert.assertEquals("Wrong getListener", listener, wrapper.getListener());
         Assert.assertEquals("Wrong getMsg", msg, wrapper.getMsg());
     }
-
 }