You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2017/10/14 17:20:15 UTC
[02/15] logging-log4j2 git commit: Add unit tests for property
sources and utilities
Add unit tests for property sources and utilities
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/44254d2e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/44254d2e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/44254d2e
Branch: refs/heads/master
Commit: 44254d2edcd91cdfcb6fd1e92dde2cabb00057dc
Parents: fd39ef4
Author: Matt Sicker <bo...@gmail.com>
Authored: Sun Feb 5 15:30:48 2017 -0600
Committer: Matt Sicker <ma...@spr.com>
Committed: Sat Aug 26 15:50:56 2017 -0500
----------------------------------------------------------------------
.../util/EnvironmentPropertySourceTest.java | 58 ++++++++++++++++
.../util/PropertiesPropertySourceTest.java | 59 +++++++++++++++++
.../log4j/util/PropertySourceCamelCaseTest.java | 57 ++++++++++++++++
.../log4j/util/PropertySourceTokenizerTest.java | 69 ++++++++++++++++++++
4 files changed, 243 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44254d2e/log4j-api/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceTest.java
new file mode 100644
index 0000000..3beea89
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class EnvironmentPropertySourceTest {
+
+ private final PropertySource source = new EnvironmentPropertySource();
+ private final CharSequence expected;
+ private final List<? extends CharSequence> tokens;
+
+ public EnvironmentPropertySourceTest(final CharSequence expected, final List<? extends CharSequence> tokens) {
+ this.expected = expected;
+ this.tokens = tokens;
+ }
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Object[][] data() {
+ return new Object[][]{
+ {"LOG4J_CONFIGURATION_FILE", Arrays.asList("configuration", "file")},
+ {"LOG4J_FOO_BAR_PROPERTY", Arrays.asList("foo", "bar", "property")},
+ {"LOG4J_EXACT", Collections.singletonList("EXACT")},
+ {"LOG4J_TEST_PROPERTY_NAME", PropertySource.Util.tokenize("Log4jTestPropertyName")},
+ };
+ }
+
+ @Test
+ public void testNormalFormFollowsEnvironmentVariableConventions() throws Exception {
+ assertEquals(expected, source.getNormalForm(tokens));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44254d2e/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesPropertySourceTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesPropertySourceTest.java
new file mode 100644
index 0000000..2f07972
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesPropertySourceTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class PropertiesPropertySourceTest {
+
+ private final PropertySource source = new PropertiesPropertySource(new Properties());
+ private final CharSequence expected;
+ private final List<? extends CharSequence> tokens;
+
+ public PropertiesPropertySourceTest(final String expected, final List<CharSequence> tokens) {
+ this.expected = expected;
+ this.tokens = tokens;
+ }
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Object[][] data() {
+ return new Object[][]{
+ {"log4j2.configurationFile", Arrays.asList("configuration", "file")},
+ {"log4j2.fooBarProperty", Arrays.asList("foo", "bar", "property")},
+ {"log4j2.EXACT", Collections.singletonList("EXACT")},
+ {"log4j2.testPropertyName", PropertySource.Util.tokenize("Log4jTestPropertyName")},
+ };
+ }
+
+ @Test
+ public void testNormalFormFollowsCamelCaseConventions() throws Exception {
+ assertEquals(expected, source.getNormalForm(tokens));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44254d2e/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceCamelCaseTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceCamelCaseTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceCamelCaseTest.java
new file mode 100644
index 0000000..c746199
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceCamelCaseTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class PropertySourceCamelCaseTest {
+
+ private final CharSequence expected;
+ private final List<String> tokens;
+
+ public PropertySourceCamelCaseTest(final CharSequence expected, final List<String> tokens) {
+ this.expected = expected;
+ this.tokens = tokens;
+ }
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Object[][] data() {
+ return new Object[][]{
+ {"", Collections.singletonList("")},
+ {"foo", Collections.singletonList("foo")},
+ {"fooBar", Arrays.asList("foo", "bar")},
+ {"oneTwoThree", Arrays.asList("one", "two", "three")},
+ };
+ }
+
+ @Test
+ public void testJoinAsCamelCase() throws Exception {
+ assertEquals(expected, PropertySource.Util.joinAsCamelCase(tokens));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/44254d2e/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceTokenizerTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceTokenizerTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceTokenizerTest.java
new file mode 100644
index 0000000..3b25af7
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceTokenizerTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class PropertySourceTokenizerTest {
+
+ private final CharSequence value;
+ private final List<CharSequence> expectedTokens;
+
+ public PropertySourceTokenizerTest(final CharSequence value, final List<CharSequence> expectedTokens) {
+ this.value = value;
+ this.expectedTokens = expectedTokens;
+ }
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Object[][] data() {
+ return new Object[][]{
+ {"log4j.simple", Collections.singletonList("simple")},
+ {"log4j_simple", Collections.singletonList("simple")},
+ {"log4j-simple", Collections.singletonList("simple")},
+ {"log4j/simple", Collections.singletonList("simple")},
+ {"log4j2.simple", Collections.singletonList("simple")},
+ {"Log4jSimple", Collections.singletonList("simple")},
+ {"LOG4J_simple", Collections.singletonList("simple")},
+ {"org.apache.logging.log4j.simple", Collections.singletonList("simple")},
+ {"log4j.simpleProperty", Arrays.asList("simple", "property")},
+ {"log4j.simple_property", Arrays.asList("simple", "property")},
+ {"LOG4J_simple_property", Arrays.asList("simple", "property")},
+ {"LOG4J_SIMPLE_PROPERTY", Arrays.asList("simple", "property")},
+ {"log4j2-dashed-propertyName", Arrays.asList("dashed", "property", "name")},
+ {"Log4jProperty_with.all-the/separators", Arrays.asList("property", "with", "all", "the", "separators")},
+ {"org.apache.logging.log4j.config.property", Arrays.asList("config", "property")},
+ };
+ }
+
+ @Test
+ public void testTokenize() throws Exception {
+ List<CharSequence> tokens = PropertySource.Util.tokenize(value);
+ assertEquals(expectedTokens, tokens);
+ }
+}
\ No newline at end of file