You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sj...@apache.org on 2026/10/21 20:17:51 UTC
(tooling-atr-maven-plugin) branch main updated: Remove Maven API dependencies from ATR client package
This is an automated email from the ASF dual-hosted git repository.
slawekjaranowski pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-atr-maven-plugin.git
The following commit(s) were added to refs/heads/main by this push:
new 0f21e37 Remove Maven API dependencies from ATR client package
0f21e37 is described below
commit 0f21e37d85baf72096242261e0513be0f4dc7ca0
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Tue Oct 20 23:05:37 2026 +0200
Remove Maven API dependencies from ATR client package
Maven specific logic is moved to the new AtrClientProvider in the mojo package.
Missing credentials are reported by the client.
Co-Authored-By: Claude Opus 5.5 <no...@anthropic.com>
---
pom.xml | 5 ++
src/it/apache-release-profile/verify.groovy | 2 +-
src/it/check-composing/verify.groovy | 2 +-
.../org/apache/tooling/atr/AbstractAtrMojo.java | 19 ++---
...ientFactoryImpl.java => AtrClientProvider.java} | 66 +++++++++---------
.../org/apache/tooling/atr/CheckComposingMojo.java | 7 +-
.../java/org/apache/tooling/atr/UploadMojo.java | 6 +-
.../tooling/atr/client/AtrClientFactory.java | 8 ++-
.../tooling/atr/client/AtrClientFactoryImpl.java | 81 +---------------------
.../apache/tooling/atr/client/AtrClientImpl.java | 13 ++--
.../tooling/atr/client/AtrClientFactoryMock.java | 14 ++--
.../tooling/atr/client/AtrClientImplTest.java | 23 +++++-
.../apache/tooling/atr/client/AtrClientMock.java | 4 +-
13 files changed, 93 insertions(+), 157 deletions(-)
diff --git a/pom.xml b/pom.xml
index 37c58d3..628d537 100644
--- a/pom.xml
+++ b/pom.xml
@@ -204,6 +204,11 @@ under the License.
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-params</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
diff --git a/src/it/apache-release-profile/verify.groovy b/src/it/apache-release-profile/verify.groovy
index 1c53dd1..9456749 100644
--- a/src/it/apache-release-profile/verify.groovy
+++ b/src/it/apache-release-profile/verify.groovy
@@ -32,7 +32,7 @@ assert buildLog.text.contains('perform:run-perform-goals') :
assert buildLog.text.count('[INFO] [INFO] [Mock ATR client] using cached JWT: mock-jwt-dummy-asfuid') == 1 :
'Expected message not found in build log'
-assert buildLog.text.count('[INFO] [INFO] [Mock ATR client] created base URL: https://releases.apache.org/, username: dummy-asfuid, password: dummy-token') == 2 :
+assert buildLog.text.count('[INFO] [INFO] [Mock ATR client] created base URL: https://releases.apache.org/, username: dummy-asfuid, pat: dummy-token') == 2 :
'Expected message not found in build log'
assert buildLog.text.count('[INFO] [INFO] [Mock ATR client] getRelease: tooling-atr-test-apache-release, 1.0') == 1 :
diff --git a/src/it/check-composing/verify.groovy b/src/it/check-composing/verify.groovy
index 31f2eca..ae3313d 100644
--- a/src/it/check-composing/verify.groovy
+++ b/src/it/check-composing/verify.groovy
@@ -21,7 +21,7 @@
def buildLog = new File(basedir, 'build.log')
assert buildLog.exists()
-assert buildLog.text.count('[INFO] [Mock ATR client] created base URL: https://releases.apache.org/, username: dummy-asfuid, password: dummy-token') == 1:
+assert buildLog.text.count('[INFO] [Mock ATR client] created base URL: https://releases.apache.org/, username: dummy-asfuid, pat: dummy-token') == 1:
'Expected message not found in build log'
assert buildLog.text.count('[INFO] [Mock ATR client] getRelease: tooling-atr-check-composing, 1.0-SNAPSHOT') == 1:
diff --git a/src/main/java/org/apache/tooling/atr/AbstractAtrMojo.java b/src/main/java/org/apache/tooling/atr/AbstractAtrMojo.java
index 28ed204..134b0b6 100644
--- a/src/main/java/org/apache/tooling/atr/AbstractAtrMojo.java
+++ b/src/main/java/org/apache/tooling/atr/AbstractAtrMojo.java
@@ -19,8 +19,6 @@
package org.apache.tooling.atr;
import java.net.URL;
-import java.util.Comparator;
-import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -29,7 +27,6 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.tooling.atr.client.AtrClient;
import org.apache.tooling.atr.client.AtrClientException;
-import org.apache.tooling.atr.client.AtrClientFactory;
/**
* Abstract base class for ATR Mojos.
@@ -98,16 +95,11 @@ public abstract class AbstractAtrMojo extends AbstractMojo {
private final MavenProject mavenProject;
- private final AtrClientFactory atrClientFactory;
+ private final AtrClientProvider atrClientProvider;
- protected AbstractAtrMojo(MavenProject mavenProject, List<AtrClientFactory> atrClientFactory) {
+ AbstractAtrMojo(MavenProject mavenProject, AtrClientProvider atrClientProvider) {
this.mavenProject = mavenProject;
- // in test environments, there may be multiple AtrClientFactory implementations,
- // e.g., the default AtrClientFactoryImpl and a mock implementation,
- // so we select the one with the highest priority
- this.atrClientFactory = atrClientFactory.stream()
- .max(Comparator.comparingInt(AtrClientFactory::priority))
- .orElseThrow(() -> new IllegalStateException("No AtrClientFactory implementation found"));
+ this.atrClientProvider = atrClientProvider;
}
@Override
@@ -133,10 +125,9 @@ public abstract class AbstractAtrMojo extends AbstractMojo {
* Create an ATR client with JWT caching support.
*
* @return the ATR client
- * @throws AtrClientException if client creation fails
*/
- protected AtrClient createAtrClient() throws AtrClientException {
- return atrClientFactory.createAtrClient(url, serverId);
+ protected AtrClient createAtrClient() {
+ return atrClientProvider.createAtrClient(url, serverId);
}
/**
diff --git a/src/main/java/org/apache/tooling/atr/client/AtrClientFactoryImpl.java b/src/main/java/org/apache/tooling/atr/AtrClientProvider.java
similarity index 62%
copy from src/main/java/org/apache/tooling/atr/client/AtrClientFactoryImpl.java
copy to src/main/java/org/apache/tooling/atr/AtrClientProvider.java
index 7df40cd..a5d1e7b 100644
--- a/src/main/java/org/apache/tooling/atr/client/AtrClientFactoryImpl.java
+++ b/src/main/java/org/apache/tooling/atr/AtrClientProvider.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tooling.atr.client;
+package org.apache.tooling.atr;
import javax.inject.Inject;
import javax.inject.Named;
@@ -24,6 +24,8 @@ import javax.inject.Provider;
import javax.inject.Singleton;
import java.net.URL;
+import java.util.Comparator;
+import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.maven.execution.MavenSession;
@@ -31,54 +33,63 @@ import org.apache.maven.settings.Server;
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
+import org.apache.tooling.atr.client.AtrClient;
+import org.apache.tooling.atr.client.AtrClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Factory for creating ATR clients.
+ * Provides ATR clients configured from the Maven session: credentials are taken from settings.xml
+ * and the JWT is cached in the repository session.
*/
@Named
@Singleton
-public class AtrClientFactoryImpl implements AtrClientFactory {
+class AtrClientProvider {
- private final Logger logger = LoggerFactory.getLogger(AtrClientFactoryImpl.class);
+ private final Logger logger = LoggerFactory.getLogger(AtrClientProvider.class);
private final Provider<MavenSession> mavenSessionProvider;
private final SettingsDecrypter settingsDecrypter;
+ private final AtrClientFactory atrClientFactory;
+
@Inject
- AtrClientFactoryImpl(Provider<MavenSession> mavenSessionProvider, SettingsDecrypter settingsDecrypter) {
+ AtrClientProvider(
+ Provider<MavenSession> mavenSessionProvider,
+ SettingsDecrypter settingsDecrypter,
+ List<AtrClientFactory> atrClientFactories) {
this.mavenSessionProvider = mavenSessionProvider;
this.settingsDecrypter = settingsDecrypter;
- }
-
- @Override
- public int priority() {
- return -10;
+ // in test environments, there may be multiple AtrClientFactory implementations,
+ // e.g., the default AtrClientFactoryImpl and a mock implementation,
+ // so we select the one with the highest priority
+ this.atrClientFactory = atrClientFactories.stream()
+ .max(Comparator.comparingInt(AtrClientFactory::priority))
+ .orElseThrow(() -> new IllegalStateException("No AtrClientFactory implementation found"));
}
/**
* Create a new ATR client.
+ * <p>
+ * Credentials are taken from the server in settings.xml. If the server or its credentials are missing,
+ * the client is created without them and will report the error when authentication is required.
*
* @param baseUrl the base URL of the ATR server
* @param serverId the server ID from settings.xml containing the credentials for the ATR server
* @return the ATR client
- * @throws AtrClientException if the client cannot be created
*/
@SuppressWarnings("unchecked")
- public AtrClient createAtrClient(URL baseUrl, String serverId) throws AtrClientException {
+ AtrClient createAtrClient(URL baseUrl, String serverId) {
MavenSession session = mavenSessionProvider.get();
// retrieve the JWT from the session cache if it exists, otherwise create a new cache entry
AtomicReference<String> jwtCache = (AtomicReference<String>) session.getRepositorySession()
.getData()
.computeIfAbsent(dataKey(baseUrl, serverId), AtomicReference::new);
Server server = getServer(session, serverId);
- return newAtrClient(baseUrl, server.getUsername(), server.getPassword(), jwtCache);
- }
-
- protected AtrClient newAtrClient(URL baseUrl, String username, String password, AtomicReference<String> jwtCache) {
- return new AtrClientImpl(baseUrl, username, password, jwtCache);
+ String username = server != null ? server.getUsername() : null;
+ String pat = server != null ? server.getPassword() : null;
+ return atrClientFactory.createAtrClient(baseUrl, username, pat, jwtCache);
}
private Object dataKey(URL baseUrl, String serverId) {
@@ -88,31 +99,22 @@ public class AtrClientFactoryImpl implements AtrClientFactory {
/**
* Get and decrypt the server configuration.
*
- * @return the decrypted server
- * @throws AtrClientException if the server cannot be found or decrypted
+ * @return the decrypted server, or null if the server is not configured
*/
- private Server getServer(MavenSession session, String serverId) throws AtrClientException {
+ private Server getServer(MavenSession session, String serverId) {
Server server = session.getSettings().getServer(serverId);
if (server == null) {
- logger.error("Missing permissions for '{}' server in ~/.m2/settings.xml", serverId);
- throw new AtrClientException(
- "<server><id>" + serverId + "</id> not found in ~/.m2/settings.xml. "
- + "Please configure it with your ASF user ID as <username> and ATR Personal Access Token as <password> (encrypted if enabled).");
+ logger.debug("Server '{}' not found in settings.xml", serverId);
+ return null;
}
DefaultSettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
if (!result.getProblems().isEmpty()) {
- logger.warn("Problems decrypting server credentials: " + result.getProblems());
- }
-
- server = result.getServer();
- if (server.getUsername() == null || server.getPassword() == null) {
- throw new AtrClientException("Server '" + serverId
- + "' must have username (ASF user ID) and password (ATR PAT) configured in settings.xml.");
+ logger.warn("Problems decrypting server credentials: {}", result.getProblems());
}
- return server;
+ return result.getServer();
}
}
diff --git a/src/main/java/org/apache/tooling/atr/CheckComposingMojo.java b/src/main/java/org/apache/tooling/atr/CheckComposingMojo.java
index 20e0afe..0ba35b6 100644
--- a/src/main/java/org/apache/tooling/atr/CheckComposingMojo.java
+++ b/src/main/java/org/apache/tooling/atr/CheckComposingMojo.java
@@ -20,8 +20,6 @@ package org.apache.tooling.atr;
import javax.inject.Inject;
-import java.util.List;
-
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -29,7 +27,6 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.tooling.atr.client.AtrClient;
import org.apache.tooling.atr.client.AtrClientException;
-import org.apache.tooling.atr.client.AtrClientFactory;
/**
* Check if a version exists in ATR and is being composed (in draft phase).
@@ -49,8 +46,8 @@ public class CheckComposingMojo extends AbstractAtrMojo {
private boolean createVersion;
@Inject
- CheckComposingMojo(MavenProject mavenProject, List<AtrClientFactory> atrClientFactories) {
- super(mavenProject, atrClientFactories);
+ CheckComposingMojo(MavenProject mavenProject, AtrClientProvider atrClientProvider) {
+ super(mavenProject, atrClientProvider);
}
@Override
diff --git a/src/main/java/org/apache/tooling/atr/UploadMojo.java b/src/main/java/org/apache/tooling/atr/UploadMojo.java
index 46e7028..e556a9a 100644
--- a/src/main/java/org/apache/tooling/atr/UploadMojo.java
+++ b/src/main/java/org/apache/tooling/atr/UploadMojo.java
@@ -21,7 +21,6 @@ package org.apache.tooling.atr;
import javax.inject.Inject;
import java.nio.file.Path;
-import java.util.List;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -29,7 +28,6 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.tooling.atr.client.AtrClient;
import org.apache.tooling.atr.client.AtrClientException;
-import org.apache.tooling.atr.client.AtrClientFactory;
import org.codehaus.plexus.util.FileUtils;
/**
@@ -56,8 +54,8 @@ public class UploadMojo extends AbstractAtrMojo {
private String directory;
@Inject
- UploadMojo(MavenProject mavenProject, List<AtrClientFactory> atrClientFactories) {
- super(mavenProject, atrClientFactories);
+ UploadMojo(MavenProject mavenProject, AtrClientProvider atrClientProvider) {
+ super(mavenProject, atrClientProvider);
}
@Override
diff --git a/src/main/java/org/apache/tooling/atr/client/AtrClientFactory.java b/src/main/java/org/apache/tooling/atr/client/AtrClientFactory.java
index 06e956f..b7b2525 100644
--- a/src/main/java/org/apache/tooling/atr/client/AtrClientFactory.java
+++ b/src/main/java/org/apache/tooling/atr/client/AtrClientFactory.java
@@ -19,6 +19,7 @@
package org.apache.tooling.atr.client;
import java.net.URL;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Factory for creating ATR clients.
@@ -36,9 +37,10 @@ public interface AtrClientFactory {
* Create a new ATR client.
*
* @param baseUrl the base URL of the ATR server
- * @param serverId the server ID from settings.xml containing the credentials for the ATR server
+ * @param username the ASF user ID
+ * @param pat the ATR Personal Access Token (PAT)
+ * @param jwtCache the reference for caching JWT across clients
* @return the ATR client
- * @throws AtrClientException if the client cannot be created
*/
- AtrClient createAtrClient(URL baseUrl, String serverId) throws AtrClientException;
+ AtrClient createAtrClient(URL baseUrl, String username, String pat, AtomicReference<String> jwtCache);
}
diff --git a/src/main/java/org/apache/tooling/atr/client/AtrClientFactoryImpl.java b/src/main/java/org/apache/tooling/atr/client/AtrClientFactoryImpl.java
index 7df40cd..e15c483 100644
--- a/src/main/java/org/apache/tooling/atr/client/AtrClientFactoryImpl.java
+++ b/src/main/java/org/apache/tooling/atr/client/AtrClientFactoryImpl.java
@@ -18,22 +18,12 @@
*/
package org.apache.tooling.atr.client;
-import javax.inject.Inject;
import javax.inject.Named;
-import javax.inject.Provider;
import javax.inject.Singleton;
import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.settings.Server;
-import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
-import org.apache.maven.settings.crypto.SettingsDecrypter;
-import org.apache.maven.settings.crypto.SettingsDecryptionResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Factory for creating ATR clients.
*/
@@ -41,78 +31,13 @@ import org.slf4j.LoggerFactory;
@Singleton
public class AtrClientFactoryImpl implements AtrClientFactory {
- private final Logger logger = LoggerFactory.getLogger(AtrClientFactoryImpl.class);
-
- private final Provider<MavenSession> mavenSessionProvider;
-
- private final SettingsDecrypter settingsDecrypter;
-
- @Inject
- AtrClientFactoryImpl(Provider<MavenSession> mavenSessionProvider, SettingsDecrypter settingsDecrypter) {
- this.mavenSessionProvider = mavenSessionProvider;
- this.settingsDecrypter = settingsDecrypter;
- }
-
@Override
public int priority() {
return -10;
}
- /**
- * Create a new ATR client.
- *
- * @param baseUrl the base URL of the ATR server
- * @param serverId the server ID from settings.xml containing the credentials for the ATR server
- * @return the ATR client
- * @throws AtrClientException if the client cannot be created
- */
- @SuppressWarnings("unchecked")
- public AtrClient createAtrClient(URL baseUrl, String serverId) throws AtrClientException {
- MavenSession session = mavenSessionProvider.get();
- // retrieve the JWT from the session cache if it exists, otherwise create a new cache entry
- AtomicReference<String> jwtCache = (AtomicReference<String>) session.getRepositorySession()
- .getData()
- .computeIfAbsent(dataKey(baseUrl, serverId), AtomicReference::new);
- Server server = getServer(session, serverId);
- return newAtrClient(baseUrl, server.getUsername(), server.getPassword(), jwtCache);
- }
-
- protected AtrClient newAtrClient(URL baseUrl, String username, String password, AtomicReference<String> jwtCache) {
- return new AtrClientImpl(baseUrl, username, password, jwtCache);
- }
-
- private Object dataKey(URL baseUrl, String serverId) {
- return String.format("AtrClient-%s-%s", baseUrl, serverId);
- }
-
- /**
- * Get and decrypt the server configuration.
- *
- * @return the decrypted server
- * @throws AtrClientException if the server cannot be found or decrypted
- */
- private Server getServer(MavenSession session, String serverId) throws AtrClientException {
- Server server = session.getSettings().getServer(serverId);
- if (server == null) {
- logger.error("Missing permissions for '{}' server in ~/.m2/settings.xml", serverId);
- throw new AtrClientException(
- "<server><id>" + serverId + "</id> not found in ~/.m2/settings.xml. "
- + "Please configure it with your ASF user ID as <username> and ATR Personal Access Token as <password> (encrypted if enabled).");
- }
-
- DefaultSettingsDecryptionRequest request = new DefaultSettingsDecryptionRequest(server);
- SettingsDecryptionResult result = settingsDecrypter.decrypt(request);
-
- if (!result.getProblems().isEmpty()) {
- logger.warn("Problems decrypting server credentials: " + result.getProblems());
- }
-
- server = result.getServer();
- if (server.getUsername() == null || server.getPassword() == null) {
- throw new AtrClientException("Server '" + serverId
- + "' must have username (ASF user ID) and password (ATR PAT) configured in settings.xml.");
- }
-
- return server;
+ @Override
+ public AtrClient createAtrClient(URL baseUrl, String username, String pat, AtomicReference<String> jwtCache) {
+ return new AtrClientImpl(baseUrl, username, pat, jwtCache);
}
}
diff --git a/src/main/java/org/apache/tooling/atr/client/AtrClientImpl.java b/src/main/java/org/apache/tooling/atr/client/AtrClientImpl.java
index 87abb85..1d77d76 100644
--- a/src/main/java/org/apache/tooling/atr/client/AtrClientImpl.java
+++ b/src/main/java/org/apache/tooling/atr/client/AtrClientImpl.java
@@ -45,7 +45,7 @@ class AtrClientImpl implements AtrClient {
private final String username;
- private final String password;
+ private final String pat;
private final AtomicReference<String> jwtCache;
@@ -57,10 +57,10 @@ class AtrClientImpl implements AtrClient {
* @param baseUrl the base URL of the ATR server
* @param jwtCache the reference for caching JWT across goals
*/
- AtrClientImpl(URL baseUrl, String username, String password, AtomicReference<String> jwtCache) {
+ AtrClientImpl(URL baseUrl, String username, String pat, AtomicReference<String> jwtCache) {
this.baseUrl = baseUrl;
this.username = username;
- this.password = password;
+ this.pat = pat;
this.jwtCache = jwtCache;
this.objectMapper = new ObjectMapper();
}
@@ -76,9 +76,14 @@ class AtrClientImpl implements AtrClient {
return;
}
+ if (username == null || pat == null) {
+ throw new AtrClientException(
+ "Missing ATR credentials: username (ASF user ID) and PAT (Personal Access Token) are required");
+ }
+
try {
// Create JWT request
- JwtCreateRequest request = new JwtCreateRequest(username, password);
+ JwtCreateRequest request = new JwtCreateRequest(username, pat);
// Execute POST request
JwtCreateResponse jwtCreateResponse = executePost("api/jwt/create", request, JwtCreateResponse.class);
diff --git a/src/test/java/org/apache/tooling/atr/client/AtrClientFactoryMock.java b/src/test/java/org/apache/tooling/atr/client/AtrClientFactoryMock.java
index 4e332e4..f68e76f 100644
--- a/src/test/java/org/apache/tooling/atr/client/AtrClientFactoryMock.java
+++ b/src/test/java/org/apache/tooling/atr/client/AtrClientFactoryMock.java
@@ -18,16 +18,12 @@
*/
package org.apache.tooling.atr.client;
-import javax.inject.Inject;
import javax.inject.Named;
-import javax.inject.Provider;
import javax.inject.Singleton;
import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,13 +34,11 @@ import org.slf4j.LoggerFactory;
*/
@Named
@Singleton
-class AtrClientFactoryMock extends AtrClientFactoryImpl {
+class AtrClientFactoryMock implements AtrClientFactory {
private final Logger logger = LoggerFactory.getLogger(AtrClientFactoryMock.class);
- @Inject
- AtrClientFactoryMock(Provider<MavenSession> mavenSessionProvider, SettingsDecrypter settingsDecrypter) {
- super(mavenSessionProvider, settingsDecrypter);
+ AtrClientFactoryMock() {
logger.info("[Mock ATR client factory] created");
}
@@ -54,7 +48,7 @@ class AtrClientFactoryMock extends AtrClientFactoryImpl {
}
@Override
- protected AtrClient newAtrClient(URL baseUrl, String username, String password, AtomicReference<String> jwtCache) {
- return new AtrClientMock(baseUrl, username, password, jwtCache);
+ public AtrClient createAtrClient(URL baseUrl, String username, String pat, AtomicReference<String> jwtCache) {
+ return new AtrClientMock(baseUrl, username, pat, jwtCache);
}
}
diff --git a/src/test/java/org/apache/tooling/atr/client/AtrClientImplTest.java b/src/test/java/org/apache/tooling/atr/client/AtrClientImplTest.java
index f2e3df0..7610a56 100644
--- a/src/test/java/org/apache/tooling/atr/client/AtrClientImplTest.java
+++ b/src/test/java/org/apache/tooling/atr/client/AtrClientImplTest.java
@@ -31,6 +31,8 @@ import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
@@ -57,8 +59,7 @@ class AtrClientImplTest {
@BeforeEach
void setup(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
- atrClient =
- new AtrClientImpl(new URL(wmRuntimeInfo.getHttpBaseUrl()), "user", "password", new AtomicReference<>());
+ atrClient = new AtrClientImpl(new URL(wmRuntimeInfo.getHttpBaseUrl()), "user", "pat", new AtomicReference<>());
}
@Test
@@ -89,7 +90,23 @@ class AtrClientImplTest {
verify(
1,
postRequestedFor(urlEqualTo("/api/jwt/create"))
- .withRequestBody(equalTo("{\"asfuid\":\"user\",\"pat\":\"password\"}")));
+ .withRequestBody(equalTo("{\"asfuid\":\"user\",\"pat\":\"pat\"}")));
+ }
+
+ @ParameterizedTest
+ @CsvSource(
+ value = {"user, null", "null, pat", "null, null"},
+ nullValues = "null")
+ void missingCredentialsShouldThrowException(String username, String pat, WireMockRuntimeInfo wmRuntimeInfo)
+ throws Exception {
+ AtrClient client =
+ new AtrClientImpl(new URL(wmRuntimeInfo.getHttpBaseUrl()), username, pat, new AtomicReference<>());
+
+ AtrClientException exception =
+ assertThrows(AtrClientException.class, () -> client.getRelease("test-project", "1.0.0"));
+
+ assertTrue(exception.getMessage().startsWith("Missing ATR credentials"));
+ verify(0, postRequestedFor(urlEqualTo("/api/jwt/create")));
}
@Test
diff --git a/src/test/java/org/apache/tooling/atr/client/AtrClientMock.java b/src/test/java/org/apache/tooling/atr/client/AtrClientMock.java
index 94c733e..718d0ca 100644
--- a/src/test/java/org/apache/tooling/atr/client/AtrClientMock.java
+++ b/src/test/java/org/apache/tooling/atr/client/AtrClientMock.java
@@ -34,7 +34,7 @@ class AtrClientMock implements AtrClient {
private final Logger logger = LoggerFactory.getLogger(AtrClientMock.class);
- public AtrClientMock(URL baseUrl, String username, String password, AtomicReference<String> jwtCache) {
+ public AtrClientMock(URL baseUrl, String username, String pat, AtomicReference<String> jwtCache) {
String jwtCacheValue = jwtCache.get();
if (jwtCacheValue != null) {
logger.info("[Mock ATR client] using cached JWT: {}", jwtCacheValue);
@@ -43,7 +43,7 @@ class AtrClientMock implements AtrClient {
jwtCache.set("mock-jwt-" + username);
}
- logger.info("[Mock ATR client] created base URL: {}, username: {}, password: {}", baseUrl, username, password);
+ logger.info("[Mock ATR client] created base URL: {}, username: {}, pat: {}", baseUrl, username, pat);
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org