Search in sources :

Example 1 with ArtifactClient

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

the class ArtifactEndpointTest method shouldNotCreateBuildConfigRevision.

@Test
public void shouldNotCreateBuildConfigRevision() 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 a not audited property should not create a new revision
    Artifact artifact = client.getSpecific(id);
    Artifact updatedArtifact = artifact.toBuilder().size(1000L).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(numRevisionsOriginal).isEqualTo(numRevisions);
    assertThat(lastRev.getRev()).isEqualTo(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 2 with ArtifactClient

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

the class ArtifactEndpointTest method shouldModifyQualityLevel.

@Test
public void shouldModifyQualityLevel() throws ClientException {
    String id = artifactRest4.getId();
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asUser());
    String REASON = "This artifact has become old enough";
    Artifact artifact = client.getSpecific(id);
    client.createQualityLevelRevision(id, "DEPrecated", REASON);
    Artifact updatedArtifactDB = client.getSpecific(id);
    assertThat(updatedArtifactDB.getId()).isEqualTo(artifact.getId());
    assertThat(updatedArtifactDB.getArtifactQuality()).isEqualTo(ArtifactQuality.DEPRECATED);
    assertThat(updatedArtifactDB.getQualityLevelReason()).isEqualTo(REASON);
    assertThat(updatedArtifactDB.getCreationTime()).isEqualTo(artifact.getCreationTime());
    assertThat(updatedArtifactDB.getModificationTime()).isNotEqualTo(artifact.getModificationTime());
    assertThat(updatedArtifactDB.getModificationUser().getUsername()).isEqualTo("demo-user");
}
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 3 with ArtifactClient

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

the class ArtifactEndpointTest method shouldNotApplyUnknownQualityLevel.

@Test
public void shouldNotApplyUnknownQualityLevel() throws ClientException {
    String id = artifactRest4.getId();
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asUser());
    String REASON = "This artifact will be marked as WHITELISTED";
    assertThatThrownBy(() -> client.createQualityLevelRevision(id, "WHITELISTED", REASON)).hasCauseInstanceOf(BadRequestException.class);
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with ArtifactClient

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

the class ArtifactEndpointTest method testGetAllArtifactsWithMd5AndSha256.

@Test
public void testGetAllArtifactsWithMd5AndSha256() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<Artifact> artifacts = client.getAll(artifactRest1.getSha256(), artifactRest1.getMd5(), null);
    assertThat(artifacts).hasSize(1).allSatisfy(a -> assertThat(a.getId()).isIn(artifactRest1.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 5 with ArtifactClient

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

the class ArtifactEndpointTest method shouldFailToSaveArtifact.

@Test
public void shouldFailToSaveArtifact() {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asUser());
    Artifact artifact = Artifact.builder().filename("builtArtifactInsert.jar").identifier("integration-test:built-artifact-insert:jar:1.0").targetRepository(targetRepositoryRef).buildCategory(BuildCategory.STANDARD).md5("insert-md5-1").sha1("insert-1").sha256("insert-1").build();
    Exception caught = null;
    try {
        client.create(artifact);
    } catch (ClientException e) {
        caught = e;
    }
    Assertions.assertThat(caught).isNotNull();
    Assertions.assertThat(caught.getCause()).isInstanceOf(javax.ws.rs.ForbiddenException.class);
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) ClientException(org.jboss.pnc.client.ClientException) Artifact(org.jboss.pnc.dto.Artifact) ClientErrorException(javax.ws.rs.ClientErrorException) ClientException(org.jboss.pnc.client.ClientException) BadRequestException(javax.ws.rs.BadRequestException) RemoteResourceException(org.jboss.pnc.client.RemoteResourceException) 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