axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject cvs commit: xml-axis/java/test/chains TestSimpleChain.java
Date Tue, 08 Jan 2002 14:51:39 GMT
rubys       02/01/08 06:51:39

  Modified:    java/src/org/apache/axis InternalException.java
               java/test/chains TestSimpleChain.java
  Log:
  Silence the logging of InternalExceptions during the chains unit tests
  in a log4j version independent manner.
  
  Revision  Changes    Path
  1.2       +36 -12    xml-axis/java/src/org/apache/axis/InternalException.java
  
  Index: InternalException.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/InternalException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InternalException.java	23 Dec 2001 12:33:31 -0000	1.1
  +++ InternalException.java	8 Jan 2002 14:51:39 -0000	1.2
  @@ -73,6 +73,28 @@
                   Category.getInstance(InternalException.class.getName());
   
       /**
  +     * Attribute which controls whether or not logging of such events should
  +     * occur.  Default is true and is recommended.  Sometimes this may be
  +     * turned off in unit tests when internal errors are intentionally
  +     * provoked.
  +     */
  +    private static boolean shouldLog = true;
  +
  +    /**
  +     * Setter for logging.
  +     */
  +    public static void setLogging(boolean logging) {
  +        shouldLog = logging;
  +    }
  +    
  +    /**
  +     * Getter for logging property.
  +     */
  +    public static boolean getLogging() {
  +        return shouldLog;
  +    }
  +
  +    /**
        * Construct an Internal Exception from a String.  The string is wrapped
        * in an exception, enabling a stack traceback to be obtained.
        * @param message String form of the error
  @@ -88,19 +110,21 @@
       public InternalException(Exception e) {
           super(e.toString());
   
  -        // if the exception is merely bubbling up the stack, only log the
  -        // event if debug is turned on.
  -        if (!(e instanceof InternalException)) {
  -            category.fatal(e);
  -        } else {
  -            category.debug(e);
  -        }
  +        if (shouldLog) {
  +            // if the exception is merely bubbling up the stack, only log the
  +            // event if debug is turned on.
  +            if (!(e instanceof InternalException)) {
  +                category.fatal(e);
  +            } else {
  +                category.debug(e);
  +            }
   
  -        // if the debug is enabled, add a stack trace.
  -        if (category.isDebugEnabled()) {
  -            StringWriter writer = new StringWriter();
  -            e.printStackTrace(new PrintWriter(writer));
  -            category.debug(writer.getBuffer().toString());
  +            // if the debug is enabled, add a stack trace.
  +            if (category.isDebugEnabled()) {
  +                StringWriter writer = new StringWriter();
  +                e.printStackTrace(new PrintWriter(writer));
  +                category.debug(writer.getBuffer().toString());
  +            }
           }
       }
   }
  
  
  
  1.3       +5 -8      xml-axis/java/test/chains/TestSimpleChain.java
  
  Index: TestSimpleChain.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/chains/TestSimpleChain.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestSimpleChain.java	7 Jan 2002 15:57:10 -0000	1.2
  +++ TestSimpleChain.java	8 Jan 2002 14:51:39 -0000	1.3
  @@ -58,15 +58,13 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
  +import org.apache.axis.InternalException;
   import org.apache.axis.SimpleChain;
   import org.apache.axis.Handler;
   import org.apache.axis.handlers.BasicHandler;
   import org.apache.axis.MessageContext;
   import org.apache.axis.AxisFault;
   
  -import org.apache.log4j.Category;
  -import org.apache.log4j.Priority;
  -
   public class TestSimpleChain extends TestCase
   {
       public TestSimpleChain (String name) {
  @@ -109,10 +107,8 @@
               c.invoke(mc);
   
               // while testing, disable noise
  -            Category category = Category.getInstance(
  -                org.apache.axis.InternalException.class.getName());
  -            Priority oldPriority = category.getPriority();
  -            category.setPriority(Priority.OFF);
  +            boolean oldLogging = InternalException.getLogging();
  +            InternalException.setLogging(false);
   
               try {
                   Handler h2 = new TestHandler();
  @@ -122,7 +118,8 @@
                   // Correct behaviour. Exact exception isn't critical
               }
   
  -            category.setPriority(oldPriority);
  +            // resume noise
  +            InternalException.setLogging(oldLogging);
           } catch (AxisFault af) {
               assertTrue("Unexpected exception", false);
           }
  
  
  

Mime
View raw message