From 40ddc690e6f488e5e9bf95e025a36cb10585dd8f Mon Sep 17 00:00:00 2001 From: yahavi Date: Sun, 1 Oct 2023 10:14:56 +0300 Subject: [PATCH] CR --- .github/workflows/tests.yml | 4 -- .../client/ArtifactoryTestsBase.java | 42 +++++-------------- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 68621268..62c27dc8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -50,7 +50,3 @@ jobs: - name: Run tests run: ./gradlew${{ matrix.gradlewSuffix }} clean test - env: - CLIENTTESTS_ARTIFACTORY_URL: http://localhost:8081/artifactory - CLIENTTESTS_ARTIFACTORY_USERNAME: admin - CLIENTTESTS_ARTIFACTORY_PASSWORD: password diff --git a/services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTestsBase.java b/services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTestsBase.java index 43088f41..c85274da 100644 --- a/services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTestsBase.java +++ b/services/src/test/java/org/jfrog/artifactory/client/ArtifactoryTestsBase.java @@ -1,7 +1,7 @@ package org.jfrog.artifactory.client; -import org.apache.http.client.HttpResponseException; import org.apache.http.HttpEntity; +import org.apache.http.client.HttpResponseException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; @@ -13,6 +13,7 @@ import org.jfrog.artifactory.client.model.repository.settings.impl.MavenRepositorySettingsImpl; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -20,10 +21,10 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.Properties; + import static org.apache.commons.codec.binary.Base64.encodeBase64; import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.apache.commons.lang3.StringUtils.remove; -import static org.testng.Assert.fail; /** * @author jbaruch @@ -58,12 +59,12 @@ public void init() throws IOException { props.load(inputStream); } - url = readParam(props, "url"); + url = readParam(props, "url", "http://localhost:8081/artifactory"); if (!url.endsWith("/")) { url += "/"; } - username = readParam(props, "username"); - password = readParam(props, "password"); + username = readParam(props, "username", "admin"); + password = readParam(props, "password", "password"); filePath = "a/b"; fileSize = 141185; fileMd5 = "8f17d4271b86478a2731deebdab8c846"; @@ -97,9 +98,9 @@ public void init() throws IOException { } } - public static String readParam(Properties props, String paramName) { - String paramValue = null; - if (props.size() > 0) { + public static String readParam(Properties props, String paramName, String defaultValue) { + String paramValue = defaultValue; + if (!props.isEmpty()) { paramValue = props.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + paramName); } if (paramValue == null) { @@ -108,30 +109,9 @@ public static String readParam(Properties props, String paramName) { if (paramValue == null) { paramValue = System.getenv(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX + paramName.toUpperCase()); } - if (paramValue == null) { - failInit(); - } return paramValue; } - private static void failInit() { - String message = - new StringBuilder("Failed to load test Artifactory instance credentials. ") - .append("Looking for System properties '") - .append(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX) - .append("url', ") - .append(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX) - .append("username' and ") - .append(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX) - .append("password' or a properties file with those properties in classpath ") - .append("or Environment variables '") - .append(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX).append("URL', ") - .append(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX).append("USERNAME' and ") - .append(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX).append("PASSWORD'").toString(); - - fail(message); - } - @AfterClass public void clean() { deleteRepoIfExists(localRepository.getKey()); @@ -208,8 +188,8 @@ protected String deleteRepoIfExists(String repoName) { try { return artifactory.repository(repoName).delete(); } catch (Exception e) { - if (e instanceof HttpResponseException && ((HttpResponseException)e).getStatusCode() == 404) { - //if repo wasn't found - that's ok. + if (e instanceof HttpResponseException && ((HttpResponseException) e).getStatusCode() == 404) { + //if repo wasn't found - that's ok. return e.getMessage(); } else { throw e;