diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..62c27dc8 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,52 @@ +name: Tests +on: + push: + branches: + - '**' + tags-ignore: + - '**' + # Triggers the workflow on labeled PRs only. + pull_request_target: + types: [ labeled ] +# Ensures that only the latest commit is running for each PR at a time. +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.ref }} + cancel-in-progress: true +jobs: + Tests: + if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push' + name: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu, windows, macOS ] + include: + - os: windows + gradlewSuffix: .bat + runs-on: ${{ matrix.os }}-latest + steps: + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: 1.20.x + cache: false + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Setup Artifactory + run: | + go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest + ~/go/bin/local-rt-setup + env: + RTLIC: ${{secrets.RTLIC}} + GOPROXY: direct + + - name: Install Java + uses: actions/setup-java@v3 + with: + java-version: "8" + distribution: "temurin" + + - name: Run tests + run: ./gradlew${{ matrix.gradlewSuffix }} clean test diff --git a/README.md b/README.md index ac178b96..46dbd037 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ [![Scanned by Frogbot](https://raw.github.com/jfrog/frogbot/master/images/frogbot-badge.svg)](https://github.com/jfrog/frogbot#readme) -|Branch|Status| -|:---:|:---:| -|master|[![Build status](https://ci.appveyor.com/api/projects/status/sarjlbpi6dfgrd5w/branch/master?svg=true)](https://ci.appveyor.com/project/jfrog-ecosystem/artifactory-client-java/branch/master) -|dev|[![Build status](https://ci.appveyor.com/api/projects/status/sarjlbpi6dfgrd5w/branch/dev?svg=true)](https://ci.appveyor.com/project/jfrog-ecosystem/artifactory-client-java/branch/dev) +| Branch |Status| +|:------:|:---:| +|master|[![Test](https://github.com/jfrog/artifactory-client-java/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/jfrog/artifactory-client-java/actions/workflows/tests.yml?query=branch%3Amaster) +|dev|[![Test](https://github.com/jfrog/artifactory-client-java/actions/workflows/tests.yml/badge.svg?branch=dev)](https://github.com/jfrog/artifactory-client-java/actions/workflows/tests.yml?query=branch%3Adev) diff --git a/ci/appveyor.yml b/ci/appveyor.yml deleted file mode 100644 index d4fca21d..00000000 --- a/ci/appveyor.yml +++ /dev/null @@ -1,20 +0,0 @@ -image: - - Visual Studio 2017 - - Ubuntu - -stack: jdk 8 -environment: - APPVEYOR_SAVE_CACHE_ON_ERROR: true - APPVEYOR_YML_DISABLE_PS_LINUX: true - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 - -test_script: - - sh: ./gradlew test - - cmd: gradlew.bat test - -# Don't actually build. -build: off - -cache: - - C:\Users\appveyor\.gradle\ -> build.gradle - - /home/appveyor/.gradle/ -> build.gradle 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..13b254a8 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,8 @@ package org.jfrog.artifactory.client; -import org.apache.http.client.HttpResponseException; +import org.apache.commons.lang3.StringUtils; 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 +14,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 +22,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 +60,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,39 +99,12 @@ public void init() throws IOException { } } - public static String readParam(Properties props, String paramName) { - String paramValue = null; - if (props.size() > 0) { - paramValue = props.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + paramName); - } - if (paramValue == null) { - paramValue = System.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + 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); + public static String readParam(Properties props, String paramName, String defaultValue) { + return StringUtils.firstNonBlank( + props.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + paramName), + System.getProperty(CLIENTTESTS_ARTIFACTORY_PROPERTIES_PREFIX + paramName), + System.getenv(CLIENTTESTS_ARTIFACTORY_ENV_VAR_PREFIX + paramName.toUpperCase()), + defaultValue); } @AfterClass @@ -208,8 +183,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; diff --git a/services/src/test/java/org/jfrog/artifactory/client/StreamingRestCallTest.java b/services/src/test/java/org/jfrog/artifactory/client/StreamingRestCallTest.java index c29df72a..7261831e 100644 --- a/services/src/test/java/org/jfrog/artifactory/client/StreamingRestCallTest.java +++ b/services/src/test/java/org/jfrog/artifactory/client/StreamingRestCallTest.java @@ -47,11 +47,6 @@ public void testErrorStreamingRestCall() throws IOException { assertFalse(response.isSuccessResponse()); assertEquals(response.getStatusLine().getStatusCode(), 404); String raw = IOUtils.toString(response.getInputStream(), StandardCharsets.UTF_8); - assertEquals(raw, "{\n" + - " \"errors\" : [ {\n" + - " \"status\" : 404,\n" + - " \"message\" : \"File not found.\"\n" + - " } ]\n" + - "}"); + assertTrue(raw.contains("File not found"), "Expected response to contain 'File not found'.\nResponse:" + raw); } }