diff --git a/platform-tooling-support-tests/projects/reflection-tests/build.gradle.kts b/platform-tooling-support-tests/projects/reflection-tests/build.gradle.kts new file mode 100644 index 000000000000..653257ae1042 --- /dev/null +++ b/platform-tooling-support-tests/projects/reflection-tests/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + java +} + +// grab jupiter version from system environment +val jupiterVersion: String = System.getenv("JUNIT_JUPITER_VERSION") +val vintageVersion: String = System.getenv("JUNIT_VINTAGE_VERSION") +val platformVersion: String = System.getenv("JUNIT_PLATFORM_VERSION") + +repositories { + maven { url = uri(file(System.getProperty("maven.repo"))) } + mavenCentral() +} + +dependencies { + testImplementation("org.junit.jupiter:junit-jupiter:$jupiterVersion") + testImplementation("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion") + testRuntimeOnly("org.junit.platform:junit-platform-reporting:$platformVersion") +} + +tasks.test { + useJUnitPlatform() + + testLogging { + events("failed") + } + + reports { + html.required = true + } + + val outputDir = reports.junitXml.outputLocation + jvmArgumentProviders += CommandLineArgumentProvider { + listOf( + "-Djunit.platform.reporting.open.xml.enabled=true", + "-Djunit.platform.reporting.output.dir=${outputDir.get().asFile.absolutePath}" + ) + } + + doFirst { + println("Using Java version: ${JavaVersion.current()}") + } +} diff --git a/platform-tooling-support-tests/projects/reflection-tests/settings.gradle.kts b/platform-tooling-support-tests/projects/reflection-tests/settings.gradle.kts new file mode 100644 index 000000000000..af17e8f41649 --- /dev/null +++ b/platform-tooling-support-tests/projects/reflection-tests/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "reflection-tests" diff --git a/platform-tooling-support-tests/projects/reflection-tests/src/test/java/ReflectionTestCase.java b/platform-tooling-support-tests/projects/reflection-tests/src/test/java/ReflectionTestCase.java new file mode 100644 index 000000000000..0692db43426b --- /dev/null +++ b/platform-tooling-support-tests/projects/reflection-tests/src/test/java/ReflectionTestCase.java @@ -0,0 +1,45 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package standalone; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.DynamicContainer.dynamicContainer; +import static org.junit.jupiter.api.DynamicTest.dynamicTest; + +import java.util.Arrays; +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicNode; +import org.junit.jupiter.api.TestFactory; +import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor; +import org.junit.jupiter.engine.descriptor.ClassTestDescriptor; +import org.junit.jupiter.engine.descriptor.JupiterTestDescriptor; +import org.junit.jupiter.engine.descriptor.MethodBasedTestDescriptor; +import org.junit.jupiter.engine.descriptor.NestedClassTestDescriptor; +import org.junit.jupiter.engine.descriptor.TestFactoryTestDescriptor; +import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor; +import org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor; +import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor; + +class ReflectionTestCase { + + @TestFactory + Stream canReadParameters() { + return Stream.of(JupiterTestDescriptor.class, ClassBasedTestDescriptor.class, ClassTestDescriptor.class, + MethodBasedTestDescriptor.class, TestMethodTestDescriptor.class, TestTemplateTestDescriptor.class, + TestTemplateInvocationTestDescriptor.class, TestFactoryTestDescriptor.class, + NestedClassTestDescriptor.class) // + .map(descriptorClass -> dynamicContainer(descriptorClass.getSimpleName(), + Arrays.stream(descriptorClass.getDeclaredMethods()) // + .map(method -> dynamicTest(method.getName(), + () -> assertDoesNotThrow(method::getParameters))))); + } +} diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ReflectionCompatibilityTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ReflectionCompatibilityTests.java new file mode 100644 index 000000000000..2a0b0f4c2189 --- /dev/null +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ReflectionCompatibilityTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package platform.tooling.support.tests; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static platform.tooling.support.Helper.TOOL_TIMEOUT; + +import java.nio.file.Paths; + +import de.sormuras.bartholdy.tool.GradleWrapper; + +import org.junit.jupiter.api.Test; +import org.opentest4j.TestAbortedException; + +import platform.tooling.support.Helper; +import platform.tooling.support.MavenRepo; +import platform.tooling.support.Request; + +/** + * @since 1.11 + */ +class ReflectionCompatibilityTests { + + @Test + void gradle_wrapper() { + var request = Request.builder() // + .setTool(new GradleWrapper(Paths.get(".."))) // + .setProject("reflection-tests") // + .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // + .addArguments("build", "--no-daemon", "--stacktrace") // + .setTimeout(TOOL_TIMEOUT) // + .setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) // + .build(); + + var result = request.run(); + + assertFalse(result.isTimedOut(), () -> "tool timed out: " + result); + + assertEquals(0, result.getExitCode()); + assertTrue(result.getOutputLines("out").stream().anyMatch(line -> line.contains("BUILD SUCCESSFUL"))); + assertThat(result.getOutput("out")).contains("Using Java version: 1.8"); + } +}