Search in sources :

Example 1 with ClientNotFoundException

use of net.nemerosa.ontrack.client.ClientNotFoundException in project ontrack by nemerosa.

the class ArtifactoryClientImpl method getBuildNumbers.

@Override
public List<String> getBuildNumbers(String buildName) {
    try {
        JsonNode node = jsonClient.get("/api/build/%s", buildName);
        List<String> numbers = new ArrayList<>();
        node.path("buildsNumbers").forEach((JsonNode numberNode) -> {
            String number = StringUtils.stripStart(numberNode.path("uri").asText(), "/");
            if (StringUtils.isNotBlank(number)) {
                numbers.add(number);
            }
        });
        return numbers;
    } catch (ClientNotFoundException ex) {
        // When the build is not defined, returns no build number
        return Collections.emptyList();
    }
}
Also used : ClientNotFoundException(net.nemerosa.ontrack.client.ClientNotFoundException) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with ClientNotFoundException

use of net.nemerosa.ontrack.client.ClientNotFoundException in project ontrack by nemerosa.

the class ArtifactoryClientImplTest method buildNumbersEmptyForBuildNotFound.

@Test
public void buildNumbersEmptyForBuildNotFound() {
    JsonClient jsonClient = mock(JsonClient.class);
    when(jsonClient.get("/api/build/%s", "PROJECT")).thenThrow(new ClientNotFoundException("Not found"));
    ArtifactoryClientImpl client = new ArtifactoryClientImpl(jsonClient);
    assertEquals(Collections.<String>emptyList(), client.getBuildNumbers("PROJECT"));
}
Also used : JsonClient(net.nemerosa.ontrack.client.JsonClient) ClientNotFoundException(net.nemerosa.ontrack.client.ClientNotFoundException) ArtifactoryClientImpl(net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClientImpl) Test(org.junit.Test)

Aggregations

ClientNotFoundException (net.nemerosa.ontrack.client.ClientNotFoundException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 JsonClient (net.nemerosa.ontrack.client.JsonClient)1 ArtifactoryClientImpl (net.nemerosa.ontrack.extension.artifactory.client.ArtifactoryClientImpl)1 Test (org.junit.Test)1