Skip to content

Commit bb2dfa1

Browse files
authored
Updates plugin framework test to use @DataPrepperPluginTest instead of extension (#6135)
Updated the approach to the plugin framework test to use only the DataPrepperPluginTest annotation. Split the ParameterResolver classes into multiple to make it easier to continue to extend this. Deprecate the DataPrepperPluginTestFrameworkExtension. Adds an integration test that runs the test framework for a test plugin. Signed-off-by: David Venable <dlv@amazon.com>
1 parent 3e71902 commit bb2dfa1

12 files changed

Lines changed: 346 additions & 2 deletions

data-prepper-test/plugin-test-framework/src/main/java/org/opensearch/dataprepper/test/plugins/DataPrepperPluginTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
package org.opensearch.dataprepper.test.plugins;
1111

12+
import org.opensearch.dataprepper.test.plugins.junit.DataPrepperPluginTestFramework;
13+
1214
import java.lang.annotation.ElementType;
1315
import java.lang.annotation.Retention;
1416
import java.lang.annotation.RetentionPolicy;
@@ -21,6 +23,7 @@
2123
*/
2224
@Retention(RetentionPolicy.RUNTIME)
2325
@Target(ElementType.TYPE)
26+
@DataPrepperPluginTestFramework
2427
public @interface DataPrepperPluginTest {
2528
/**
2629
* Provides the name of the plugin.

data-prepper-test/plugin-test-framework/src/main/java/org/opensearch/dataprepper/test/plugins/junit/BaseDataPrepperPluginStandardTestSuite.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import org.junit.jupiter.api.DynamicTest;
1313
import org.junit.jupiter.api.TestFactory;
14-
import org.junit.jupiter.api.extension.ExtendWith;
1514
import org.opensearch.dataprepper.plugin.PluginProvider;
1615

1716
import java.util.stream.Stream;
@@ -22,7 +21,6 @@
2221
*
2322
* @since 2.13
2423
*/
25-
@ExtendWith(DataPrepperPluginTestFrameworkExtension.class)
2624
public class BaseDataPrepperPluginStandardTestSuite {
2725
@TestFactory
2826
Stream<DynamicTest> standardDataPrepperPluginTests(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
package org.opensearch.dataprepper.test.plugins.junit;
11+
12+
import org.junit.jupiter.api.extension.ExtensionContext;
13+
import org.junit.jupiter.api.extension.ParameterContext;
14+
import org.junit.jupiter.api.extension.ParameterResolutionException;
15+
import org.junit.jupiter.api.extension.ParameterResolver;
16+
import org.opensearch.dataprepper.test.plugins.DataPrepperPluginTest;
17+
18+
class DataPrepperPluginTestContextParameterResolver implements ParameterResolver {
19+
@Override
20+
public boolean supportsParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException {
21+
return DataPrepperPluginTestContext.class.equals(parameterContext.getParameter().getType());
22+
}
23+
24+
@Override
25+
public Object resolveParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException {
26+
final Class<?> testClass = extensionContext.getRequiredTestClass();
27+
final DataPrepperPluginTest annotation = testClass.getAnnotation(DataPrepperPluginTest.class);
28+
if (annotation == null) {
29+
throw new ParameterResolutionException("Missing @DataPrepperPluginTest annotation on class: " + testClass.getName());
30+
}
31+
return new DataPrepperPluginTestContext(annotation.pluginName(), annotation.pluginType());
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
package org.opensearch.dataprepper.test.plugins.junit;
11+
12+
import org.junit.jupiter.api.extension.ExtendWith;
13+
14+
import java.lang.annotation.ElementType;
15+
import java.lang.annotation.Retention;
16+
import java.lang.annotation.RetentionPolicy;
17+
import java.lang.annotation.Target;
18+
19+
/**
20+
* An annotation to enable the Data Prepper plugin test framework
21+
* in JUnit.
22+
* <p>
23+
* Use {@link org.opensearch.dataprepper.test.plugins.DataPrepperPluginTest} instead.
24+
*/
25+
@Retention(RetentionPolicy.RUNTIME)
26+
@Target(ElementType.TYPE)
27+
@ExtendWith({
28+
DataPrepperPluginTestContextParameterResolver.class,
29+
PluginProviderParameterResolver.class
30+
})
31+
public @interface DataPrepperPluginTestFramework {
32+
}

data-prepper-test/plugin-test-framework/src/main/java/org/opensearch/dataprepper/test/plugins/junit/DataPrepperPluginTestFrameworkExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/**
2323
* A JUnit extension for using the Data Prepper plugin test framework.
2424
*/
25+
@Deprecated
2526
public class DataPrepperPluginTestFrameworkExtension implements ParameterResolver {
2627
private static final Set<Class<?>> SUPPORTED_CLASSES = Set.of(
2728
DataPrepperPluginTestContext.class,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
package org.opensearch.dataprepper.test.plugins.junit;
11+
12+
import org.junit.jupiter.api.extension.ExtensionContext;
13+
import org.junit.jupiter.api.extension.ParameterContext;
14+
import org.junit.jupiter.api.extension.ParameterResolutionException;
15+
import org.junit.jupiter.api.extension.ParameterResolver;
16+
import org.opensearch.dataprepper.plugin.ClasspathPluginProvider;
17+
import org.opensearch.dataprepper.plugin.PluginProvider;
18+
19+
class PluginProviderParameterResolver implements ParameterResolver {
20+
@Override
21+
public boolean supportsParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException {
22+
return PluginProvider.class.equals(parameterContext.getParameter().getType());
23+
}
24+
25+
@Override
26+
public Object resolveParameter(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException {
27+
return new ClasspathPluginProvider();
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
package org.opensearch.dataprepper.plugins.test;
11+
12+
public interface TestPluggableInterface {
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
package org.opensearch.dataprepper.plugins.test;
11+
12+
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin;
13+
import org.opensearch.dataprepper.model.annotations.DataPrepperPluginConstructor;
14+
15+
@DataPrepperPlugin(name = "test_plugin", pluginType = TestPluggableInterface.class, pluginConfigurationType = TestPluginConfiguration.class)
16+
public class TestPlugin {
17+
@DataPrepperPluginConstructor
18+
public TestPlugin(final TestPluginConfiguration configuration) {
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
package org.opensearch.dataprepper.plugins.test;
11+
12+
public class TestPluginConfiguration {
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
package org.opensearch.dataprepper.test.plugins;
11+
12+
import org.opensearch.dataprepper.plugins.test.TestPluggableInterface;
13+
import org.opensearch.dataprepper.test.plugins.junit.BaseDataPrepperPluginStandardTestSuite;
14+
15+
@DataPrepperPluginTest(pluginName = "test_plugin", pluginType = TestPluggableInterface.class)
16+
class DataPrepperPluginIT extends BaseDataPrepperPluginStandardTestSuite {
17+
}

0 commit comments

Comments
 (0)