Search in sources :

Example 21 with ArtifactClient

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

the class ArtifactEndpointTest method testGetAllArtifactsWithMd5AndSha1.

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

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

the class ArtifactEndpointTest method shouldNotModifyBlacklistedQualityLevel.

@Test
public void shouldNotModifyBlacklistedQualityLevel() throws ClientException {
    String id = artifactRest3.getId();
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asSystem());
    String REASON = "This artifact has severe CVEs";
    Artifact artifact = client.getSpecific(id);
    client.createQualityLevelRevision(id, "BLACKLISTED", REASON);
    Artifact updatedArtifactDB = client.getSpecific(id);
    assertThat(updatedArtifactDB.getId()).isEqualTo(artifact.getId());
    assertThat(updatedArtifactDB.getArtifactQuality()).isEqualTo(ArtifactQuality.BLACKLISTED);
    assertThat(updatedArtifactDB.getQualityLevelReason()).isEqualTo(REASON);
    assertThat(updatedArtifactDB.getCreationTime()).isEqualTo(artifact.getCreationTime());
    assertThat(updatedArtifactDB.getModificationTime()).isNotEqualTo(artifact.getModificationTime());
    assertThat(updatedArtifactDB.getModificationUser().getUsername()).isEqualTo("system");
    assertThatThrownBy(() -> client.createQualityLevelRevision(id, "DEPRECATED", 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 23 with ArtifactClient

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

the class ArtifactEndpointTest method testGetAllArtifactsWithSha256.

@Test
public void testGetAllArtifactsWithSha256() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    RemoteCollection<Artifact> artifacts = client.getAll(artifactRest1.getSha256(), null, null);
    // artifacts 1 and 3 have same SHA256
    assertThat(artifacts).hasSize(2).allSatisfy(a -> assertThat(a.getId()).isIn(artifactRest1.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 24 with ArtifactClient

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

the class ArtifactEndpointTest method shouldNotStandardUserModifyUnallowedQualityLevel.

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

Example 25 with ArtifactClient

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

the class ArtifactEndpointTest method shouldSaveArtifact.

@Test
public void shouldSaveArtifact() throws ClientException {
    Artifact artifact = Artifact.builder().artifactQuality(ArtifactQuality.NEW).filename("builtArtifactInsert2.jar").identifier("integration-test:built-artifact-insert2:jar:1.0").targetRepository(targetRepositoryRef).buildCategory(BuildCategory.STANDARD).md5("insert-md5-2").sha1("insert-2").sha256("insert-2").size(10L).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.NEW);
    Assertions.assertThat(retrieved.getMd5()).isEqualTo("insert-md5-2");
    Assertions.assertThat(retrieved.getSize()).isEqualTo(10L);
    Artifact.Builder builder = inserted.toBuilder();
    builder.artifactQuality(ArtifactQuality.TESTED);
    Artifact update = builder.build();
    client.update(id, update);
    Artifact updated = client.getSpecific(id);
    Assertions.assertThat(updated.getArtifactQuality()).isEqualTo(ArtifactQuality.TESTED);
}
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)

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