Fix ALOTOF Checkstyle violation, and switch over to enforcement.
[ovsdb.git] / library / impl / src / test / java / org / opendaylight / ovsdb / lib / jsonrpc / TestClient.java
index 22b1285f0b50f187b5f6d3eb2f1fa72d396cb660..915caf19c138bcdae690e04c934ab01e95278594 100644 (file)
@@ -4,99 +4,91 @@
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Authors : Aswin Raveendran
  */
 package org.opendaylight.ovsdb.lib.jsonrpc;
 
 import io.netty.handler.logging.LogLevel;
 import io.netty.handler.logging.LoggingHandler;
-import junit.framework.TestCase;
-import org.junit.Test;
-
-import java.io.OutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.net.Socket;
+import junit.framework.TestCase;
+import org.junit.Test;
 
 public class TestClient extends TestCase {
 
-        String serverurl = "127.0.0.1";
-        NettyBootStrapper bootstrapper = new NettyBootStrapper();
-        JsonRpcDecoder jsonRpcDecoder = new JsonRpcDecoder(100000);
-
-        public void setupServer() throws Exception {
-            bootstrapper.startServer(0,
-                    jsonRpcDecoder,
-                    new LoggingHandler(LogLevel.DEBUG));
-        }
+    String serverurl = "127.0.0.1";
+    NettyBootStrapper bootstrapper = new NettyBootStrapper();
+    JsonRpcDecoder jsonRpcDecoder = new JsonRpcDecoder(100000);
 
-        public void shutDownServer() throws InterruptedException {
-            bootstrapper.stopServer();
-        }
-
-        /**
-         * Testing appropriate ChannelHandler integration for
-         * JsonRpcDecoder, so that JSON strings written using an
-         * OutputStream connected to a ServerSocket of a Netty
-         * ServerBootstrap can be decoded properly.
-         */
-        @Test
-        public void testBasicFlow() throws Exception {
-            setupServer();
-            Socket socket = new Socket(serverurl, bootstrapper.getServerPort());
-            OutputStream outputStream = socket.getOutputStream();
-
-            int records = 20;
+    public void setupServer() throws Exception {
+        bootstrapper.startServer(0, jsonRpcDecoder, new LoggingHandler(LogLevel.DEBUG));
+    }
 
-            for (int i = 0; i < records; i++) {
-                writeJson(outputStream, 1);
-                writePartialFirst(outputStream);
-                outputStream.flush();
-                Thread.sleep(10);
-                writePartialLast(outputStream);
-            }
-            socket.close();
-            shutDownServer();
+    public void shutDownServer() throws InterruptedException {
+        bootstrapper.stopServer();
+    }
 
-            assertEquals("mismatch in records processed", records * 2, jsonRpcDecoder.getRecordsRead());
+    /**
+     * Testing appropriate ChannelHandler integration for JsonRpcDecoder, so that JSON strings written using an
+     * OutputStream connected to a ServerSocket of a Netty ServerBootstrap can be decoded properly.
+     */
+    @Test
+    public void testBasicFlow() throws Exception {
+        setupServer();
+        Socket socket = new Socket(serverurl, bootstrapper.getServerPort());
+        OutputStream outputStream = socket.getOutputStream();
+
+        int records = 20;
+
+        for (int i = 0; i < records; i++) {
+            writeJson(outputStream, 1);
+            writePartialFirst(outputStream);
+            outputStream.flush();
+            Thread.sleep(10);
+            writePartialLast(outputStream);
         }
+        socket.close();
+        shutDownServer();
+
+        assertEquals("mismatch in records processed", records * 2, jsonRpcDecoder.getRecordsRead());
+    }
 
     static int counter = 0;
 
-    /*
-       create and write a json string for specified number of times
+    /**
+     * Create and write a json string for specified number of times.
      */
     private void writeJson(OutputStream outputStream, int times) throws IOException {
         outputStream.write("{".getBytes("UTF-8"));
-        for (int i = 0 ; i < times; i ++) {
+        for (int i = 0; i < times; i++) {
             counter++;
-            String s = ",\"key1"+ counter +"\":\"planet of apes" + counter +
-                    "\", \"key2"+ counter +"\":{\"k1\":\"ovs-db rocks the world\"}";
-            outputStream.write(s.substring(i == 0 ? 1 : 0).getBytes("UTF-8"));
-            System.out.println("data counter = " + counter);
+            String string = ",\"key1" + counter + "\":\"planet of apes" + counter + "\", \"key2" + counter
+                    "\":{\"k1\":\"ovs-db rocks the world\"}";
+            outputStream.write(string.substring(i == 0 ? 1 : 0).getBytes("UTF-8"));
+            // System.out.println("data counter = " + counter);
         }
         outputStream.write("}".getBytes("UTF-8"));
     }
 
-    /*
-      writes a partial json and flush to simulate the case where netty gets half the message and
-      has to frame it accordingly.
+    /**
+     * Writes a partial JSON and flush to simulate the case where netty gets half the message and has to frame it
+     * accordingly.
      */
     private void writePartialFirst(OutputStream outputStream) throws IOException {
         counter++;
-        String s  = "                       {\"part"+ counter+"\":";
-        outputStream.write(s.getBytes("UTF-8"));
-        System.out.println("partial first half counter = " + counter);
+        String string = "                       {\"part" + counter + "\":";
+        outputStream.write(string.getBytes("UTF-8"));
+        // System.out.println("partial first half counter = " + counter);
     }
 
-    /*
-      finishes the json started by writePartialFirst
+    /**
+     * Finishes the JSON started by writePartialFirst.
      */
     private void writePartialLast(OutputStream outputStream) throws IOException {
-        String s  = "\"val"+ counter+"\"}";
-        outputStream.write(s.getBytes("UTF-8"));
-        System.out.println("partial second half counter = " + counter);
+        String string = "\"val" + counter + "\"}";
+        outputStream.write(string.getBytes("UTF-8"));
+        // System.out.println("partial second half counter = " + counter);
     }
 
 }
-