Search in sources :

Example 26 with ArtifactClient

use of org.jboss.pnc.client.ArtifactClient in project pnc by project-ncl.

the class ArtifactEndpointTest method shouldCreateArtifactRevision.

@Test
public void shouldCreateArtifactRevision() throws ClientException {
    String id = artifactRest1.getId();
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asSystem());
    Iterator<ArtifactRevision> itOriginal = client.getRevisions(id).iterator();
    int numRevisionsOriginal = client.getRevisions(id).size();
    // given latest revision
    ArtifactRevision lastRevOriginal = itOriginal.next();
    while (itOriginal.hasNext()) {
        ArtifactRevision candidate = itOriginal.next();
        if (candidate.getRev() > lastRevOriginal.getRev()) {
            lastRevOriginal = candidate;
        }
    }
    // Updating an audited property should create a new revision
    Artifact artifact = client.getSpecific(id);
    Artifact updatedArtifact = artifact.toBuilder().artifactQuality(ArtifactQuality.TESTED).qualityLevelReason("Preliminary tests passed").build();
    client.update(id, updatedArtifact);
    Iterator<ArtifactRevision> it = client.getRevisions(id).iterator();
    int numRevisions = client.getRevisions(id).size();
    // given latest revision
    ArtifactRevision lastRev = it.next();
    while (it.hasNext()) {
        ArtifactRevision candidate = it.next();
        if (candidate.getRev() > lastRev.getRev()) {
            lastRev = candidate;
        }
    }
    assertThat(numRevisions).isGreaterThan(numRevisionsOriginal);
    assertThat(lastRev.getRev()).isGreaterThan(lastRevOriginal.getRev());
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) Artifact(org.jboss.pnc.dto.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 27 with ArtifactClient

use of org.jboss.pnc.client.ArtifactClient in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetAllArtifactsWithSha1AndSha256.

@Test
public void testGetAllArtifactsWithSha1AndSha256() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<Artifact> artifacts = client.getAll(artifactRest4.getSha256(), null, artifactRest4.getSha1());
    assertThat(artifacts).hasSize(1).allSatisfy(a -> assertThat(a.getId()).isIn(artifactRest4.getId()));
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) Artifact(org.jboss.pnc.dto.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 28 with ArtifactClient

use of org.jboss.pnc.client.ArtifactClient in project pnc by project-ncl.

the class ArtifactEndpointTest method shouldNotModifyTemporaryQualityLevel.

@Test
public void shouldNotModifyTemporaryQualityLevel() throws ClientException {
    Artifact artifact = Artifact.builder().artifactQuality(ArtifactQuality.TEMPORARY).buildCategory(BuildCategory.STANDARD).filename("temp-builtArtifactInsert2.jar").identifier("integration-test:temp-built-artifact-insert2:jar:1.0").targetRepository(targetRepositoryRef).md5("insert-md5-13").sha1("insert-13").sha256("insert-13").size(13L).build();
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asSystem());
    Artifact inserted = client.create(artifact);
    String id = inserted.getId();
    Artifact retrieved = client.getSpecific(id);
    Assertions.assertThat(retrieved.getArtifactQuality()).isEqualTo(ArtifactQuality.TEMPORARY);
    String REASON = "This artifact has severe CVEs";
    assertThatThrownBy(() -> client.createQualityLevelRevision(id, "BLACKLISTED", REASON)).hasCauseInstanceOf(ClientErrorException.class);
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) Artifact(org.jboss.pnc.dto.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 29 with ArtifactClient

use of org.jboss.pnc.client.ArtifactClient in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetAllArtifactsWithSha1.

@Test
public void testGetAllArtifactsWithSha1() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<Artifact> artifacts = client.getAll(null, null, artifactRest2.getSha1());
    // artifacts 2 and 3 have same SHA1
    assertThat(artifacts).hasSize(2).allSatisfy(a -> assertThat(a.getId()).isIn(artifactRest2.getId(), artifactRest4.getId()));
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) Artifact(org.jboss.pnc.dto.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 30 with ArtifactClient

use of org.jboss.pnc.client.ArtifactClient in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetAllArtifactsFilteredByRepoType.

@Test
public void testGetAllArtifactsFilteredByRepoType() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<ArtifactInfo> result;
    RepositoryType type = RepositoryType.NPM;
    result = client.getAllFiltered(null, null, type);
    // from DatabaseDataInitializer
    assertThat(result).hasSize(2).allSatisfy(a -> assertThat(a.getRepositoryType().equals(type)));
}
Also used : ArtifactInfo(org.jboss.pnc.dto.response.ArtifactInfo) RepositoryType(org.jboss.pnc.enums.RepositoryType) ArtifactClient(org.jboss.pnc.client.ArtifactClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

ArtifactClient (org.jboss.pnc.client.ArtifactClient)31 ContainerTest (org.jboss.pnc.test.category.ContainerTest)30 Test (org.junit.Test)30 Artifact (org.jboss.pnc.dto.Artifact)22 ArtifactInfo (org.jboss.pnc.dto.response.ArtifactInfo)4 ArtifactRevision (org.jboss.pnc.dto.ArtifactRevision)3 HashSet (java.util.HashSet)2 BuildClient (org.jboss.pnc.client.BuildClient)2 Build (org.jboss.pnc.dto.Build)2 ArrayList (java.util.ArrayList)1 BadRequestException (javax.ws.rs.BadRequestException)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 ClientException (org.jboss.pnc.client.ClientException)1 RemoteResourceException (org.jboss.pnc.client.RemoteResourceException)1 MilestoneInfo (org.jboss.pnc.dto.response.MilestoneInfo)1 RepositoryType (org.jboss.pnc.enums.RepositoryType)1 Before (org.junit.Before)1