[logback-dev] svn commit: r975 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access/net logback-access/src/test/java/ch/qos/logback/access logback-access/src/test/java/ch/qos/logback/access/net logback-access/src/test/java/ch/qos/logback/access/pattern/helpers logback-core/src/test/java/ch/qos/logback/core/rolling

noreply.seb at qos.ch noreply.seb at qos.ch
Tue Nov 21 18:26:32 CET 2006


Author: seb
Date: Tue Nov 21 18:26:31 2006
New Revision: 975

Added:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/URLEvaluator.java
      - copied, changed from r974, /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/DefaultSMTPEvaluator.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/URLEvaluatorTest.java
      - copied, changed from r974, /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/DefaultSMTPEvaluatorTest.java
Removed:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/DefaultSMTPEvaluator.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/DefaultSMTPEvaluatorTest.java
Modified:
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/AllTest.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/PackageTest.java
   logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyRequest.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java

Log:
Renamed DefaultSMTPEvaluator to URLEvaluator
Updated test case
Minor javadoc modifications to TimeBasedRollingTest

Copied: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/URLEvaluator.java (from r974, /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/DefaultSMTPEvaluator.java)
==============================================================================
--- /logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/DefaultSMTPEvaluator.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/URLEvaluator.java	Tue Nov 21 18:26:31 2006
@@ -1,21 +1,59 @@
 package ch.qos.logback.access.net;
 
-import ch.qos.logback.access.boolex.JaninoEventEvaluator;
+import java.util.ArrayList;
+import java.util.List;
 
-public class DefaultSMTPEvaluator extends JaninoEventEvaluator {
-  
-  private String url;
-  
-  public DefaultSMTPEvaluator() { 
-  }
-  
-  public void setUrl(String url) {
-    this.url = url;
+import ch.qos.logback.access.spi.AccessEvent;
+import ch.qos.logback.core.boolex.EvaluationException;
+import ch.qos.logback.core.boolex.EventEvaluator;
+import ch.qos.logback.core.spi.ContextAwareBase;
+import ch.qos.logback.core.spi.LifeCycle;
+
+public class URLEvaluator extends ContextAwareBase implements EventEvaluator, LifeCycle {
+
+  boolean started;
+  String name;
+  private List<String> URLList = new ArrayList<String>();
+
+  public URLEvaluator() {
+  }
+
+  public void addURL(String url) {
+    URLList.add(url);
   }
-  
-  @Override
+
   public void start() {
-    setExpression("request.getRequestURL().toString().contains(\"" + url + "\")");
-    super.start();
+    if (URLList.size() == 0) {
+      addWarn("No URL was given to URLEvaluator");
+    } else {
+      started = true;
+    }
+  }
+    
+  public boolean evaluate(Object eventObject) throws NullPointerException, EvaluationException {
+    AccessEvent event = (AccessEvent)eventObject;
+    String url = event.getRequestURL();
+    for(String expected:URLList) {
+      if (url.contains(expected)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public boolean isStarted() {
+    return started;
+  }
+
+  public void stop() {
+    started = false;
   }
 }

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/AllTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/AllTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/AllTest.java	Tue Nov 21 18:26:31 2006
@@ -17,7 +17,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
- 
+    suite.addTest(ch.qos.logback.access.net.PackageTest.suite());
     suite.addTest(ch.qos.logback.access.pattern.PackageTest.suite());
     suite.addTest(ch.qos.logback.access.jetty.PackageTest.suite());
     return suite;

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/PackageTest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/PackageTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/PackageTest.java	Tue Nov 21 18:26:31 2006
@@ -15,7 +15,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTestSuite(DefaultSMTPEvaluatorTest.class);
+    suite.addTestSuite(URLEvaluatorTest.class);
     return suite;
   }
 }
\ No newline at end of file

Copied: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/URLEvaluatorTest.java (from r974, /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/DefaultSMTPEvaluatorTest.java)
==============================================================================
--- /logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/DefaultSMTPEvaluatorTest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/net/URLEvaluatorTest.java	Tue Nov 21 18:26:31 2006
@@ -9,19 +9,20 @@
 import ch.qos.logback.core.ContextBase;
 import ch.qos.logback.core.boolex.EvaluationException;
 
-public class DefaultSMTPEvaluatorTest extends TestCase {
+public class URLEvaluatorTest extends TestCase {
 
-  final String expectedURL = "testUrl";
+  final String expectedURL1 = "testUrl1";
+  final String expectedURL2 = "testUrl2";
   Context context = new ContextBase();
-  DefaultSMTPEvaluator evaluator;    
+  URLEvaluator evaluator;    
   DummyRequest request;
   DummyResponse response;
   DummyServerAdapter serverAdapter;
   
   public void setUp() throws Exception {
-    evaluator = new DefaultSMTPEvaluator();
+    evaluator = new URLEvaluator();
     evaluator.setContext(context);
-    evaluator.setUrl(expectedURL);
+    evaluator.addURL(expectedURL1);
     evaluator.start();
     request = new DummyRequest();
     response = new DummyResponse();
@@ -38,15 +39,25 @@
     context = null;
   }
   
-  public void testExpectFalseBecauseOfStatus() throws EvaluationException {
-    request.setRequestUrl("test");
+  public void testExpectFalse() throws EvaluationException {
+    request.setRequestUri("test");
     AccessEvent ae = new AccessEvent(request, response, serverAdapter);
+    System.out.println(ae.getRequestURL());
     assertFalse(evaluator.evaluate(ae));
   }
   
   public void testExpectTrue() throws EvaluationException {
-    request.setRequestUrl(expectedURL);    
+    request.setRequestUri(expectedURL1);   
     AccessEvent ae = new AccessEvent(request, response, serverAdapter);
+    System.out.println(ae.getRequestURL());
+    assertTrue(evaluator.evaluate(ae));    
+  }
+  
+  public void testExpectTrueMultiple() throws EvaluationException {
+    evaluator.addURL(expectedURL2);
+    request.setRequestUri(expectedURL2);    
+    AccessEvent ae = new AccessEvent(request, response, serverAdapter);
+    System.out.println(ae.getRequestURL());
     assertTrue(evaluator.evaluate(ae));    
   }
 }

Modified: logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyRequest.java
==============================================================================
--- logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyRequest.java	(original)
+++ logback/trunk/logback-access/src/test/java/ch/qos/logback/access/pattern/helpers/DummyRequest.java	Tue Nov 21 18:26:31 2006
@@ -18,7 +18,7 @@
 public class DummyRequest implements HttpServletRequest {
 
   Hashtable<String, String> headerNames;
-  String url;
+  String uri;
 
   public DummyRequest() {
     headerNames = new Hashtable<String, String>();
@@ -80,11 +80,11 @@
   }
 
   public String getRequestURI() {
-    return "testURI";
+    return uri;
   }
 
   public StringBuffer getRequestURL() {
-    return new StringBuffer(url);
+    return new StringBuffer(uri);
   }
 
   public String getRequestedSessionId() {
@@ -245,7 +245,7 @@
       throws UnsupportedEncodingException {
   }
   
-  public void setRequestUrl(String url) {
-    this.url = url;
+  public void setRequestUri(String uri) {
+    this.uri = uri;
   }
 }

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java	Tue Nov 21 18:26:31 2006
@@ -24,8 +24,8 @@
 import ch.qos.logback.core.util.Constants;
 
 /**
- * A rather exhaustive set of tests. Tests include leaving the ActiveFileName
- * argument blank, or setting it, with and without compression, and tests with
+ * A rather exhaustive set of tests. Tests include leaving the file option
+ * blank, or setting it, with and without compression, and tests with
  * or without stopping/restarting the RollingFileAppender.
  * 
  * The regression tests log a few times using a RollingFileAppender. Then, they
@@ -33,7 +33,7 @@
  * with witness files.
  * 
  * <pre>
- *             Compression     ActiveFileName  Stop/Restart 
+ *             Compression     file option    Stop/Restart 
  *  Test1      NO              BLANK           NO
  *  Test2      NO              BLANK           YES
  *  Test3      YES             BLANK           NO
@@ -79,7 +79,7 @@
   }
 
   /**
-   * Test rolling without compression, activeFileName left blank, no stop/start
+   * Test rolling without compression, file option left blank, no stop/start
    */
   public void test1() throws Exception {
 
@@ -127,7 +127,7 @@
   }
 
   /**
-   * No compression, with stop/restart, activeFileName left blank
+   * No compression, with stop/restart, file option left blank
    */
   public void test2() throws Exception {
     RollingFileAppender rfa1 = new RollingFileAppender();
@@ -190,7 +190,7 @@
   }
 
   /**
-   * With compression, activeFileName left blank, no stop/restart
+   * With compression, file option left blank, no stop/restart
    */
   public void test3() throws Exception {
     RollingFileAppender rfa = new RollingFileAppender();
@@ -242,7 +242,7 @@
   }
 
   /**
-   * Without compression, activeFileName set, with stop/restart
+   * Without compression, file option set, with stop/restart
    */
   public void test4() throws Exception {
     RollingFileAppender rfa1 = new RollingFileAppender();
@@ -310,7 +310,7 @@
   }
 
   /**
-   * No compression, activeFileName set, without stop/restart
+   * No compression, file option set, without stop/restart
    */
   public void test5() throws Exception {
     RollingFileAppender rfa = new RollingFileAppender();
@@ -357,7 +357,7 @@
   }
 
   /**
-   * With compression, activeFileName set, no stop/restart,
+   * With compression, file option set, no stop/restart,
    */
   public void test6() throws Exception {
     RollingFileAppender rfa = new RollingFileAppender();
@@ -412,9 +412,6 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    // CompressTest requires external copying
-    // suite.addTestSuite(CompressTest.class);
-    // suite.addTest(new TimeBasedRollingTest("test1"));
     suite.addTestSuite(TimeBasedRollingTest.class);
     return suite;
   }



More information about the logback-dev mailing list