Author: veithen
Date: Sun Jan  7 22:44:26 2018
New Revision: 1820505

URL: http://svn.apache.org/viewvc?rev=1820505&view=rev
Log:
Don't write files to the source tree during test execution. Anyway this isn't 
necessary because the test server runs in the same JVM.

Modified:
    
axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
    
axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java

Modified: 
axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java?rev=1820505&r1=1820504&r2=1820505&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/AddNumbersHandlerTests.java
 Sun Jan  7 22:44:26 2018
@@ -75,6 +75,7 @@ import org.apache.axis2.jaxws.sample.add
 import 
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerFault_Exception;
 import 
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerPortType;
 import 
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersHandlerService;
+import 
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersProtocolHandler;
 import 
org.apache.axis2.jaxws.sample.addnumbershandler.AddNumbersProtocolHandler2;
 import org.apache.axis2.jaxws.spi.ServiceDelegate;
 import org.apache.axis2.testutils.Axis2Server;
@@ -132,12 +133,7 @@ public class AddNumbersHandlerTests {
             assertEquals("With handler manipulation, total should be 3 less 
than a proper sumation.", 17, total);
             TestLogger.logger.debug("Total (after handler manipulation) = " + 
total);
             
-            // also confirm that @PreDestroy method is called.  Since it only 
makes sense to call it on the managed
-            // (server) side and just before the handler instance goes out of 
scope, we are creating a file in the
-            // @PreDestroy method, and will check for its existance here.  If 
the file does not exist, it means
-            // @PreDestroy method was never called.  The file is set to 
.deleteOnExit(), so no need to delete it.
-            File file = new File("AddNumbersProtocolHandler.preDestroy.txt");
-            assertTrue("File AddNumbersProtocolHandler.preDestroy.txt does not 
exist, meaning the @PreDestroy method was not called.", file.exists());
+            assertTrue("@PreDestroy method was not called.", 
AddNumbersProtocolHandler.getAndResetPredestroyCalled());
 
             String log = readLogFile();
             String expected_calls =
@@ -216,12 +212,7 @@ public class AddNumbersHandlerTests {
                         "but the exception is: " + t);
         }
        
-        // also confirm that @PreDestroy method is called.  Since it only 
makes sense to call it on the managed
-        // (server) side and just before the handler instance goes out of 
scope, we are creating a file in the
-        // @PreDestroy method, and will check for its existance here.  If the 
file does not exist, it means
-        // @PreDestroy method was never called.  The file is set to 
.deleteOnExit(), so no need to delete it.
-        File file = new File("AddNumbersProtocolHandler.preDestroy.txt");
-        assertTrue("File AddNumbersProtocolHandler.preDestroy.txt does not 
exist, meaning the @PreDestroy method was not called.", file.exists());
+        assertTrue("@PreDestroy method was not called.", 
AddNumbersProtocolHandler.getAndResetPredestroyCalled());
 
         String log = readLogFile();
         String expected_calls =
@@ -310,12 +301,7 @@ public class AddNumbersHandlerTests {
                         "but the exception is: " + t);
         }
        
-        // also confirm that @PreDestroy method is called.  Since it only 
makes sense to call it on the managed
-        // (server) side and just before the handler instance goes out of 
scope, we are creating a file in the
-        // @PreDestroy method, and will check for its existance here.  If the 
file does not exist, it means
-        // @PreDestroy method was never called.  The file is set to 
.deleteOnExit(), so no need to delete it.
-        File file = new File("AddNumbersProtocolHandler.preDestroy.txt");
-        assertTrue("File AddNumbersProtocolHandler.preDestroy.txt does not 
exist, meaning the @PreDestroy method was not called.", file.exists());
+        assertTrue("@PreDestroy method was not called.", 
AddNumbersProtocolHandler.getAndResetPredestroyCalled());
 
         String log = readLogFile();
         String expected_calls =

Modified: 
axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java?rev=1820505&r1=1820504&r2=1820505&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws-integration/src/test/java/org/apache/axis2/jaxws/sample/addnumbershandler/AddNumbersProtocolHandler.java
 Sun Jan  7 22:44:26 2018
@@ -19,7 +19,6 @@
 
 package org.apache.axis2.jaxws.sample.addnumbershandler;
 
-import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.TestLogger;
 
 import javax.annotation.PreDestroy;
@@ -30,12 +29,11 @@ import javax.xml.soap.SOAPFault;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.soap.SOAPMessageContext;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 public class AddNumbersProtocolHandler implements 
javax.xml.ws.handler.soap.SOAPHandler<SOAPMessageContext> {
+    private static final AtomicBoolean predestroyCalled = new AtomicBoolean();
 
     HandlerTracker tracker = new 
HandlerTracker(AddNumbersProtocolHandler.class.getSimpleName());
     
@@ -113,22 +111,11 @@ public class AddNumbersProtocolHandler i
     @PreDestroy
     public void preDestroy() {
         tracker.preDestroy();
-       try {
-               /*
-                * since @PreDestroy methods are called just before the managed 
(server) side
-                * handler instance goes out of scope, there's not a good way 
to test if it is
-                * called.  So, we are creating a file that one of the 
AddNumbersHandlerTests tests
-                * checks the existance of.
-                */
-               File file = new 
File("AddNumbersProtocolHandler.preDestroy.txt");
-               file.createNewFile();
-               FileOutputStream fos = new FileOutputStream(file);
-               fos.write(new byte[]{'h','i'});
-               fos.close();
-               file.deleteOnExit();
-       } catch (Exception e) {
-               throw ExceptionFactory.makeWebServiceException(e);
-       }
+        predestroyCalled.set(true);
+    }
+
+    public static boolean getAndResetPredestroyCalled() {
+        return predestroyCalled.getAndSet(false);
     }
 
     private static String stackToString(Throwable e) {


Reply via email to