Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Oct 1, 2023
1 parent 32d51d6 commit 40ddc69
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,17 +13,18 @@
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;
import java.security.MessageDigest;
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
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand All @@ -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());
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 40ddc69

Please sign in to comment.