Hackathon integration tests for checkout Test environment - #2037
Hackathon integration tests for checkout Test environment#2037poojah-adyen wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a structured integration testing framework using Maven Failsafe, adding comprehensive documentation, configuration templates, and concrete integration tests for Checkout and Cloud Device APIs. Key feedback includes caching and properly closing the Client instance in BaseIntegrationTest to prevent resource leaks, safely loading classpath resources, supporting Java System properties for configuration overrides, and removing accidental system prompt tags from the documentation.
| protected final Client getClient() { | ||
| Environment environment = getEnvironment(); | ||
| Config config = new Config().apiKey(getApiKey()).environment(environment); | ||
|
|
||
| String liveEndpointUrlPrefix = getOptionalProperty(LIVE_ENDPOINT_URL_PREFIX_PROPERTY); | ||
| if (environment == Environment.LIVE && liveEndpointUrlPrefix != null) { | ||
| config.liveEndpointUrlPrefix(liveEndpointUrlPrefix); | ||
| } | ||
|
|
||
| return new Client(config); | ||
| } |
There was a problem hiding this comment.
The getClient() method currently instantiates a new Client on every call. Since Client holds an underlying HTTP client with connection pools and threads, creating multiple unclosed instances can lead to resource leaks (such as socket or thread exhaustion) and slower test execution due to repeated TLS handshakes. Caching the client instance and closing it after each test using @AfterEach resolves these issues and improves performance through connection reuse.
private Client client;
protected final Client getClient() {
if (client == null) {
Environment environment = getEnvironment();
Config config = new Config().apiKey(getApiKey()).environment(environment);
String liveEndpointUrlPrefix = getOptionalProperty(LIVE_ENDPOINT_URL_PREFIX_PROPERTY);
if (environment == Environment.LIVE && liveEndpointUrlPrefix != null) {
config.liveEndpointUrlPrefix(liveEndpointUrlPrefix);
}
client = new Client(config);
}
return client;
}
@AfterEach
protected void tearDownClient() throws IOException {
if (client != null) {
client.close();
client = null;
}
}| import com.adyen.enums.Environment; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Locale; | ||
| import java.util.Properties; |
There was a problem hiding this comment.
Add the org.junit.jupiter.api.AfterEach import to support tearing down and closing the cached Client instance after each test execution.
| import com.adyen.enums.Environment; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.util.Locale; | |
| import java.util.Properties; | |
| import com.adyen.enums.Environment; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.util.Locale; | |
| import java.util.Properties; | |
| import org.junit.jupiter.api.AfterEach; |
| try (InputStream inputStream = | ||
| BaseIntegrationTest.class.getClassLoader().getResourceAsStream(CONFIGURATION_RESOURCE)) { |
There was a problem hiding this comment.
Using BaseIntegrationTest.class.getClassLoader() can potentially return null if the class is loaded by the bootstrap classloader. It is safer and more idiomatic to use BaseIntegrationTest.class.getResourceAsStream with a leading slash to load classpath resources defensively.
| try (InputStream inputStream = | |
| BaseIntegrationTest.class.getClassLoader().getResourceAsStream(CONFIGURATION_RESOURCE)) { | |
| try (InputStream inputStream = | |
| BaseIntegrationTest.class.getResourceAsStream("/" + CONFIGURATION_RESOURCE)) { |
| private static String getOptionalProperty(String name) { | ||
| String property = System.getenv(name); | ||
| if (property == null || property.isBlank()) { | ||
| property = PROPERTIES.getProperty(name); | ||
| } | ||
| return property == null || property.isBlank() ? null : property; | ||
| } |
There was a problem hiding this comment.
The configuration lookup currently only checks environment variables and the properties file. It does not check Java System properties (System.getProperty(name)). Adding System properties to the lookup chain allows developers to easily override configuration values via standard Maven command-line flags (e.g., -DADYEN_API_KEY=...).
private static String getOptionalProperty(String name) {
String property = System.getenv(name);
if (property == null || property.isBlank()) {
property = System.getProperty(name);
}
if (property == null || property.isBlank()) {
property = PROPERTIES.getProperty(name);
}
return property == null || property.isBlank() ? null : property;
}| @@ -0,0 +1,59 @@ | |||
| <integration_test_guidelines> | |||
There was a problem hiding this comment.
|



Description
Tested scenarios
Fixed issue: