You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2008/05/18 22:13:19 UTC
svn commit: r657626 - in
/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j:
filter/ rule/ util/
Author: carnold
Date: Sun May 18 13:13:18 2008
New Revision: 657626
URL: http://svn.apache.org/viewvc?rev=657626&view=rev
Log:
Bug 45029: Additional unit tests for Filters
Added:
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/AndFilterTest.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/DenyAllFilterTest.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelMatchFilterTest.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelRangeFilterTest.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LoggerMatchFilterTest.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/StringMatchFilterTest.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelEqualsRuleTest.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelInequalityRuleTest.java
logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/SerializationTestHelper.java
- copied unchanged from r640538, logging/log4j/trunk/tests/src/java/org/apache/log4j/util/SerializationTestHelper.java
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/AndFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/AndFilterTest.java?rev=657626&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/AndFilterTest.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/AndFilterTest.java Sun May 18 13:13:18 2008
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.filter;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.Filter;
+import org.apache.log4j.spi.LoggingEvent;
+
+
+/**
+ * Unit tests for AndFilter.
+ */
+public class AndFilterTest extends TestCase {
+
+ /**
+ * Create new test instance.
+ *
+ * @param name test name.
+ */
+ public AndFilterTest(final String name) {
+ super(name);
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.ACCEPT if no filters added.
+ */
+ public void test1() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(AndFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ Filter filter = new AndFilter();
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.ACCEPT if
+ * only nested filter returns Filter.ACCEPT.
+ */
+ public void test2() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(AndFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ AndFilter filter = new AndFilter();
+ LevelMatchFilter filter1 = new LevelMatchFilter();
+ filter1.setLevelToMatch("info");
+ filter1.activateOptions();
+ filter.addFilter(filter1);
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.ACCEPT if
+ * two nested filters return Filter.ACCEPT.
+ */
+ public void test3() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(AndFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ AndFilter filter = new AndFilter();
+ LevelMatchFilter filter1 = new LevelMatchFilter();
+ filter1.setLevelToMatch("info");
+ filter1.activateOptions();
+ filter.addFilter(filter1);
+ LevelMatchFilter filter2 = new LevelMatchFilter();
+ filter2.setLevelToMatch("info");
+ filter2.activateOptions();
+ filter.addFilter(filter2);
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.DENY if
+ * only nested filter returns Filter.ACCEPT
+ * and acceptOnMatch is false.
+ */
+ public void test4() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(AndFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ AndFilter filter = new AndFilter();
+ LevelMatchFilter filter1 = new LevelMatchFilter();
+ filter1.setLevelToMatch("info");
+ filter1.activateOptions();
+ filter.addFilter(filter1);
+ filter.setAcceptOnMatch(false);
+ filter.activateOptions();
+ assertEquals(Filter.DENY, filter.decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.NEUTRAL if
+ * nested filters return Filter.ACCEPT and Filter.DENY.
+ */
+ public void test5() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(AndFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ AndFilter filter = new AndFilter();
+ LevelMatchFilter filter1 = new LevelMatchFilter();
+ filter1.setLevelToMatch("info");
+ filter1.activateOptions();
+ filter.addFilter(filter1);
+ Filter filter2 = new DenyAllFilter();
+ filter2.activateOptions();
+ filter.addFilter(filter2);
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+ /**
+ * Check that AndFilter.decide() returns Filter.NEUTRAL if
+ * nested filters return Filter.ACCEPT and Filter.NEUTRAL.
+ */
+ public void test6() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(AndFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ AndFilter filter = new AndFilter();
+ LevelMatchFilter filter1 = new LevelMatchFilter();
+ filter1.setLevelToMatch("info");
+ filter1.activateOptions();
+ filter.addFilter(filter1);
+ Filter filter2 = new StringMatchFilter();
+ filter2.activateOptions();
+ filter.addFilter(filter2);
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+}
+
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/DenyAllFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/DenyAllFilterTest.java?rev=657626&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/DenyAllFilterTest.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/DenyAllFilterTest.java Sun May 18 13:13:18 2008
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.filter;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.Filter;
+import org.apache.log4j.spi.LoggingEvent;
+
+
+/**
+ * Unit tests for DenyAllFilter.
+ */
+public class DenyAllFilterTest extends TestCase {
+
+ /**
+ * Create new test instance.
+ *
+ * @param name test name.
+ */
+ public DenyAllFilterTest(final String name) {
+ super(name);
+ }
+
+ /**
+ * Check that DenyAllFilter.decide() returns Filter.DENY.
+ */
+ public void test1() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(DenyAllFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ Filter filter = new DenyAllFilter();
+ filter.activateOptions();
+ assertEquals(Filter.DENY, filter.decide(event));
+ }
+
+}
+
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelMatchFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelMatchFilterTest.java?rev=657626&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelMatchFilterTest.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelMatchFilterTest.java Sun May 18 13:13:18 2008
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.filter;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.Filter;
+import org.apache.log4j.spi.LoggingEvent;
+
+
+/**
+ * Unit tests for LevelMatchFilter.
+ */
+public class LevelMatchFilterTest extends TestCase {
+
+ /**
+ * Create new test instance.
+ *
+ * @param name test name.
+ */
+ public LevelMatchFilterTest(final String name) {
+ super(name);
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns Filter.ACCEPT when level matches.
+ */
+ public void test1() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelMatchFilter filter = new LevelMatchFilter();
+ filter.setLevelToMatch("info");
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns Filter.DENY
+ * when level matches and acceptOnMatch = false.
+ */
+ public void test2() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelMatchFilter filter = new LevelMatchFilter();
+ filter.setLevelToMatch("info");
+ filter.setAcceptOnMatch(false);
+ filter.activateOptions();
+ assertEquals(Filter.DENY, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns Filter.NEUTRAL
+ * when levelToMatch is unspecified.
+ */
+ public void test3() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelMatchFilter filter = new LevelMatchFilter();
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns Filter.NEUTRAL
+ * when event level is higher than level to match.
+ */
+ public void test4() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelMatchFilter filter = new LevelMatchFilter();
+ filter.setLevelToMatch("debug");
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelMatchFilter.decide() returns Filter.NEUTRAL
+ * when event level is lower than level to match.
+ */
+ public void test5() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelMatchFilter filter = new LevelMatchFilter();
+ filter.setLevelToMatch("warn");
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+}
+
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelRangeFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelRangeFilterTest.java?rev=657626&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelRangeFilterTest.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LevelRangeFilterTest.java Sun May 18 13:13:18 2008
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.filter;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.Filter;
+import org.apache.log4j.spi.LoggingEvent;
+
+
+/**
+ * Unit tests for LevelRangeFilter.
+ */
+public class LevelRangeFilterTest extends TestCase {
+
+ /**
+ * Create new test instance.
+ *
+ * @param name test name.
+ */
+ public LevelRangeFilterTest(final String name) {
+ super(name);
+ }
+
+ /**
+ * Check that LevelRangeFilter.decide() returns Filter.DENY
+ * when event level is below min level.
+ */
+ public void test1() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelRangeFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelRangeFilter filter = new LevelRangeFilter();
+ filter.setLevelMin(Level.WARN);
+ filter.activateOptions();
+ assertEquals(Filter.DENY, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelRangeFilter.decide() returns Filter.DENY
+ * when event level is above max level.
+ */
+ public void test2() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelRangeFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelRangeFilter filter = new LevelRangeFilter();
+ filter.setLevelMax(Level.DEBUG);
+ filter.activateOptions();
+ assertEquals(Filter.DENY, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelRangeFilter.decide() returns Filter.ACCEPT
+ * when event level is above min level.
+ */
+ public void test3() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelRangeFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelRangeFilter filter = new LevelRangeFilter();
+ filter.setLevelMin(Level.DEBUG);
+ filter.setAcceptOnMatch(true);
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelRangeFilter.decide() returns Filter.ACCEPT
+ * when event level is below max level.
+ */
+ public void test4() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelRangeFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelRangeFilter filter = new LevelRangeFilter();
+ filter.setLevelMax(Level.ERROR);
+ filter.setAcceptOnMatch(true);
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelRangeFilter.decide() returns Filter.NEUTRAL
+ * when event level is above min level and accept on match is false.
+ */
+ public void test5() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelRangeFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelRangeFilter filter = new LevelRangeFilter();
+ filter.setLevelMin(Level.DEBUG);
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+ /**
+ * Check that LevelRangeFilter.decide() returns Filter.NEUTRAL
+ * when event level is below max level and accept on match is false.
+ */
+ public void test6() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(LevelRangeFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LevelRangeFilter filter = new LevelRangeFilter();
+ filter.setLevelMax(Level.ERROR);
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+}
+
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LoggerMatchFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LoggerMatchFilterTest.java?rev=657626&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LoggerMatchFilterTest.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/LoggerMatchFilterTest.java Sun May 18 13:13:18 2008
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.filter;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.Filter;
+import org.apache.log4j.spi.LoggingEvent;
+
+
+/**
+ * Unit tests for LoggerMatchFilter.
+ */
+public class LoggerMatchFilterTest extends TestCase {
+
+ /**
+ * Create new test instance.
+ *
+ * @param name test name.
+ */
+ public LoggerMatchFilterTest(final String name) {
+ super(name);
+ }
+
+ /**
+ * Check that LoggerMatchFilter.decide() with unspecified level
+ * returns Filter.ACCEPT for root logger.
+ */
+ public void test1() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ Filter filter = new LoggerMatchFilter();
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+ /**
+ * Check that LoggerMatchFilter.decide() with unspecified level
+ * returns Filter.DENY for root logger when accept on match is false.
+ */
+ public void test2() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LoggerMatchFilter filter = new LoggerMatchFilter();
+ filter.setAcceptOnMatch(false);
+ filter.activateOptions();
+ assertEquals(Filter.DENY, filter.decide(event));
+ }
+
+ /**
+ * Check that LoggerMatchFilter.decide() with unspecified level
+ * returns Filter.NEUTRAL for non-root logger.
+ */
+ public void test3() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger("org.apache.log4j.filter.LoggerMatchFilterTest"),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ Filter filter = new LoggerMatchFilter();
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+ /**
+ * Check that LoggerMatchFilter.decide()
+ * returns Filter.ACCEPT for matching logger.
+ */
+ public void test4() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger("org.apache.log4j.filter.LoggerMatchFilterTest"),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ LoggerMatchFilter filter = new LoggerMatchFilter();
+ filter.setLoggerToMatch("org.apache.log4j.filter.LoggerMatchFilterTest");
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+}
+
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/StringMatchFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/StringMatchFilterTest.java?rev=657626&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/StringMatchFilterTest.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/filter/StringMatchFilterTest.java Sun May 18 13:13:18 2008
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.filter;
+
+import junit.framework.TestCase;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.Filter;
+import org.apache.log4j.spi.LoggingEvent;
+
+
+/**
+ * Unit tests for StringMatchFilter.
+ */
+public class StringMatchFilterTest extends TestCase {
+
+ /**
+ * Create new test instance.
+ *
+ * @param name test name.
+ */
+ public StringMatchFilterTest(final String name) {
+ super(name);
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns Filter.NEUTRAL
+ * when string to match is unspecified.
+ */
+ public void test1() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(StringMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ Filter filter = new StringMatchFilter();
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns Filter.NEUTRAL
+ * when string to match does not appear in message.
+ */
+ public void test2() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(StringMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ StringMatchFilter filter = new StringMatchFilter();
+ filter.setStringToMatch("Monde");
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns Filter.ACCEPT
+ * when string to match does appear in message.
+ */
+ public void test3() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(StringMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ StringMatchFilter filter = new StringMatchFilter();
+ filter.setStringToMatch("World");
+ filter.activateOptions();
+ assertEquals(Filter.ACCEPT, filter.decide(event));
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns Filter.DENY
+ * when string to match does appear in message and
+ * accept on match is false.
+ */
+ public void test4() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(StringMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ StringMatchFilter filter = new StringMatchFilter();
+ filter.setStringToMatch("World");
+ filter.setAcceptOnMatch(false);
+ filter.activateOptions();
+ assertEquals(Filter.DENY, filter.decide(event));
+ }
+
+ /**
+ * Check that StringMatchFilter.decide() returns Filter.NEUTRAL
+ * when string to match does appear in message but differs in case.
+ */
+ public void test5() {
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getLogger(StringMatchFilterTest.class),
+ System.currentTimeMillis(), Level.INFO, "Hello, World", null);
+ StringMatchFilter filter = new StringMatchFilter();
+ filter.setStringToMatch("world");
+ filter.activateOptions();
+ assertEquals(Filter.NEUTRAL, filter.decide(event));
+ }
+
+}
+
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelEqualsRuleTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelEqualsRuleTest.java?rev=657626&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelEqualsRuleTest.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelEqualsRuleTest.java Sun May 18 13:13:18 2008
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.rule;
+
+
+import junit.framework.TestCase;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.helpers.UtilLoggingLevel;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.util.SerializationTestHelper;
+
+import java.io.IOException;
+
+/**
+ * Test for LevelEqualsRule.
+ */
+public class LevelEqualsRuleTest extends TestCase {
+
+ /**
+ * Create new test.
+ *
+ * @param testName test name.
+ */
+ public LevelEqualsRuleTest(final String testName) {
+ super(testName);
+ }
+
+ /**
+ * Tests evaluate when levels are equal.
+ */
+ public void test1() {
+ LevelEqualsRule rule = (LevelEqualsRule) LevelEqualsRule.getRule("info");
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), Level.INFO,
+ "Hello, World", null);
+ assertTrue(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate when levels are not equal.
+ */
+ public void test2() {
+ LevelEqualsRule rule = (LevelEqualsRule) LevelEqualsRule.getRule("info");
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), Level.WARN,
+ "Hello, World", null);
+ assertFalse(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate of a deserialized clone when levels are equal.
+ */
+ public void test3() throws IOException, ClassNotFoundException {
+ LevelEqualsRule rule = (LevelEqualsRule)
+ SerializationTestHelper.serializeClone(LevelEqualsRule.getRule("info"));
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), Level.INFO,
+ "Hello, World", null);
+ assertTrue(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate of a deserialized clone when levels are equal.
+ */
+ public void test4() throws IOException, ClassNotFoundException {
+ LevelEqualsRule rule = (LevelEqualsRule)
+ SerializationTestHelper.serializeClone(LevelEqualsRule.getRule("info"));
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), Level.WARN,
+ "Hello, World", null);
+ assertFalse(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate when levels are JDK 1.4 levels and equal.
+ */
+ public void test5() {
+ LevelEqualsRule rule = (LevelEqualsRule) LevelEqualsRule.getRule("finer");
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), UtilLoggingLevel.FINER,
+ "Hello, World", null);
+ assertTrue(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate when levels are JDK 1.4 levels and not equal.
+ */
+ public void test6() {
+ LevelEqualsRule rule = (LevelEqualsRule) LevelEqualsRule.getRule("finer");
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), UtilLoggingLevel.FINE,
+ "Hello, World", null);
+ assertFalse(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate of a deserialized clone when levels are JDK 1.4 levels and equal.
+ */
+ public void test7() throws IOException, ClassNotFoundException {
+ LevelEqualsRule rule = (LevelEqualsRule)
+ SerializationTestHelper.serializeClone(LevelEqualsRule.getRule("finer"));
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), UtilLoggingLevel.FINER,
+ "Hello, World", null);
+ assertTrue(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate of a deserialized clone when levels are JDK 1.4 levels and not equal.
+ */
+ public void test8() throws IOException, ClassNotFoundException {
+ LevelEqualsRule rule = (LevelEqualsRule)
+ SerializationTestHelper.serializeClone(LevelEqualsRule.getRule("finer"));
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), UtilLoggingLevel.FINE,
+ "Hello, World", null);
+ assertFalse(rule.evaluate(event));
+ }
+
+}
Added: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelInequalityRuleTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelInequalityRuleTest.java?rev=657626&view=auto
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelInequalityRuleTest.java (added)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/rule/LevelInequalityRuleTest.java Sun May 18 13:13:18 2008
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.log4j.rule;
+
+
+import junit.framework.TestCase;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.helpers.UtilLoggingLevel;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.util.SerializationTestHelper;
+
+import java.io.IOException;
+
+/**
+ * Test for LevelInequalityRule.
+ */
+public class LevelInequalityRuleTest extends TestCase {
+
+ /**
+ * Create new test.
+ *
+ * @param testName test name.
+ */
+ public LevelInequalityRuleTest(final String testName) {
+ super(testName);
+ }
+
+ /**
+ * Test construction when level is unrecognized.
+ */
+ public void test1() {
+ try {
+ LevelInequalityRule.getRule(">", "emergency");
+ fail("Expected IllegalArgumentException");
+ } catch(IllegalArgumentException ex) {
+ }
+ }
+
+ /**
+ * Tests construction when operator is unrecognized.
+ */
+ public void test2() {
+ Rule rule = LevelInequalityRule.getRule("~", "iNfO");
+ assertNull(rule);
+ }
+
+ /**
+ * Tests evaluate of a deserialized clone when levels are equal.
+ */
+ public void test3() throws IOException, ClassNotFoundException {
+ LevelEqualsRule rule = (LevelEqualsRule)
+ SerializationTestHelper.serializeClone(LevelEqualsRule.getRule("info"));
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), Level.INFO,
+ "Hello, World", null);
+ assertTrue(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate of a deserialized clone when levels are equal.
+ */
+ public void test4() throws IOException, ClassNotFoundException {
+ LevelEqualsRule rule = (LevelEqualsRule)
+ SerializationTestHelper.serializeClone(LevelEqualsRule.getRule("info"));
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), Level.WARN,
+ "Hello, World", null);
+ assertFalse(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate when levels are JDK 1.4 levels and equal.
+ */
+ public void test5() {
+ LevelEqualsRule rule = (LevelEqualsRule) LevelEqualsRule.getRule("finer");
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), UtilLoggingLevel.FINER,
+ "Hello, World", null);
+ assertTrue(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate when levels are JDK 1.4 levels and not equal.
+ */
+ public void test6() {
+ LevelEqualsRule rule = (LevelEqualsRule) LevelEqualsRule.getRule("finer");
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), UtilLoggingLevel.FINE,
+ "Hello, World", null);
+ assertFalse(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate of a deserialized clone when levels are JDK 1.4 levels and equal.
+ */
+ public void test7() throws IOException, ClassNotFoundException {
+ LevelEqualsRule rule = (LevelEqualsRule)
+ SerializationTestHelper.serializeClone(LevelEqualsRule.getRule("finer"));
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), UtilLoggingLevel.FINER,
+ "Hello, World", null);
+ assertTrue(rule.evaluate(event));
+ }
+
+ /**
+ * Tests evaluate of a deserialized clone when levels are JDK 1.4 levels and not equal.
+ */
+ public void test8() throws IOException, ClassNotFoundException {
+ LevelEqualsRule rule = (LevelEqualsRule)
+ SerializationTestHelper.serializeClone(LevelEqualsRule.getRule("finer"));
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
+ Logger.getRootLogger(), System.currentTimeMillis(), UtilLoggingLevel.FINE,
+ "Hello, World", null);
+ assertFalse(rule.evaluate(event));
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org