Author: rgoers
Date: Sun Oct 31 06:13:06 2010
New Revision: 1029255
URL: http://svn.apache.org/viewvc?rev=1029255&view=rev
Log:
Add unit test
Added:
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
- copied, changed from r1029218,
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java
Modified:
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
Modified:
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
URL:
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java?rev=1029255&r1=1029254&r2=1029255&view=diff
==============================================================================
---
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
(original)
+++
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
Sun Oct 31 06:13:06 2010
@@ -86,7 +86,13 @@ public class RegexFilter extends FilterB
return null;
}
boolean raw = useRawMsg == null ? false :
Boolean.parseBoolean(useRawMsg);
- Pattern pattern = Pattern.compile(regex);
+ Pattern pattern;
+ try {
+ pattern = Pattern.compile(regex);
+ } catch (Exception ex) {
+ logger.error("RegexFilter caught exception compiling pattern: " +
regex + " cause: " + ex.getMessage());
+ return null;
+ }
Result onMatch = match == null ? null : Result.valueOf(match);
Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch);
Copied:
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
(from r1029218,
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java)
URL:
http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java&r1=1029218&r2=1029255&rev=1029255&view=diff
==============================================================================
---
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThresholdFilterTest.java
(original)
+++
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
Sun Oct 31 06:13:06 2010
@@ -24,24 +24,25 @@ import org.apache.logging.log4j.message.
import org.junit.Test;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
/**
*
*/
-public class ThresholdFilterTest {
+public class RegexFilterTest {
@Test
public void testThresholds() {
- ThresholdFilter filter = ThresholdFilter.createFilter("ERROR", null,
null);
+ RegexFilter filter = RegexFilter.createFilter(".* test .*", null,
null, null);
filter.start();
assertTrue(filter.isStarted());
- assertTrue(filter.filter(null, Level.DEBUG, null, null,
(Throwable)null) == Filter.Result.DENY);
- assertTrue(filter.filter(null, Level.ERROR, null, null,
(Throwable)null) == Filter.Result.NEUTRAL);
- LogEvent event = new Log4jLogEvent(null, null, null, Level.DEBUG, new
SimpleMessage("Test"), null);
- assertTrue(filter.filter(event) == Filter.Result.DENY);
- event = new Log4jLogEvent(null, null, null, Level.ERROR, new
SimpleMessage("Test"), null);
+ assertTrue(filter.filter(null, Level.DEBUG, null, "This is a test
message", (Throwable)null) == Filter.Result.NEUTRAL);
+ assertTrue(filter.filter(null, Level.ERROR, null, "This is not a
test", (Throwable)null) == Filter.Result.DENY);
+ LogEvent event = new Log4jLogEvent(null, null, null, Level.DEBUG, new
SimpleMessage("Another test message"), null);
assertTrue(filter.filter(event) == Filter.Result.NEUTRAL);
+ event = new Log4jLogEvent(null, null, null, Level.ERROR, new
SimpleMessage("test"), null);
+ assertTrue(filter.filter(event) == Filter.Result.DENY);
+ filter = RegexFilter.createFilter("* test *", null, null, null);
+ assertNull(filter);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]