Repository navigation
test: move the tests to JUnit 5 - #194
Conversation
Move all unit and integration tests from JUnit 4 (vintage engine) to JUnit Jupiter: - lifecycle annotations, Jupiter assertions (messages last), assertThrows instead of @test(expected), hamcrest's MatcherAssert - Spring Boot's test annotations instead of SpringRunner, the Spring extension where only plain Spring test annotations are used, and MockitoExtension instead of MockitoJUnitRunner - WireMockExtension instead of WireMockRule, OutputCaptureExtension instead of OutputCaptureRule, @tempdir instead of TemporaryFolder, and a @ParameterizedTest instead of the Parameterized runner - one @beforeeach in TesKubernetesConverterTest, as Jupiter doesn't order several of them KubernetesObjectsSupplier reads CONFIGMAP, CONFIGMAPNAMESPACE and CONFIGMAPKEY through Spring's Environment, which includes the environment variables, instead of System.getenv, so that the tests set them with a MockEnvironment instead of system-rules' EnvironmentVariables. Drop the vintage engine, system-rules and the --add-opens of Surefire that EnvironmentVariables needed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CONFIGMAP, CONFIGMAPNAMESPACE and CONFIGMAPKEY were missing from the configuration reference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- WireMock servers fail on unmatched requests again, as WireMockRule did (WireMockExtension doesn't by default) - CapturedOutput as a parameter of the tests that read it, except where shared helpers read it - wireMockConfig() for all WireMock options - the configuration reference names all the cases in which a security context ConfigMap stops TESK API from starting Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideImplementationInject Spring’s Environment into KubernetesObjectsSupplier and use it to resolve the ConfigMap name, namespace, and key instead of reading the process environment directly.
ConfigurationRemove the JUnit Vintage and system-rules dependencies and drop the module-opening arguments that were needed by system-rules.
DocumentationDocument the ConfigMap settings and describe the JUnit Jupiter conventions and test extensions used by the project.
TestsMigrate unit and integration tests to JUnit Jupiter and its extensions, update assertion and lifecycle APIs, and cover the Environment-based ConfigMap settings.
Other changesFiles not grouped.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #194 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 53 53
Lines 2260 2257 -3
Branches 255 254 -1
=========================================
- Hits 2260 2257 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The integration test came with #193 after the move. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Linked issuesChecked at commit 14fb18a #167 test: move the tests to JUnit 5 · 6 of 6 met
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserInfoTokenIntrospectorTest.java" line_range="159-160" />
<code_context>
+ static void mockUngroupedTaskKubernetesResponses(
+ WireMockExtension mockKubernetes, String userId) {
mockTaskKubernetesResponses(mockKubernetes, taskmaster(null, userId));
}
/** Lets task-123 be a task of the user {@code userId} for the group {@code group} */
</code_context>
<issue_to_address>
**Refused-response test flakes**
When another local process binds the released port and serves valid user-info JSON, `introspector.introspect` accepts the response, so `refused()`'s `assertThrows` fails.
Test refusal with a deterministic approach that does not depend on a released port remaining unused.
</issue_to_address>
### Comment 2
<location path="src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java" line_range="72" />
<code_context>
+ environment.setProperty("CONFIGMAP", "security");
+ environment.setProperty("CONFIGMAPNAMESPACE", "config");
+ environment.setProperty("CONFIGMAPKEY", "executors");
configMap("security", "config", new V1ConfigMap().putDataItem("executors", "{}"));
assertThat(securityContext()).isEqualTo(new V1PodSecurityContext());
</code_context>
<issue_to_address>
**Custom key regressions pass**
When the supplier ignores `CONFIGMAPKEY` and the ConfigMap has no `securityContext` key, `emptySecurityContext` (line 74) and `configMapWithoutTheKey` (line 85) both expect an empty context, which is also returned if the supplier ignores `CONFIGMAPKEY` and looks for an absent default key, so the configured-key lookup regression passes.
Make a test with a nonempty value under the configured non-default key and assert the resulting security context.
Also at `src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java:82`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and spring’s Environment can resolve CONFIGMAP and its namespace/key from property sources beyond process environment variables, potentially selecting a different ConfigMap and applying unintended security settings to executor pods. Reverting changes future startups, but cannot undo effects of jobs already launched with that pod security context.
Blocking findings: src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserInfoTokenIntrospectorTest.java:160, src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java:72
- the unreachable user info endpoint is a port that a bound, non-listening socket holds during the call, instead of a port that was free a moment ago and that another process could take - a test of a custom ConfigMap namespace and key with a non-empty security context, so that a supplier that ignored CONFIGMAPKEY would fail it Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Moves all unit and integration tests from JUnit 4 (vintage engine) to JUnit Jupiter, and drops JUnit 4, the vintage engine, system-rules and the
--add-opensof Surefire'sargLine.assertThrowsinstead of@Test(expected)(wrapping only the call that throws), hamcrest'sMatcherAssertSpringRunner(@ExtendWith(SpringExtension.class)where only plain Spring test annotations are used),MockitoExtensioninstead ofMockitoJUnitRunnerWireMockExtension(withfailOnUnmatchedRequests(true), asWireMockRulehad) instead ofWireMockRule,OutputCaptureExtensioninstead ofOutputCaptureRule,@TempDirinstead ofTemporaryFolder,@ParameterizedTestinstead of theParameterizedrunner@BeforeEachinTesKubernetesConverterTest, as Jupiter doesn't order several of themWireMockExtensionhas nostop())Production change (minimal seam):
KubernetesObjectsSupplierreadsCONFIGMAP,CONFIGMAPNAMESPACEandCONFIGMAPKEYthrough Spring'sEnvironment(a new constructor parameter, injected by Spring) instead ofSystem.getenv, so that tests set them with aMockEnvironmentinstead of system-rules'EnvironmentVariables. Deployments that set these environment variables behave as before (unset, empty and set values alike); as with any Spring setting, they can now also come from system properties, arguments orSPRING_APPLICATION_JSON.Docs:
docs/development.mddescribes the Jupiter setup;docs/configuration.mdgets the so far undocumentedCONFIGMAP*settings (separate commit).The migration was done with a script plus hand edits rather than the OpenRewrite recipe, whose own downloader couldn't get through the local sandbox's proxy.
Closes #167
Verification
./mvnw clean verify(Java 21): BUILD SUCCESS; 18562 unit tests and 122 integration tests (after mergingdevwith fix: honour forwarded headers outside Kubernetes #193 and moving its newForwardedHeadersIT), 0 failures; the same count per test class as ondev, plus one new test of a custom ConfigMap key and namespace (from the Sourcery review); the JaCoCo check (100% lines and branches) passes./mvnw spotless:check checkstyle:check(Java 8, as theLintjob): BUILD SUCCESS./mvnw dependency:list -DincludeScope=test: nojunit:junit, vintage engine or system-rules leftCI passed)Declined review findings
WireMockExtensiondeclarations of the integration tests, and static (per-class) WireMock servers: behaviour-preserving as is (the rules also restarted per test); a possible follow-up, kept out to keep this PR a 1:1 movepublicfrom test classes and methods, and replacing hamcrest's deprecatedisEmptyOrNullString: style only, kept out to keep the diff smallCONFIGMAPenvironment variable reaches theEnvironment: that is Spring Boot's ownSystemEnvironmentPropertySource; the new code is fully covered withMockEnvironmentOpen questions
None.
🤖 Generated with Claude Code