Search in sources :

Example 6 with Artifact

use of org.jboss.pnc.dto.Artifact in project pnc by project-ncl.

the class ArtifactEndpointTest method setTargetRepository.

@Before
public void setTargetRepository() throws RemoteResourceException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    List<Artifact> artifacts = new ArrayList<>();
    for (Artifact artifact : client.getAll(null, null, null)) {
        artifacts.add(artifact);
    }
    targetRepositoryRef = artifacts.get(0).getTargetRepository();
    artifactRest1 = artifacts.get(0);
    artifactRest2 = artifacts.get(1);
    artifactRest3 = artifacts.get(4);
    artifactRest4 = artifacts.get(6);
    logger.debug("Using targetRepositoryRef: {}", targetRepositoryRef);
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) ArrayList(java.util.ArrayList) Artifact(org.jboss.pnc.dto.Artifact) Before(org.junit.Before)

Example 7 with Artifact

use of org.jboss.pnc.dto.Artifact in project pnc by project-ncl.

the class ArtifactEndpointTest method testGetSpecificArtifact.

@Test
public void testGetSpecificArtifact() throws ClientException {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    Artifact artifact = client.getSpecific(artifactRest1.getId());
    assertThat(artifact.getId()).isEqualTo(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 8 with Artifact

use of org.jboss.pnc.dto.Artifact in project pnc by project-ncl.

the class ArtifactEndpointTest method shouldModifyModificationFields.

@Test
public void shouldModifyModificationFields() throws ClientException {
    String id = artifactRest1.getId();
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asSystem());
    // Updating an audited property should create a new revision and should alter modificationUser and
    // modificationTime. But, creationTime should never be updated, not creationUser
    Artifact artifact = client.getSpecific(id);
    Artifact updatedArtifact = artifact.toBuilder().modificationTime(Instant.now()).artifactQuality(ArtifactQuality.DEPRECATED).creationTime(Instant.now()).size(1000L).build();
    client.update(id, updatedArtifact);
    Artifact updatedArtifactDB = client.getSpecific(id);
    assertThat(updatedArtifactDB.getId()).isEqualTo(artifact.getId());
    assertThat(updatedArtifactDB.getArtifactQuality()).isEqualTo(updatedArtifact.getArtifactQuality());
    assertThat(updatedArtifactDB.getSize()).isEqualTo(updatedArtifact.getSize());
    assertThat(updatedArtifactDB.getCreationTime()).isEqualTo(artifact.getCreationTime());
    assertThat(updatedArtifactDB.getCreationUser()).isEqualTo(artifact.getCreationUser());
    assertThat(updatedArtifactDB.getModificationTime()).isNotEqualTo(artifact.getModificationTime());
    assertThat(updatedArtifactDB.getCreationTime()).isNotEqualTo(updatedArtifact.getCreationTime());
    assertThat(updatedArtifactDB.getModificationTime()).isNotEqualTo(updatedArtifact.getModificationTime());
}
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 9 with Artifact

use of org.jboss.pnc.dto.Artifact in project pnc by project-ncl.

the class ArtifactEndpointTest method shouldUpdateArtifact.

@Test
public void shouldUpdateArtifact() throws ClientException {
    String id = artifactRest1.getId();
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asSystem());
    Artifact artifact = client.getSpecific(id);
    final long size = artifact.getSize() + 10;
    Artifact updatedArtifact = artifact.toBuilder().size(size).build();
    client.update(id, updatedArtifact);
    Artifact artifact2 = client.getSpecific(id);
    assertThat(artifact2.getSize()).isEqualTo(size);
}
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 10 with Artifact

use of org.jboss.pnc.dto.Artifact in project pnc by project-ncl.

the class BuildEndpointTest method shouldReturnForbiddenCodeForPushOfBadQualityArtifact.

@Test
public void shouldReturnForbiddenCodeForPushOfBadQualityArtifact() throws RemoteResourceException {
    BuildClient client = new BuildClient(RestClientConfiguration.asSystem());
    ArtifactClient artifactClient = new ArtifactClient(RestClientConfiguration.asSystem());
    Artifact badQuality = artifactClient.create(Artifact.builder().artifactQuality(ArtifactQuality.DELETED).buildCategory(BuildCategory.STANDARD).filename("builtArtifactInsert2.jar").identifier("integration-test:built-artifact:jar:1.0").targetRepository(artifactClient.getSpecific("100").getTargetRepository()).md5("insert-md5-2").sha1("insert-2").sha256("insert-2").size(10L).build());
    client.setBuiltArtifacts(build2Id, Collections.singletonList(badQuality.getId()));
    assertThatThrownBy(() -> client.push(build2Id, BuildPushParameters.builder().reimport(true).tagPrefix("test-tag").build())).hasCauseInstanceOf(ForbiddenException.class);
}
Also used : BuildClient(org.jboss.pnc.client.BuildClient) ArtifactClient(org.jboss.pnc.client.ArtifactClient) Artifact(org.jboss.pnc.dto.Artifact) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

Artifact (org.jboss.pnc.dto.Artifact)31 Test (org.junit.Test)28 ContainerTest (org.jboss.pnc.test.category.ContainerTest)24 ArtifactClient (org.jboss.pnc.client.ArtifactClient)22 BuildClient (org.jboss.pnc.client.BuildClient)4 ArrayList (java.util.ArrayList)3 ArtifactRevision (org.jboss.pnc.dto.ArtifactRevision)3 List (java.util.List)2 TargetRepository (org.jboss.pnc.dto.TargetRepository)2 DTOValidationException (org.jboss.pnc.facade.validation.DTOValidationException)2 Before (org.junit.Before)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Iterator (java.util.Iterator)1 Collectors (java.util.stream.Collectors)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 BadRequestException (javax.ws.rs.BadRequestException)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Condition (org.assertj.core.api.Condition)1