This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/main by this push:
new 14ffeaf8c0 Add test for record-based plugins
14ffeaf8c0 is described below
commit 14ffeaf8c0d80cfbcb768d7f27e37d5af2e4e80a
Author: Matt Sicker <[email protected]>
AuthorDate: Fri Jan 5 13:23:22 2024 -0600
Add test for record-based plugins
---
.../core/config/ConfigurationProcessorTest.java | 37 ++++++++++++++++++++++
.../test/validation/di/ConfigurableRecord.java | 37 ++++++++++++++++++++++
2 files changed, 74 insertions(+)
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationProcessorTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationProcessorTest.java
index f24f199a87..8e74b878e8 100644
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationProcessorTest.java
+++
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationProcessorTest.java
@@ -30,6 +30,7 @@ import
org.apache.logging.log4j.plugins.test.validation.ValidatingPlugin;
import
org.apache.logging.log4j.plugins.test.validation.ValidatingPluginWithGenericBuilder;
import
org.apache.logging.log4j.plugins.test.validation.ValidatingPluginWithTypedBuilder;
import org.apache.logging.log4j.plugins.test.validation.di.ConfigurablePlugin;
+import org.apache.logging.log4j.plugins.test.validation.di.ConfigurableRecord;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -57,6 +58,10 @@ class ConfigurationProcessorTest {
@Configurable
PluginType<PluginWithGenericSubclassFoo1Builder>
pluginWithGenericSubclassFoo1BuilderPluginType;
+ @Inject
+ @Configurable
+ PluginType<ConfigurableRecord> configurableRecordPluginType;
+
@BeforeEach
void setUp() {
instanceFactory.injectMembers(this);
@@ -139,4 +144,36 @@ class ConfigurationProcessorTest {
.returns("thought", from(ConfigurablePlugin::getDeltaThing))
.returns("bar2", from(ConfigurablePlugin::getDeltaName));
}
+
+ @Test
+ void configurableRecord() {
+ final Node root = Node.newBuilder()
+ .setName("root")
+ .setPluginType(configurableRecordPluginType)
+ .addChild(builder -> builder.setName("alpha")
+ .setPluginType(validatingPluginType)
+ .setAttribute("name", "Alpha"))
+ .addChild(builder -> builder.setName("beta")
+
.setPluginType(validatingPluginWithGenericBuilderPluginType)
+ .setAttribute("name", "Beta"))
+ .addChild(builder -> builder.setName("gamma")
+
.setPluginType(validatingPluginWithTypedBuilderPluginType)
+ .setAttribute("name", "Gamma"))
+ .addChild(builder -> builder.setName("delta")
+
.setPluginType(pluginWithGenericSubclassFoo1BuilderPluginType)
+ .setAttribute("thing", "thought")
+ .setAttribute("foo1", "bar2"))
+ .get();
+ final ConfigurableRecord result =
configurationProcessor.processNodeTree(root);
+ assertThat(result)
+ .hasNoNullFieldsOrProperties()
+ .returns("Alpha",
from(ConfigurableRecord::alpha).andThen(ValidatingPlugin::getName))
+ .returns("Beta",
from(ConfigurableRecord::beta).andThen(ValidatingPluginWithGenericBuilder::getName))
+ .returns("Gamma",
from(ConfigurableRecord::gamma).andThen(ValidatingPluginWithTypedBuilder::getName))
+ .returns(
+ "thought",
+
from(ConfigurableRecord::delta).andThen(PluginWithGenericSubclassFoo1Builder::getThing))
+ .returns(
+ "bar2",
from(ConfigurableRecord::delta).andThen(PluginWithGenericSubclassFoo1Builder::getFoo1));
+ }
}
diff --git
a/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/di/ConfigurableRecord.java
b/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/di/ConfigurableRecord.java
new file mode 100644
index 0000000000..d445be3e89
--- /dev/null
+++
b/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/di/ConfigurableRecord.java
@@ -0,0 +1,37 @@
+/*
+ * 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.plugins.test.validation.di;
+
+import org.apache.logging.log4j.plugins.Configurable;
+import org.apache.logging.log4j.plugins.Inject;
+import org.apache.logging.log4j.plugins.Plugin;
+import org.apache.logging.log4j.plugins.PluginElement;
+import
org.apache.logging.log4j.plugins.test.validation.PluginWithGenericSubclassFoo1Builder;
+import org.apache.logging.log4j.plugins.test.validation.ValidatingPlugin;
+import
org.apache.logging.log4j.plugins.test.validation.ValidatingPluginWithGenericBuilder;
+import
org.apache.logging.log4j.plugins.test.validation.ValidatingPluginWithTypedBuilder;
+
+@Configurable
+@Plugin
+public record ConfigurableRecord(
+ @PluginElement ValidatingPlugin alpha,
+ @PluginElement ValidatingPluginWithGenericBuilder beta,
+ @PluginElement ValidatingPluginWithTypedBuilder gamma,
+ @PluginElement PluginWithGenericSubclassFoo1Builder delta) {
+ @Inject
+ public ConfigurableRecord {}
+}