This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 62b20e8  improve tests stability (#485)
62b20e8 is described below

commit 62b20e87b46bfcdcee48f8f7cb509bc3bc05a230
Author: Alexey Markevich <[email protected]>
AuthorDate: Thu Dec 20 18:30:27 2018 +0300

    improve tests stability (#485)
    
    * cxf-core: improve AutomaticWorkQueueTest stability
    
    * cxf-tools-corba: improve WSDLToIDLTest stability
---
 .../cxf/workqueue/AutomaticWorkQueueTest.java      | 100 ++++-------
 .../corba/processors/wsdl/WSDLToIDLAction.java     |  59 ++++---
 .../org/apache/cxf/tools/corba/IDLToWSDLTest.java  |  74 ++++----
 .../org/apache/cxf/tools/corba/WSDLToIDLTest.java  | 193 ++++++++++-----------
 .../cxf/tools/corba/common/ToolTestBase.java       |   4 +-
 5 files changed, 190 insertions(+), 240 deletions(-)

diff --git 
a/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java 
b/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
index 92c7434..988678c 100644
--- a/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
+++ b/core/src/test/java/org/apache/cxf/workqueue/AutomaticWorkQueueTest.java
@@ -20,6 +20,7 @@
 package org.apache.cxf.workqueue;
 
 import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
@@ -40,7 +41,7 @@ public class AutomaticWorkQueueTest extends Assert {
     public static final int DEFAULT_LOW_WATER_MARK = 1;
     public static final long DEFAULT_DEQUEUE_TIMEOUT = 2 * 60 * 1000L;
 
-    public static final int TIMEOUT = 100;
+    public static final long TIMEOUT = 100L;
 
     AutomaticWorkQueueImpl workqueue;
 
@@ -95,7 +96,7 @@ public class AutomaticWorkQueueTest extends Assert {
                                 //just need to wait until all the runnables 
are created and enqueued and such.
                             }
                         }
-                    }, 50);
+                    }, 50L);
                 }
             }
             fail("Should have failed with a RejectedExecutionException as 5th 
should not be queuable");
@@ -107,17 +108,13 @@ public class AutomaticWorkQueueTest extends Assert {
 
 
     @Test
-    public void testEnqueue() {
+    public void testEnqueue() throws InterruptedException {
         workqueue = new AutomaticWorkQueueImpl(DEFAULT_MAX_QUEUE_SIZE, 
INITIAL_SIZE,
                                                DEFAULT_HIGH_WATER_MARK,
                                                DEFAULT_LOW_WATER_MARK,
                                                DEFAULT_DEQUEUE_TIMEOUT);
 
-        try {
-            Thread.sleep(100);
-        } catch (Exception e) {
-            // ignore
-        }
+        Thread.sleep(100L);
 
         // We haven't enqueued anything yet, so should be zero
         assertEquals(0, workqueue.getSize());
@@ -134,16 +131,12 @@ public class AutomaticWorkQueueTest extends Assert {
         // Give threads a chance to dequeue (5sec max)
         int i = 0;
         while (workqueue.getSize() != 0 && i++ < 50) {
-            try {
-                Thread.sleep(100);
-            } catch (InterruptedException ie) {
-                // ignore
-            }
+            Thread.sleep(100L);
         }
         assertEquals(0, workqueue.getSize());
     }
 
-    int numRunning(BlockingWorkItem[] workItems) {
+    static int numRunning(BlockingWorkItem[] workItems) {
         int count = 0;
         for (BlockingWorkItem item : workItems) {
             if (item.isRunning()) {
@@ -153,17 +146,13 @@ public class AutomaticWorkQueueTest extends Assert {
         return count;
     }
     @Test
-    public void testEnqueueImmediate() {
+    public void testEnqueueImmediate() throws InterruptedException {
         workqueue = new AutomaticWorkQueueImpl(DEFAULT_MAX_QUEUE_SIZE, 
INITIAL_SIZE,
                                                DEFAULT_HIGH_WATER_MARK,
                                                DEFAULT_LOW_WATER_MARK,
                                                DEFAULT_DEQUEUE_TIMEOUT);
 
-        try {
-            Thread.sleep(100);
-        } catch (Exception e) {
-            // ignore
-        }
+        Thread.sleep(100L);
 
         // We haven't enqueued anything yet, so should there shouldn't be
         // any items on the queue, the thread pool should still be the
@@ -194,13 +183,8 @@ public class AutomaticWorkQueueTest extends Assert {
                     || numRun < DEFAULT_HIGH_WATER_MARK 
                     || workqueue.getSize() > 0)
                 && max < 10) {
-                try {
-                    //wait up to a second for all the threads to start and 
grab items
-                    Thread.sleep(100);
-                    max++;
-                } catch (InterruptedException ex) {
-                    // ignore
-                }
+                //wait up to a second for all the threads to start and grab 
items
+                Thread.sleep(100L);
                 numRun = numRunning(workItems);
             }
             numRun = numRunning(workItems);
@@ -233,11 +217,7 @@ public class AutomaticWorkQueueTest extends Assert {
             workItems[0] = new BlockingWorkItem();
 
             for (int i = 0; i < 20 && !accepted; i++) {
-                try {
-                    Thread.sleep(100);
-                } catch (InterruptedException ex) {
-                    // ignore
-                }
+                Thread.sleep(100L);
                 try {
                     workqueue.execute(workItems[0]);
                     accepted = true;
@@ -261,7 +241,7 @@ public class AutomaticWorkQueueTest extends Assert {
     }
 
     @Test
-    public void testDeadLockEnqueueLoads() {
+    public void testDeadLockEnqueueLoads() throws InterruptedException {
         workqueue = new AutomaticWorkQueueImpl(500, 1, 2, 2,
                                                DEFAULT_DEQUEUE_TIMEOUT);
         DeadLockThread dead = new DeadLockThread(workqueue, 200,
@@ -271,7 +251,7 @@ public class AutomaticWorkQueueTest extends Assert {
     }
 
     @Test
-    public void testNonDeadLockEnqueueLoads() {
+    public void testNonDeadLockEnqueueLoads() throws InterruptedException {
         workqueue = new AutomaticWorkQueueImpl(UNBOUNDED_MAX_QUEUE_SIZE,
                                                INITIAL_SIZE,
                                                UNBOUNDED_HIGH_WATER_MARK,
@@ -302,7 +282,7 @@ public class AutomaticWorkQueueTest extends Assert {
             }
         };
 
-        workqueue.schedule(doNothing, 5000);
+        workqueue.schedule(doNothing, 5000L);
 
         runLock.lock();
         try {
@@ -312,11 +292,11 @@ public class AutomaticWorkQueueTest extends Assert {
         }
 
         assertTrue("expected delay",
-                   System.currentTimeMillis() - start >= 4950);
+                   System.currentTimeMillis() - start >= 4950L);
     }
 
     @Test
-    public void testThreadPoolShrink() {
+    public void testThreadPoolShrink() throws InterruptedException {
         workqueue = new AutomaticWorkQueueImpl(UNBOUNDED_MAX_QUEUE_SIZE, 20, 
20, 10, 100L);
 
         DeadLockThread dead = new DeadLockThread(workqueue, 1000, 5L);
@@ -326,11 +306,7 @@ public class AutomaticWorkQueueTest extends Assert {
         // Give threads a chance to dequeue (5sec max)
         int i = 0;
         while (workqueue.getPoolSize() > 10 && i++ < 50) {
-            try {
-                Thread.sleep(100);
-            } catch (InterruptedException ie) {
-                // ignore
-            }
+            Thread.sleep(100L);
         }
 //        if (System.getProperty("java.version").startsWith("1.6")
 //            || System.getProperty("java.vendor").startsWith("IBM")) {
@@ -360,14 +336,14 @@ public class AutomaticWorkQueueTest extends Assert {
                 last = workqueue.getPoolSize();
                 i = 0;
             }
-            Thread.sleep(100);
+            Thread.sleep(100L);
         }
         int sz = workqueue.getPoolSize();
         assertTrue("threads_total(): " + sz, workqueue.getPoolSize() <= 
DEFAULT_LOW_WATER_MARK);
     }
 
     @Test
-    public void testShutdown() {
+    public void testShutdown() throws InterruptedException {
         workqueue = new AutomaticWorkQueueImpl(DEFAULT_MAX_QUEUE_SIZE, 
INITIAL_SIZE,
                                                INITIAL_SIZE, INITIAL_SIZE, 
500);
 
@@ -380,11 +356,7 @@ public class AutomaticWorkQueueTest extends Assert {
 
         // Give threads a chance to shutdown (1 sec max)
         for (int i = 0; i < 20 && (workqueue.getSize() > 0 || 
workqueue.getPoolSize() > 0); i++) {
-            try {
-                Thread.sleep(250);
-            } catch (InterruptedException ie) {
-                // ignore
-            }
+            Thread.sleep(250L);
         }
         assertEquals(0, workqueue.getSize());
         assertEquals(0, workqueue.getPoolSize());
@@ -393,7 +365,7 @@ public class AutomaticWorkQueueTest extends Assert {
         workqueue = null;
     }
 
-    private void checkCompleted(DeadLockThread dead) {
+    private static void checkCompleted(DeadLockThread dead) throws 
InterruptedException {
         int oldCompleted = 0;
         int newCompleted = 0;
         int noProgressCount = 0;
@@ -415,20 +387,16 @@ public class AutomaticWorkQueueTest extends Assert {
                          + "\nof " + dead.getWorkItemCount());
                 }
             }
-            try {
-                Thread.sleep(250);
-            } catch (InterruptedException ie) {
-                // ignore
-            }
+            Thread.sleep(250L);
         }
     }
 
-    private void checkDeadLock(DeadLockThread dead) {
+    private static void checkDeadLock(DeadLockThread dead) throws 
InterruptedException {
         dead.start();
         checkCompleted(dead);
     }
 
-    public class TestWorkItem implements Runnable {
+    public static class TestWorkItem implements Runnable {
         String name;
         long worktime;
         Callback callback;
@@ -471,7 +439,7 @@ public class AutomaticWorkQueueTest extends Assert {
         }
     }
 
-    public class BlockingWorkItem implements Runnable {
+    public static class BlockingWorkItem implements Runnable {
         volatile boolean running;
         
         private boolean unblocked;
@@ -504,13 +472,13 @@ public class AutomaticWorkQueueTest extends Assert {
         void workItemCompleted(String name);
     }
 
-    public class DeadLockThread extends Thread implements Callback {
+    public static class DeadLockThread extends Thread implements Callback {
         public static final long DEFAULT_WORK_TIME = 10L;
         public static final int DEFAULT_WORK_ITEMS = 200;
 
         AutomaticWorkQueueImpl workqueue;
         int nWorkItems;
-        int nWorkItemsCompleted;
+        final AtomicInteger nWorkItemsCompleted = new AtomicInteger();
         long worktime;
         long finishTime;
         long startTime;
@@ -529,12 +497,12 @@ public class AutomaticWorkQueueTest extends Assert {
             worktime = wt;
         }
 
-        public synchronized boolean isFinished() {
-            return nWorkItemsCompleted == nWorkItems;
+        public boolean isFinished() {
+            return nWorkItemsCompleted.get() == nWorkItems;
         }
 
-        public synchronized void workItemCompleted(String name) {
-            nWorkItemsCompleted++;
+        public void workItemCompleted(String name) {
+            nWorkItemsCompleted.incrementAndGet();
             if (isFinished()) {
                 finishTime = System.currentTimeMillis();
             }
@@ -548,8 +516,8 @@ public class AutomaticWorkQueueTest extends Assert {
             return worktime;
         }
 
-        public synchronized int getWorkItemCompletedCount() {
-            return nWorkItemsCompleted;
+        public int getWorkItemCompletedCount() {
+            return nWorkItemsCompleted.get();
         }
 
         public long finishTime() {
diff --git 
a/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/wsdl/WSDLToIDLAction.java
 
b/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/wsdl/WSDLToIDLAction.java
index a7d8b22..03a2cdc 100644
--- 
a/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/wsdl/WSDLToIDLAction.java
+++ 
b/tools/corba/src/main/java/org/apache/cxf/tools/corba/processors/wsdl/WSDLToIDLAction.java
@@ -117,40 +117,39 @@ public class WSDLToIDLAction {
         if (printWriter == null) {
             printWriter = createPrintWriter(outputFile);
         }
-
-        if (!isGenerateAllBindings()) {
-            Binding binding = findBinding(def);
-            if (binding == null) {
-                String msgStr = "Binding " + bindingName + " doesn't exists in 
WSDL.";
-                org.apache.cxf.common.i18n.Message msg = new 
org.apache.cxf.common.i18n.Message(msgStr, LOG);
-                throw new Exception(msg.toString());
-            }
-            generateIDL(def, binding);
-        } else {
-            // generate idl for all bindings in the file.
-            // each idl file will have the name of the binding.
-            Collection<Binding> bindings = 
CastUtils.cast(def.getAllBindings().values());
-            if (bindings.isEmpty()) {
-                String msgStr = "No bindings exists within this WSDL.";
-                org.apache.cxf.common.i18n.Message msg = new 
org.apache.cxf.common.i18n.Message(msgStr, LOG);
-                throw new Exception(msg.toString());
-            }
-            List<QName> portTypes = new ArrayList<>();
-            for (Binding binding : bindings) {
-                List<?> ext = binding.getExtensibilityElements();
-                if (!(ext.get(0) instanceof BindingType)) {
-                    continue;
-                }
-                if (portTypes.contains(binding.getPortType().getQName())) {
-                    continue;
+        try (PrintWriter pw = printWriter != null ? printWriter : 
createPrintWriter(outputFile)) {
+            if (!isGenerateAllBindings()) {
+                Binding binding = findBinding(def);
+                if (binding == null) {
+                    String msgStr = "Binding " + bindingName + " doesn't 
exists in WSDL.";
+                    org.apache.cxf.common.i18n.Message msg = new 
org.apache.cxf.common.i18n.Message(msgStr, LOG);
+                    throw new Exception(msg.toString());
                 }
-                portTypes.add(binding.getPortType().getQName());
                 generateIDL(def, binding);
-                root = IdlRoot.create();
+            } else {
+                // generate idl for all bindings in the file.
+                // each idl file will have the name of the binding.
+                Collection<Binding> bindings = 
CastUtils.cast(def.getAllBindings().values());
+                if (bindings.isEmpty()) {
+                    String msgStr = "No bindings exists within this WSDL.";
+                    org.apache.cxf.common.i18n.Message msg = new 
org.apache.cxf.common.i18n.Message(msgStr, LOG);
+                    throw new Exception(msg.toString());
+                }
+                List<QName> portTypes = new ArrayList<>();
+                for (Binding binding : bindings) {
+                    List<?> ext = binding.getExtensibilityElements();
+                    if (!(ext.get(0) instanceof BindingType)) {
+                        continue;
+                    }
+                    if (portTypes.contains(binding.getPortType().getQName())) {
+                        continue;
+                    }
+                    portTypes.add(binding.getPortType().getQName());
+                    generateIDL(def, binding);
+                    root = IdlRoot.create();
+                }
             }
         }
-        printWriter.close();
-
     }
 
     private void generateIDL(Definition definition, Binding binding) {
diff --git 
a/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java 
b/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java
index c870873..30acda7 100644
--- a/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java
+++ b/tools/corba/src/test/java/org/apache/cxf/tools/corba/IDLToWSDLTest.java
@@ -26,7 +26,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileWriter;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
@@ -65,7 +64,7 @@ public class IDLToWSDLTest extends ToolTestBase {
     }
 
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
         super.setUp();
         try {
             TestUtils utils = new TestUtils(IDLToWSDL.TOOL_NAME, 
IDLToWSDL.class
@@ -88,15 +87,12 @@ public class IDLToWSDLTest extends ToolTestBase {
         }
     }
 
-    private void deleteDir(File dir) throws IOException {
-        FileUtils.removeDir(dir);
-    }
-
     @After
-    public void tearDown() {
+    public void tearDown() throws Exception {
+        // super.tearDown();
         try {
-            deleteDir(output);
-        } catch (IOException ex) {
+            FileUtils.removeDir(output);
+        } catch (Exception e) {
             //ignore
         }
         output = null;
@@ -113,28 +109,26 @@ public class IDLToWSDLTest extends ToolTestBase {
     }
 
     private void checkStrings(byte[] orig, byte[] generated) throws Exception {
-        BufferedReader origReader = new BufferedReader(new 
InputStreamReader(new ByteArrayInputStream(orig)));
-        BufferedReader genReader =
-            new BufferedReader(new InputStreamReader(
-                       new ByteArrayInputStream(generated)));
-
-        String sorig = origReader.readLine();
-        String sgen = genReader.readLine();
-
-        while (sorig != null && sgen != null) {
-            if (!sorig.equals(sgen)) {
-                //assertEquals(sorig, sgen);
-                //sorig = origReader.readLine();
-                sgen = genReader.readLine();
-            } else {
-                assertEquals(sorig, sgen);
-                sorig = null;
-                sgen = null;
-                break;
+        try (BufferedReader origReader = new BufferedReader(new 
InputStreamReader(new ByteArrayInputStream(orig)));
+                BufferedReader genReader = new BufferedReader(
+                        new InputStreamReader(new 
ByteArrayInputStream(generated)))) {
+
+            String sorig = origReader.readLine();
+            String sgen = genReader.readLine();
+    
+            while (sorig != null && sgen != null) {
+                if (!sorig.equals(sgen)) {
+                    //assertEquals(sorig, sgen);
+                    //sorig = origReader.readLine();
+                    sgen = genReader.readLine();
+                } else {
+                    assertEquals(sorig, sgen);
+                    sorig = null;
+                    sgen = null;
+                    break;
+                }
             }
         }
-        origReader.close();
-        genReader.close();
     }
 
     @Test
@@ -243,17 +237,17 @@ public class IDLToWSDLTest extends ToolTestBase {
 
         // create temporary file containing ior
         File addressFile = new File(output, "HelloWorld.idl");
-        FileWriter addressFileWriter = new FileWriter(addressFile);
-        addressFileWriter.write(
-            "IOR:010000001400000049444c3a48656c6c6f576f726c64493a312e300002"
-            + "0000000000000080000000010101001e0000006d766573636f76692e6475"
-            + "626c696e2e656d65612e696f6e612e636f6d0022064d0000003a5c6d7665"
-            + "73636f76692e6475626c696e2e656d65612e696f6e612e636f6d3a48656c"
-            + "6c6f576f726c642f48656c6c6f576f726c643a6d61726b65723a3a49523a"
-            + "48656c6c6f576f726c644900000000000000000100000018000000010000"
-            + "0001000000000000000800000001000000305f5449"
-        );
-        addressFileWriter.close();
+        try (FileWriter addressFileWriter = new FileWriter(addressFile)) {
+            addressFileWriter.write(
+                
"IOR:010000001400000049444c3a48656c6c6f576f726c64493a312e300002"
+                + 
"0000000000000080000000010101001e0000006d766573636f76692e6475"
+                + 
"626c696e2e656d65612e696f6e612e636f6d0022064d0000003a5c6d7665"
+                + 
"73636f76692e6475626c696e2e656d65612e696f6e612e636f6d3a48656c"
+                + 
"6c6f576f726c642f48656c6c6f576f726c643a6d61726b65723a3a49523a"
+                + 
"48656c6c6f576f726c644900000000000000000100000018000000010000"
+                + "0001000000000000000800000001000000305f5449"
+            );
+        }
         addressFile.deleteOnExit();
 
         String[] args = new String[] {"-f", addressFile.toString(),
diff --git 
a/tools/corba/src/test/java/org/apache/cxf/tools/corba/WSDLToIDLTest.java 
b/tools/corba/src/test/java/org/apache/cxf/tools/corba/WSDLToIDLTest.java
index 753b671..0d7cea4 100644
--- a/tools/corba/src/test/java/org/apache/cxf/tools/corba/WSDLToIDLTest.java
+++ b/tools/corba/src/test/java/org/apache/cxf/tools/corba/WSDLToIDLTest.java
@@ -22,19 +22,19 @@ package org.apache.cxf.tools.corba;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
 import java.nio.charset.StandardCharsets;
-import java.nio.file.FileSystems;
+import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
 
 import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
 
-import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.tools.corba.common.ToolTestBase;
 import org.apache.cxf.tools.corba.processors.wsdl.WSDLToProcessor;
 import org.apache.cxf.tools.corba.utils.TestUtils;
@@ -46,98 +46,87 @@ import org.junit.Test;
 public class WSDLToIDLTest extends ToolTestBase {
 
     private static String usage;
-    private static int noError;
-    private static int error = -1;
     ByteArrayOutputStream bout;
-    PrintStream newOut;
-    private File output;
+    private Path output;
 
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
         super.setUp();
-        try {
-            TestUtils utils = new TestUtils(WSDLToIDL.TOOL_NAME, 
WSDLToIDL.class
-                .getResourceAsStream("/toolspecs/wsdl2idl.xml"));
-            usage = utils.getUsage();
-            bout = new ByteArrayOutputStream();
-            newOut = new PrintStream(bout);
-            System.setOut(newOut);
-            System.setErr(newOut);
-        } catch (Exception e) {
-            // complete
-        }
 
-        try {
-            output = new File(getClass().getResource(".").toURI());
-            output = new File(output, "generated-idl");
-            FileUtils.mkDir(output);
-        } catch (Exception e) {
-            // complete
-        }
-    }
+        TestUtils utils = new TestUtils(WSDLToIDL.TOOL_NAME, WSDLToIDL.class
+            .getResourceAsStream("/toolspecs/wsdl2idl.xml"));
+        usage = utils.getUsage();
+        bout = new ByteArrayOutputStream();
+        PrintStream newOut = new PrintStream(bout);
+        System.setOut(newOut);
+        System.setErr(newOut);
 
-    private void deleteDir(File dir) throws IOException {
-        FileUtils.removeDir(dir);
+        output = Files.createTempDirectory("wsdl2idl");
     }
 
     @After
-    public void tearDown() {
-        try {
-            deleteDir(output);
-        } catch (IOException ex) {
-            //ignore
-        }
+    public void tearDown() throws Exception {
+        super.tearDown();
+
+        Files.walkFileTree(output, new SimpleFileVisitor<Path>() {
+            @Override
+            public FileVisitResult visitFile(Path file, BasicFileAttributes 
attrs) throws IOException {
+                Files.delete(file);
+                return FileVisitResult.CONTINUE;
+            }
+            @Override
+            public FileVisitResult postVisitDirectory(Path dir, IOException 
exc) throws IOException {
+                Files.delete(dir);
+                return FileVisitResult.CONTINUE;
+            }
+        });
         output = null;
     }
 
-    private int execute(String[] args) throws Exception {
+    private static String execute(String[] args) {
         try {
             WSDLToIDL.run(args);
         } catch (Exception ex) {
-            return -1;
+            return ex.getMessage();
         }
-        return 0;
+        return null;
     }
 
-    private void checkStrings(byte[] orig, byte[] generated) throws Exception {
-        BufferedReader origReader = new BufferedReader(new 
InputStreamReader(new ByteArrayInputStream(orig)));
-        BufferedReader genReader =
-            new BufferedReader(new InputStreamReader(
-                       new ByteArrayInputStream(generated)));
-
-        String sorig = origReader.readLine();
-        String sgen = genReader.readLine();
-
-        while (sorig != null && sgen != null) {
-            if (!sorig.equals(sgen)) {
-                //assertEquals(sorig, sgen);
-                //sorig = origReader.readLine();
-                sgen = genReader.readLine();
-            } else {
-                assertEquals(sorig, sgen);
-                sorig = null;
-                sgen = null;
-                break;
+    private static void checkStrings(byte[] orig, byte[] generated) throws 
IOException {
+        try (BufferedReader origReader = new BufferedReader(new 
InputStreamReader(new ByteArrayInputStream(orig)));
+                BufferedReader genReader = new BufferedReader(
+                        new InputStreamReader(new 
ByteArrayInputStream(generated)))) {
+
+            String sorig = origReader.readLine();
+            String sgen = genReader.readLine();
+
+            while (sorig != null && sgen != null) {
+                if (!sorig.equals(sgen)) {
+                    // assertEquals(sorig, sgen);
+                    // sorig = origReader.readLine();
+                    sgen = genReader.readLine();
+                } else {
+                    assertEquals(sorig, sgen);
+                    sorig = origReader.readLine();
+                }
             }
         }
-        origReader.close();
-        genReader.close();
     }
 
     @Test
     public void testBindingGenDefault() throws Exception {
         String[] cmdArgs = {"-corba", "-i", "BasePortType",
-                            "-d", output.getCanonicalPath(),
+                            "-d", output.toString(),
                             
getClass().getResource("/wsdl/simpleList.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", noError, exc);
+        String error = execute(cmdArgs);
+        assertNull("WSDLToIDL Failed", error);
 
-        File f = new File(output, "simpleList-corba.wsdl");
-        assertTrue("simpleList-corba.wsdl should be generated", f.exists());
+        Path f = output.resolve("simpleList-corba.wsdl");
+        assertTrue("simpleList-corba.wsdl should be generated", 
Files.exists(f));
 
         WSDLToProcessor proc = new WSDLToProcessor();
         try {
-            proc.parseWSDL(f.getAbsolutePath());
+            proc.parseWSDL(f.toString());
             Definition model = proc.getWSDLDefinition();
             assertNotNull("WSDL Definition Should not be Null", model);
             QName bindingName = new QName("http://schemas.apache.org/tests";, 
"BaseCORBABinding");
@@ -152,17 +141,17 @@ public class WSDLToIDLTest extends ToolTestBase {
 
         String[] cmdArgs = {"-corba", "-i", "BasePortType",
                             "-w", "simpleList-corba_gen.wsdl",
-                            "-d", output.getCanonicalPath(),
+                            "-d", output.toString(),
                             
getClass().getResource("/wsdl/simpleList.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", noError, exc);
+        String error = execute(cmdArgs);
+        assertNull("WSDLToIDL Failed", error);
 
-        File f = new File(output, "simpleList-corba_gen.wsdl");
-        assertTrue("simpleList-corba_gen.wsdl should be generated", 
f.exists());
+        Path f = output.resolve("simpleList-corba_gen.wsdl");
+        assertTrue("simpleList-corba_gen.wsdl should be generated", 
Files.exists(f));
 
         WSDLToProcessor proc = new WSDLToProcessor();
         try {
-            proc.parseWSDL(f.getAbsolutePath());
+            proc.parseWSDL(f.toString());
             Definition model = proc.getWSDLDefinition();
             assertNotNull("WSDL Definition Should not be Null", model);
             QName bindingName = new QName("http://schemas.apache.org/tests";, 
"BaseCORBABinding");
@@ -176,12 +165,12 @@ public class WSDLToIDLTest extends ToolTestBase {
     @Test
     public void testIDLGenDefault() throws Exception {
         String[] cmdArgs = {"-idl", "-b", "BaseCORBABinding",
-                            "-d", output.getCanonicalPath(),
+                            "-d", output.toString(),
                             
getClass().getResource("/wsdl/simple-binding.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", noError, exc);
+        String error = execute(cmdArgs);
+        assertNull("WSDLToIDL Failed", error);
 
-        Path path = FileSystems.getDefault().getPath(output.getPath(), 
"simple-binding.idl");
+        Path path = output.resolve("simple-binding.idl");
         assertTrue("simple-binding.idl should be generated", 
Files.isReadable(path));
 
         String line = new String(Files.readAllBytes(path), 
StandardCharsets.UTF_8);
@@ -192,12 +181,12 @@ public class WSDLToIDLTest extends ToolTestBase {
     public void testIDLGenSpecifiedFile() throws Exception {
         String[] cmdArgs = {"-idl", "-b", "BaseCORBABinding",
                             "-o", "simple-binding_gen.idl",
-                            "-d", output.getCanonicalPath(),
+                            "-d", output.toString(),
                             
getClass().getResource("/wsdl/simple-binding.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed in Idl Generation", noError, exc);
+        String error = execute(cmdArgs);
+        assertNull("WSDLToIDL Failed in Idl Generation", error);
 
-        Path path = FileSystems.getDefault().getPath(output.getPath(), 
"simple-binding_gen.idl");
+        Path path = output.resolve("simple-binding_gen.idl");
         assertTrue("simple-binding_gen.idl should be generated", 
Files.isReadable(path));
 
         String line = new String(Files.readAllBytes(path), 
StandardCharsets.UTF_8);
@@ -210,19 +199,19 @@ public class WSDLToIDLTest extends ToolTestBase {
     public void testBindAndIDLGen() throws Exception {
         String[] cmdArgs = {"-i", "BasePortType",
                             "-b", "BaseOneCORBABinding",
-                            "-d", output.getCanonicalPath(),
+                            "-d", output.toString(),
                             
getClass().getResource("/wsdl/simple-binding.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", noError, exc);
+        String error = execute(cmdArgs);
+        assertNull("WSDLToIDL Failed", error);
 
-        Path path1 = FileSystems.getDefault().getPath(output.getPath(), 
"simple-binding-corba.wsdl");
+        Path path1 = output.resolve("simple-binding-corba.wsdl");
         assertTrue("simple-binding-corba.wsdl should be generated", 
Files.isReadable(path1));
-        Path path2 = FileSystems.getDefault().getPath(output.getPath(), 
"simple-binding.idl");
+        Path path2 = output.resolve("simple-binding.idl");
         assertTrue("simple-binding.idl should be generated", 
Files.isReadable(path2));
 
         WSDLToProcessor proc = new WSDLToProcessor();
         try {
-            proc.parseWSDL(path1.toAbsolutePath().toString());
+            proc.parseWSDL(path1.toString());
             Definition model = proc.getWSDLDefinition();
             assertNotNull("WSDL Definition Should not be Null", model);
             QName bindingName = new QName("http://schemas.apache.org/tests";, 
"BaseOneCORBABinding");
@@ -238,8 +227,8 @@ public class WSDLToIDLTest extends ToolTestBase {
     @Test
     public void testNoArgs() throws Exception {
         String[] cmdArgs = {};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", error, exc);
+        String error = execute(cmdArgs);
+        assertNotNull("WSDLToIDL Failed", error);
         StringBuilder strBuf = new StringBuilder();
         strBuf.append("Missing argument: wsdlurl\n\n");
         strBuf.append(usage);
@@ -249,8 +238,8 @@ public class WSDLToIDLTest extends ToolTestBase {
     @Test
     public void testMissingRequiredFlags() throws Exception {
         String[] cmdArgs = {"-i", " interfaceName"};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", error, exc);
+        String error = execute(cmdArgs);
+        assertNotNull("WSDLToIDL Failed", error);
         StringBuilder expected = new StringBuilder();
         expected.append("Missing argument: wsdlurl\n\n");
         expected.append(usage);
@@ -262,8 +251,8 @@ public class WSDLToIDLTest extends ToolTestBase {
 
         String[] cmdArgs = {"-corba", "-i", "TestInterface",
                              
getClass().getResource("/wsdl/simpleList.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", error, exc);
+        String error = execute(cmdArgs);
+        assertNotNull("WSDLToIDL Failed", error);
         String expected = "Error : PortType TestInterface doesn't exist in 
WSDL.";
         checkStrings(expected.getBytes(), bout.toByteArray());
     }
@@ -274,8 +263,8 @@ public class WSDLToIDLTest extends ToolTestBase {
         String[] cmdArgs = {"-i", "BasePortType",
                             "-b", "BaseCORBABinding",
                             
getClass().getResource("/wsdl/simple-binding.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", error, exc);
+        String error = execute(cmdArgs);
+        assertNotNull("WSDLToIDL Failed", error);
         String expected = "Error : Binding BaseCORBABinding already exists in 
WSDL.";
         checkStrings(expected.getBytes(), bout.toByteArray());
     }
@@ -283,34 +272,34 @@ public class WSDLToIDLTest extends ToolTestBase {
 
     @Test
     public void testIdlGenMissingBinding() throws Exception {
-        String[] cmdArgs = {"-d", output.getAbsolutePath(),
+        String[] cmdArgs = {"-d", output.toString(),
                             "-idl",
                             
getClass().getResource("/wsdl/simpleList.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToIDL Failed", error, exc);
+        String error = execute(cmdArgs);
+        assertNotNull("WSDLToIDL Failed", error);
         String expected = "Error : Binding Name required for generating IDL";
         checkStrings(expected.getBytes(), bout.toByteArray());
     }
 
     @Test
     public void testIdlGenInvalidBinding() throws Exception {
-        String[] cmdArgs = {"-d", output.getAbsolutePath(),
+        String[] cmdArgs = {"-d", output.toString(),
                             "-idl", "-b", "TestBinding",
                              
getClass().getResource("/wsdl/simpleList.wsdl").toString()};
-        int exc = execute(cmdArgs);
-        assertEquals("WSDLToCORBA Failed", error, exc);
+        String error = execute(cmdArgs);
+        assertNotNull("WSDLToCORBA Failed", error);
         String expected = "Error : Binding TestBinding doesn't exist in WSDL.";
         checkStrings(expected.getBytes(), bout.toByteArray());
     }
 
     @Test
     public void testMissingBindingName() throws Exception {
-        String[] cmdArgs = {"-d", output.getAbsolutePath(),
+        String[] cmdArgs = {"-d", output.toString(),
                             "-i", "BasePortType",
                             
getClass().getResource("/wsdl/simpleList.wsdl").toString()};
-        assertEquals("WSDLToIDL should succeed even without Binding name. "
+        assertNull("WSDLToIDL should succeed even without Binding name. "
                         + "Name used from creation of CORBA binding to 
generate IDL.",
-                        noError, execute(cmdArgs));
+                        execute(cmdArgs));
     }
 
     @Test
diff --git 
a/tools/corba/src/test/java/org/apache/cxf/tools/corba/common/ToolTestBase.java 
b/tools/corba/src/test/java/org/apache/cxf/tools/corba/common/ToolTestBase.java
index 7b9c6c8..cec434a 100644
--- 
a/tools/corba/src/test/java/org/apache/cxf/tools/corba/common/ToolTestBase.java
+++ 
b/tools/corba/src/test/java/org/apache/cxf/tools/corba/common/ToolTestBase.java
@@ -38,7 +38,7 @@ public abstract class ToolTestBase extends Assert {
     protected ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
 
     @Before
-    public void setUp() {
+    public void setUp() throws Exception {
 
         oldStdErr = System.err;
         oldStdOut = System.out;
@@ -51,7 +51,7 @@ public abstract class ToolTestBase extends Assert {
     }
 
     @After
-    public void tearDown() {
+    public void tearDown() throws Exception {
 
         System.setErr(oldStdErr);
         System.setOut(oldStdOut);

Reply via email to