LOG4J2-435 renamed composite conditions - And to IfAll - Or to IfAny - Not to IfNot - similar for tests - added tests for new method beforeWalkFileTree
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/167abba2 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/167abba2 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/167abba2 Branch: refs/heads/master Commit: 167abba2ab81d20a0ab8f6a1c5f400759799a437 Parents: b174519 Author: rpopma <[email protected]> Authored: Thu Nov 26 23:49:45 2015 +0900 Committer: rpopma <[email protected]> Committed: Thu Nov 26 23:49:45 2015 +0900 ---------------------------------------------------------------------- .../log4j/core/appender/rolling/action/And.java | 76 ----------------- .../core/appender/rolling/action/IfAll.java | 86 ++++++++++++++++++++ .../core/appender/rolling/action/IfAny.java | 86 ++++++++++++++++++++ .../core/appender/rolling/action/IfNot.java | 77 ++++++++++++++++++ .../log4j/core/appender/rolling/action/Not.java | 70 ---------------- .../log4j/core/appender/rolling/action/Or.java | 74 ----------------- .../core/appender/rolling/action/AndTest.java | 41 ---------- .../rolling/action/CountingCondition.java | 62 ++++++++++++++ .../appender/rolling/action/FixedCondition.java | 3 + .../core/appender/rolling/action/IfAllTest.java | 49 +++++++++++ .../core/appender/rolling/action/IfAnyTest.java | 47 +++++++++++ .../core/appender/rolling/action/IfNotTest.java | 47 +++++++++++ .../core/appender/rolling/action/NotTest.java | 39 --------- .../core/appender/rolling/action/OrTest.java | 41 ---------- 14 files changed, 457 insertions(+), 341 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java deleted file mode 100644 index a103d64..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/And.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.logging.log4j.core.appender.rolling.action; - -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Arrays; -import java.util.Objects; - -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; - -/** - * Composite {@code PathCondition} that only accepts objects that are accepted by <em>all</em> component filters. - */ -@Plugin(name = "And", category = "Core", printObject = true) -public final class And implements PathCondition { - - private final PathCondition[] components; - - private And(final PathCondition... filters) { - this.components = Objects.requireNonNull(filters, "filters"); - } - - public PathCondition[] getDeleteFilters() { - return components; - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.appender.rolling.action.DeleteFilter#accept(java.nio.file.Path, - * java.nio.file.Path) - */ - @Override - public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { - for (final PathCondition component : components) { - if (!component.accept(baseDir, relativePath, attrs)) { - return false; - } - } - return true; - } - - /** - * Create a Composite PathCondition that all need to accept before this condition accepts. - * - * @param components The component filters. - * @return A Composite PathCondition. - */ - @PluginFactory - public static And createAndCondition( // - @PluginElement("PathConditions") final PathCondition... components) { - return new And(components); - } - - @Override - public String toString() { - return "And" + Arrays.toString(components); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAll.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAll.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAll.java new file mode 100644 index 0000000..8e086cd --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAll.java @@ -0,0 +1,86 @@ +/* + * 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.logging.log4j.core.appender.rolling.action; + +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Arrays; +import java.util.Objects; + +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; + +/** + * Composite {@code PathCondition} that only accepts objects that are accepted by <em>all</em> component conditions. + * Corresponds to logical "AND". + */ +@Plugin(name = "IfAll", category = "Core", printObject = true) +public final class IfAll implements PathCondition { + + private final PathCondition[] components; + + private IfAll(final PathCondition... filters) { + this.components = Objects.requireNonNull(filters, "filters"); + } + + public PathCondition[] getDeleteFilters() { + return components; + } + + /* + * (non-Javadoc) + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) + */ + @Override + public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { + for (final PathCondition component : components) { + if (!component.accept(baseDir, relativePath, attrs)) { + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() + */ + @Override + public void beforeFileTreeWalk() { + for (PathCondition condition : components) { + condition.beforeFileTreeWalk(); + } + } + + /** + * Create a Composite PathCondition whose components all need to accept before this condition accepts. + * + * @param components The component filters. + * @return A Composite PathCondition. + */ + @PluginFactory + public static IfAll createAndCondition( // + @PluginElement("PathConditions") final PathCondition... components) { + return new IfAll(components); + } + + @Override + public String toString() { + return "IfAll" + Arrays.toString(components); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAny.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAny.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAny.java new file mode 100644 index 0000000..30529d4 --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAny.java @@ -0,0 +1,86 @@ +/* + * 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.logging.log4j.core.appender.rolling.action; + +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Arrays; +import java.util.Objects; + +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; + +/** + * Composite {@code PathCondition} that accepts objects that are accepted by <em>any</em> component conditions. + * Corresponds to logical "OR". + */ +@Plugin(name = "IfAny", category = "Core", printObject = true) +public final class IfAny implements PathCondition { + + private final PathCondition[] components; + + private IfAny(final PathCondition... filters) { + this.components = Objects.requireNonNull(filters, "filters"); + } + + public PathCondition[] getDeleteFilters() { + return components; + } + + /* + * (non-Javadoc) + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) + */ + @Override + public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { + for (final PathCondition component : components) { + if (component.accept(baseDir, relativePath, attrs)) { + return true; + } + } + return false; + } + + /* + * (non-Javadoc) + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() + */ + @Override + public void beforeFileTreeWalk() { + for (PathCondition condition : components) { + condition.beforeFileTreeWalk(); + } + } + + /** + * Create a Composite PathCondition: accepts if any of the nested conditions accepts. + * + * @param components The component conditions. + * @return A Composite PathCondition. + */ + @PluginFactory + public static IfAny createOrCondition( // + @PluginElement("PathConditions") final PathCondition... components) { + return new IfAny(components); + } + + @Override + public String toString() { + return "IfAny" + Arrays.toString(components); + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java new file mode 100644 index 0000000..37d2eff --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfNot.java @@ -0,0 +1,77 @@ +/* + * 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.logging.log4j.core.appender.rolling.action; + +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Objects; + +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; + +/** + * Wrapper {@code PathCondition} that accepts objects that are rejected by the wrapped component filter. + */ +@Plugin(name = "IfNot", category = "Core", printObject = true) +public final class IfNot implements PathCondition { + + private final PathCondition negate; + + private IfNot(final PathCondition negate) { + this.negate = Objects.requireNonNull(negate, "filter"); + } + + public PathCondition getWrappedFilter() { + return negate; + } + + /* + * (non-Javadoc) + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#accept(java.nio.file.Path, java.nio.file.Path, java.nio.file.attribute.BasicFileAttributes) + */ + @Override + public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { + return !negate.accept(baseDir, relativePath, attrs); + } + + /* + * (non-Javadoc) + * @see org.apache.logging.log4j.core.appender.rolling.action.PathCondition#beforeFileTreeWalk() + */ + @Override + public void beforeFileTreeWalk() { + negate.beforeFileTreeWalk(); + } + + /** + * Create an IfNot PathCondition. + * + * @param condition The condition to negate. + * @return An IfNot PathCondition. + */ + @PluginFactory + public static IfNot createNotCondition( // + @PluginElement("PathConditions") final PathCondition condition) { + return new IfNot(condition); + } + + @Override + public String toString() { + return "IfNot(" + negate + ")"; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java deleted file mode 100644 index 8f43ef1..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Not.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.logging.log4j.core.appender.rolling.action; - -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Objects; - -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; - -/** - * Wrapper {@code PathCondition} that accepts objects that are rejected by the wrapped component filter. - */ -@Plugin(name = "Not", category = "Core", printObject = true) -public final class Not implements PathCondition { - - private final PathCondition negate; - - private Not(final PathCondition negate) { - this.negate = Objects.requireNonNull(negate, "filter"); - } - - public PathCondition getWrappedFilter() { - return negate; - } - - /* - * (non-Javadoc) - * - * @see org.apache.logging.log4j.core.appender.rolling.action.DeleteFilter#accept(java.nio.file.Path, - * java.nio.file.Path) - */ - @Override - public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { - return !negate.accept(baseDir, relativePath, attrs); - } - - /** - * Create a Not PathCondition. - * - * @param condition The condition to negate. - * @return A Not PathCondition. - */ - @PluginFactory - public static Not createNotCondition( // - @PluginElement("PathConditions") final PathCondition condition) { - return new Not(condition); - } - - @Override - public String toString() { - return "Not(" + negate + ")"; - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java deleted file mode 100644 index 542262f..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/Or.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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.logging.log4j.core.appender.rolling.action; - -import java.nio.file.Path; -import java.nio.file.attribute.BasicFileAttributes; -import java.util.Arrays; -import java.util.Objects; - -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; - -/** - * Composite {@code PathCondition} that accepts objects that are accepted by <em>any</em> component filters. - */ -@Plugin(name = "Or", category = "Core", printObject = true) -public final class Or implements PathCondition { - - private final PathCondition[] components; - - private Or(final PathCondition... filters) { - this.components = Objects.requireNonNull(filters, "filters"); - } - - public PathCondition[] getDeleteFilters() { - return components; - } - - /* (non-Javadoc) - * @see org.apache.logging.log4j.core.appender.rolling.action.DeleteFilter#accept(java.nio.file.Path, - * java.nio.file.Path) - */ - @Override - public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { - for (final PathCondition component : components) { - if (component.accept(baseDir, relativePath, attrs)) { - return true; - } - } - return false; - } - - /** - * Create a Composite PathCondition: accepts if any of the nested conditions accepts. - * - * @param components The component conditions. - * @return A Composite PathCondition. - */ - @PluginFactory - public static Or createOrCondition( // - @PluginElement("PathConditions") final PathCondition... components) { - return new Or(components); - } - - @Override - public String toString() { - return "Or" + Arrays.toString(components); - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java deleted file mode 100644 index f802557..0000000 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/AndTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.logging.log4j.core.appender.rolling.action; - -import org.apache.logging.log4j.core.appender.rolling.action.And; -import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the And composite filter. - */ -public class AndTest { - - @Test - public void test() { - final PathCondition TRUE = new FixedCondition(true); - final PathCondition FALSE = new FixedCondition(false); - assertTrue(And.createAndCondition(TRUE, TRUE).accept(null, null, null)); - assertFalse(And.createAndCondition(FALSE, TRUE).accept(null, null, null)); - assertFalse(And.createAndCondition(TRUE, FALSE).accept(null, null, null)); - assertFalse(And.createAndCondition(FALSE, FALSE).accept(null, null, null)); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java new file mode 100644 index 0000000..9355582 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/CountingCondition.java @@ -0,0 +1,62 @@ +/* + * 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.logging.log4j.core.appender.rolling.action; + +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; + +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; + +/** + * Test helper class. + */ +public class CountingCondition implements PathCondition { + + private final boolean accept; + private int acceptCount; + private int beforeFileTreeWalkCount; + + public CountingCondition(boolean accept) { + this.accept = accept; + } + + @Override + public boolean accept(Path baseDir, Path path, BasicFileAttributes attrs) { + acceptCount++; + return accept; + } + + @Override + public void beforeFileTreeWalk() { + beforeFileTreeWalkCount++; + } + + /** + * @return the acceptCount + */ + public int getAcceptCount() { + return acceptCount; + } + + /** + * @return the beforeFileTreeWalkCount + */ + public int getBeforeFileTreeWalkCount() { + return beforeFileTreeWalkCount; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java index 7a9faf7..e78f878 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/FixedCondition.java @@ -38,4 +38,7 @@ public class FixedCondition implements PathCondition { return accept; } + @Override + public void beforeFileTreeWalk() { + } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAllTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAllTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAllTest.java new file mode 100644 index 0000000..545c856 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAllTest.java @@ -0,0 +1,49 @@ +/* + * 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.logging.log4j.core.appender.rolling.action; + +import org.apache.logging.log4j.core.appender.rolling.action.IfAll; +import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the And composite condition. + */ +public class IfAllTest { + + @Test + public void testAccept() { + final PathCondition TRUE = new FixedCondition(true); + final PathCondition FALSE = new FixedCondition(false); + assertTrue(IfAll.createAndCondition(TRUE, TRUE).accept(null, null, null)); + assertFalse(IfAll.createAndCondition(FALSE, TRUE).accept(null, null, null)); + assertFalse(IfAll.createAndCondition(TRUE, FALSE).accept(null, null, null)); + assertFalse(IfAll.createAndCondition(FALSE, FALSE).accept(null, null, null)); + } + + @Test + public void testBeforeTreeWalk() { + final CountingCondition counter = new CountingCondition(true); + final IfAll and = IfAll.createAndCondition(counter, counter, counter); + and.beforeFileTreeWalk(); + assertEquals(3, counter.getBeforeFileTreeWalkCount()); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAnyTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAnyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAnyTest.java new file mode 100644 index 0000000..a90aa70 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAnyTest.java @@ -0,0 +1,47 @@ +/* + * 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.logging.log4j.core.appender.rolling.action; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the Or composite condition. + */ +public class IfAnyTest { + + @Test + public void test() { + final PathCondition TRUE = new FixedCondition(true); + final PathCondition FALSE = new FixedCondition(false); + assertTrue(IfAny.createOrCondition(TRUE, TRUE).accept(null, null, null)); + assertTrue(IfAny.createOrCondition(FALSE, TRUE).accept(null, null, null)); + assertTrue(IfAny.createOrCondition(TRUE, FALSE).accept(null, null, null)); + assertFalse(IfAny.createOrCondition(FALSE, FALSE).accept(null, null, null)); + } + + @Test + public void testBeforeTreeWalk() { + final CountingCondition counter = new CountingCondition(true); + final IfAny or = IfAny.createOrCondition(counter, counter, counter); + or.beforeFileTreeWalk(); + assertEquals(3, counter.getBeforeFileTreeWalkCount()); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfNotTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfNotTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfNotTest.java new file mode 100644 index 0000000..3f2a89a --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfNotTest.java @@ -0,0 +1,47 @@ +/* + * 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.logging.log4j.core.appender.rolling.action; + +import org.apache.logging.log4j.core.appender.rolling.action.IfNot; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the Not composite condition. + */ +public class IfNotTest { + + @Test + public void test() { + assertTrue(new FixedCondition(true).accept(null, null, null)); + assertFalse(IfNot.createNotCondition(new FixedCondition(true)).accept(null, null, null)); + + assertFalse(new FixedCondition(false).accept(null, null, null)); + assertTrue(IfNot.createNotCondition(new FixedCondition(false)).accept(null, null, null)); + } + + @Test + public void testBeforeTreeWalk() { + final CountingCondition counter = new CountingCondition(true); + final IfNot not = IfNot.createNotCondition(counter); + not.beforeFileTreeWalk(); + assertEquals(1, counter.getBeforeFileTreeWalkCount()); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java deleted file mode 100644 index d20018c..0000000 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/NotTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.logging.log4j.core.appender.rolling.action; - -import org.apache.logging.log4j.core.appender.rolling.action.Not; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the Not composite filter. - */ -public class NotTest { - - @Test - public void test() { - assertTrue(new FixedCondition(true).accept(null, null, null)); - assertFalse(Not.createNotCondition(new FixedCondition(true)).accept(null, null, null)); - - assertFalse(new FixedCondition(false).accept(null, null, null)); - assertTrue(Not.createNotCondition(new FixedCondition(false)).accept(null, null, null)); - } - -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/167abba2/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java deleted file mode 100644 index 7edc9ad..0000000 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/OrTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.logging.log4j.core.appender.rolling.action; - -import org.apache.logging.log4j.core.appender.rolling.action.Or; -import org.apache.logging.log4j.core.appender.rolling.action.PathCondition; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the Or composite filter. - */ -public class OrTest { - - @Test - public void test() { - final PathCondition TRUE = new FixedCondition(true); - final PathCondition FALSE = new FixedCondition(false); - assertTrue(Or.createOrCondition(TRUE, TRUE).accept(null, null, null)); - assertTrue(Or.createOrCondition(FALSE, TRUE).accept(null, null, null)); - assertTrue(Or.createOrCondition(TRUE, FALSE).accept(null, null, null)); - assertFalse(Or.createOrCondition(FALSE, FALSE).accept(null, null, null)); - } - -}
