This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new bfe0ef8d664 Add tests for yaml swappers and plugin helpers (#37518)
bfe0ef8d664 is described below
commit bfe0ef8d6641ce509f6067d583c3fb3a56cc0f4f
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Dec 25 18:53:30 2025 +0800
Add tests for yaml swappers and plugin helpers (#37518)
---
.../YamlAdvisorConfigurationSwapperTest.java | 57 +++++++++++++
.../YamlPointcutConfigurationSwapperTest.java | 93 ++++++++++++++++++++++
.../agent/core/builder/AgentJunctionTest.java | 57 +++++++++++++
.../AgentBuilderInterceptChainEngineTest.java | 57 +++++++++++++
.../loader/YamlPluginConfigurationLoaderTest.java | 65 +++++++++++++++
.../agent/core/plugin/jar/PluginJarLoaderTest.java | 63 +++++++++++++++
.../FileLoggingPluginLifecycleServiceTest.java | 57 +++++++++++++
7 files changed, 449 insertions(+)
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorConfigurationSwapperTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorConfigurationSwapperTest.java
new file mode 100644
index 00000000000..99f7003bfb3
--- /dev/null
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorConfigurationSwapperTest.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.shardingsphere.agent.core.advisor.config.yaml.swapper;
+
+import net.bytebuddy.description.method.MethodDescription;
+import
org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfiguration;
+import
org.apache.shardingsphere.agent.core.advisor.config.MethodAdvisorConfiguration;
+import
org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlAdvisorConfiguration;
+import
org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlPointcutConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+class YamlAdvisorConfigurationSwapperTest {
+
+ @Test
+ void assertSwapWithPointcut() throws NoSuchMethodException {
+ YamlAdvisorConfiguration yamlConfig = new YamlAdvisorConfiguration();
+ yamlConfig.setTarget(getClass().getName());
+ Object adviceMock = mock(Object.class);
+ yamlConfig.setAdvice(adviceMock.getClass().getName());
+ YamlPointcutConfiguration pointcutConfig = new
YamlPointcutConfiguration();
+ pointcutConfig.setType("method");
+ pointcutConfig.setName("call");
+ pointcutConfig.setParamLength(1);
+ yamlConfig.getPointcuts().add(pointcutConfig);
+ AdvisorConfiguration actual =
YamlAdvisorConfigurationSwapper.swap(yamlConfig, "PLUGIN");
+ assertThat(actual.getTargetClassName(), is(getClass().getName()));
+ assertThat(actual.getAdvisors().size(), is(1));
+ MethodAdvisorConfiguration advisorConfig =
actual.getAdvisors().iterator().next();
+ assertTrue(advisorConfig.getPointcut().matches(new
MethodDescription.ForLoadedMethod(YamlAdvisorConfigurationSwapperTest.class.getDeclaredMethod("call",
String.class))));
+ assertThat(advisorConfig.getAdviceClassName(),
is(adviceMock.getClass().getName()));
+ assertThat(advisorConfig.getPluginType(), is("PLUGIN"));
+ }
+
+ private String call(final String input) {
+ return input;
+ }
+}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlPointcutConfigurationSwapperTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlPointcutConfigurationSwapperTest.java
new file mode 100644
index 00000000000..c5b991fdd68
--- /dev/null
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlPointcutConfigurationSwapperTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.shardingsphere.agent.core.advisor.config.yaml.swapper;
+
+import net.bytebuddy.description.method.MethodDescription;
+import net.bytebuddy.description.method.MethodDescription.ForLoadedConstructor;
+import net.bytebuddy.description.method.MethodDescription.ForLoadedMethod;
+import net.bytebuddy.matcher.ElementMatcher;
+import
org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlPointcutConfiguration;
+import
org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlPointcutParameterConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class YamlPointcutConfigurationSwapperTest {
+
+ @Test
+ void assertSwapConstructorPointcutWithModifiersParametersAndReturn()
throws NoSuchMethodException {
+ YamlPointcutConfiguration yamlConfig = new YamlPointcutConfiguration();
+ yamlConfig.setType("constructor");
+ yamlConfig.setModifiers("public invalid static");
+ yamlConfig.setParamLength(1);
+ yamlConfig.setReturnType(String.class.getName());
+ YamlPointcutParameterConfiguration parameterConfig = new
YamlPointcutParameterConfiguration();
+ parameterConfig.setIndex(0);
+ parameterConfig.setType(String.class.getName());
+ yamlConfig.getParams().add(parameterConfig);
+ Optional<ElementMatcher<MethodDescription>> actual =
YamlPointcutConfigurationSwapper.swap(yamlConfig);
+ assertTrue(actual.isPresent());
+ assertFalse(actual.get().matches(new
ForLoadedConstructor(ConstructorFixture.class.getDeclaredConstructor(String.class))));
+ }
+
+ @Test
+ void assertSwapMethodPointcutAndInvalidType() throws NoSuchMethodException
{
+ YamlPointcutConfiguration methodConfig = new
YamlPointcutConfiguration();
+ methodConfig.setType("method");
+ methodConfig.setName("execute");
+ Optional<ElementMatcher<MethodDescription>> methodMatcher =
YamlPointcutConfigurationSwapper.swap(methodConfig);
+ assertTrue(methodMatcher.isPresent());
+ ForLoadedMethod methodDescription = new
ForLoadedMethod(MethodFixture.class.getDeclaredMethod("execute"));
+ assertTrue(methodMatcher.get().matches(methodDescription));
+ YamlPointcutConfiguration unsupportedConfig = new
YamlPointcutConfiguration();
+ unsupportedConfig.setType("unknown");
+
assertFalse(YamlPointcutConfigurationSwapper.swap(unsupportedConfig).isPresent());
+ }
+
+ @Test
+ void assertSwapMethodPointcutWithNegativeParamLength() throws
NoSuchMethodException {
+ YamlPointcutConfiguration methodConfig = new
YamlPointcutConfiguration();
+ methodConfig.setType("method");
+ methodConfig.setName("execute");
+ methodConfig.setParamLength(-1);
+ Optional<ElementMatcher<MethodDescription>> methodMatcher =
YamlPointcutConfigurationSwapper.swap(methodConfig);
+ assertTrue(methodMatcher.isPresent());
+ ForLoadedMethod methodDescription = new
ForLoadedMethod(MethodFixture.class.getDeclaredMethod("execute"));
+ assertTrue(methodMatcher.get().matches(methodDescription));
+ }
+
+ private static final class ConstructorFixture {
+
+ @SuppressWarnings("unused")
+ ConstructorFixture() {
+ }
+
+ @SuppressWarnings("unused")
+ ConstructorFixture(final String value) {
+ }
+ }
+
+ private static final class MethodFixture {
+
+ private void execute() {
+ }
+ }
+}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentJunctionTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentJunctionTest.java
new file mode 100644
index 00000000000..aa0ef3579e0
--- /dev/null
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentJunctionTest.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.shardingsphere.agent.core.builder;
+
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+import
org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfiguration;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class AgentJunctionTest {
+
+ @Test
+ void assertMatchesWithExistingTarget() {
+ TypeDescription matched = mock(TypeDescription.class);
+ when(matched.getTypeName()).thenReturn("matched");
+ assertTrue(new AgentJunction(Collections.singletonMap("matched",
mock(AdvisorConfiguration.class))).matches(matched));
+ }
+
+ @Test
+ void assertMatchesWithoutTarget() {
+ TypeDescription unmatched = mock(TypeDescription.class);
+ when(unmatched.getTypeName()).thenReturn("unmatched");
+ assertFalse(new
AgentJunction(Collections.emptyMap()).matches(unmatched));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ void assertAndAndOrReturnNull() {
+ AgentJunction junction = new AgentJunction(Collections.emptyMap());
+ ElementMatcher<TypeDescription> matcher = mock(ElementMatcher.class);
+ assertNull(junction.and(matcher));
+ assertNull(junction.or(matcher));
+ }
+}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/interceptor/AgentBuilderInterceptChainEngineTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/interceptor/AgentBuilderInterceptChainEngineTest.java
new file mode 100644
index 00000000000..0157cfbdeb6
--- /dev/null
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/interceptor/AgentBuilderInterceptChainEngineTest.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.shardingsphere.agent.core.builder.interceptor;
+
+import net.bytebuddy.dynamic.DynamicType.Builder;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class AgentBuilderInterceptChainEngineTest {
+
+ @SuppressWarnings("unchecked")
+ @Test
+ void assertIntercept() {
+ Builder<Object> builder = mock(Builder.class);
+ Builder<Object> firstResult = mock(Builder.class);
+ Builder<Object> secondResult = mock(Builder.class);
+ AgentBuilderInterceptor first = mock(AgentBuilderInterceptor.class);
+ AgentBuilderInterceptor second = mock(AgentBuilderInterceptor.class);
+ AtomicReference<Builder<?>> firstReceived = new AtomicReference<>();
+ AtomicReference<Builder<?>> secondReceived = new AtomicReference<>();
+ when(first.intercept(builder)).then(invocation -> {
+ firstReceived.set(invocation.getArgument(0));
+ return firstResult;
+ });
+ when(second.intercept(firstResult)).then(invocation -> {
+ secondReceived.set(invocation.getArgument(0));
+ return secondResult;
+ });
+ assertThat(AgentBuilderInterceptChainEngine.intercept(builder, first,
second), is(secondResult));
+ assertThat(firstReceived.get(), is(builder));
+ assertThat(secondReceived.get(), is(firstResult));
+ inOrder(first, second).verify(first).intercept(builder);
+ inOrder(first, second).verify(second).intercept(firstResult);
+ }
+}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/loader/YamlPluginConfigurationLoaderTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/loader/YamlPluginConfigurationLoaderTest.java
new file mode 100644
index 00000000000..785354fd9f4
--- /dev/null
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/loader/YamlPluginConfigurationLoaderTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.shardingsphere.agent.core.plugin.config.yaml.loader;
+
+import
org.apache.shardingsphere.agent.core.plugin.config.yaml.entity.YamlAgentConfiguration;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class YamlPluginConfigurationLoaderTest {
+
+ @Test
+ void assertLoad(@TempDir final Path tempDir) throws IOException {
+ Path yamlFile = tempDir.resolve("agent.yaml");
+ String yamlContent = ""
+ + "plugins:\n"
+ + " logging:\n"
+ + " FILE:\n"
+ + " host: localhost\n"
+ + " port: 3307\n"
+ + " password: root\n"
+ + " props:\n"
+ + " level: INFO\n";
+ Files.write(yamlFile, yamlContent.getBytes(StandardCharsets.UTF_8));
+ Optional<YamlAgentConfiguration> actual =
YamlPluginConfigurationLoader.load(yamlFile.toFile());
+ assertTrue(actual.isPresent());
+
assertThat(actual.get().getPlugins().getLogging().get("FILE").getHost(),
is("localhost"));
+
assertThat(actual.get().getPlugins().getLogging().get("FILE").getPort(),
is(3307));
+
assertThat(actual.get().getPlugins().getLogging().get("FILE").getPassword(),
is("root"));
+
assertThat(actual.get().getPlugins().getLogging().get("FILE").getProps().get("level"),
is("INFO"));
+ }
+
+ @Test
+ void assertLoadEmptyYaml(@TempDir final Path tempDir) throws IOException {
+ File yamlFile = tempDir.resolve("empty.yaml").toFile();
+ Files.write(yamlFile.toPath(), new byte[0]);
+ assertFalse(YamlPluginConfigurationLoader.load(yamlFile).isPresent());
+ }
+}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoaderTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoaderTest.java
new file mode 100644
index 00000000000..03b27ed918e
--- /dev/null
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/jar/PluginJarLoaderTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.shardingsphere.agent.core.plugin.jar;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class PluginJarLoaderTest {
+
+ @Test
+ void assertLoadJarFiles(@TempDir final Path tempDir) throws IOException {
+ Path pluginsDir = Files.createDirectory(tempDir.resolve("plugins"));
+ try (JarOutputStream jarOutputStream = new
JarOutputStream(Files.newOutputStream(pluginsDir.resolve("sample.jar")), new
Manifest())) {
+ jarOutputStream.putNextEntry(new JarEntry("sample.txt"));
+ jarOutputStream.write("sample".getBytes());
+ jarOutputStream.closeEntry();
+ }
+ Files.write(pluginsDir.resolve("README.txt"),
"ignored".getBytes(StandardCharsets.UTF_8));
+ Collection<JarFile> actual = PluginJarLoader.load(tempDir.toFile());
+ assertThat(actual.size(), is(1));
+ JarFile jarFile = actual.iterator().next();
+ assertThat(new File(jarFile.getName()).getName(), is("sample.jar"));
+ for (JarFile each : actual) {
+ each.close();
+ }
+ }
+
+ @Test
+ void assertLoadWithoutJar(@TempDir final Path tempDir) throws IOException {
+ Files.createDirectory(tempDir.resolve("plugins"));
+ assertTrue(PluginJarLoader.load(tempDir.toFile()).isEmpty());
+ }
+}
diff --git
a/agent/plugins/logging/type/file/src/test/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleServiceTest.java
b/agent/plugins/logging/type/file/src/test/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleServiceTest.java
new file mode 100644
index 00000000000..0b29b2afeba
--- /dev/null
+++
b/agent/plugins/logging/type/file/src/test/java/org/apache/shardingsphere/agent/plugin/logging/file/FileLoggingPluginLifecycleServiceTest.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.shardingsphere.agent.plugin.logging.file;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import org.apache.shardingsphere.agent.plugin.core.context.PluginContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class FileLoggingPluginLifecycleServiceTest {
+
+ @AfterEach
+ void resetContext() throws ReflectiveOperationException {
+
Plugins.getMemberAccessor().set(PluginContext.class.getDeclaredField("isEnhancedForProxy"),
PluginContext.getInstance(), false);
+ }
+
+ @Test
+ void assertStart() {
+ try (FileLoggingPluginLifecycleService lifecycleService = new
FileLoggingPluginLifecycleService()) {
+ lifecycleService.start(new PluginConfiguration("127.0.0.1", 9000,
"pwd", new Properties()), true);
+ assertTrue(getEnhancedForProxy());
+ lifecycleService.start(new PluginConfiguration("127.0.0.1", 9000,
"pwd", new Properties()), false);
+ assertFalse(getEnhancedForProxy());
+ assertThat(lifecycleService.getType(), is("File"));
+ }
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ private boolean getEnhancedForProxy() {
+ return (boolean)
Plugins.getMemberAccessor().get(PluginContext.class.getDeclaredField("isEnhancedForProxy"),
PluginContext.getInstance());
+
+ }
+}