Search in sources :

Example 1 with ArtifactRevision

use of org.jboss.pnc.dto.ArtifactRevision 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 ArtifactRevision

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

the class ArtifactProviderTest method testGetRevisions.

@Test
public void testGetRevisions() {
    // With
    final Integer revision = 1;
    ArtifactAudited aa1 = ArtifactAudited.fromArtifact(artifact1, revision);
    ArtifactAudited aa2 = ArtifactAudited.fromArtifact(artifact1, revision + 1);
    List<org.jboss.pnc.model.ArtifactAudited> artifactRevisions = new ArrayList<>();
    artifactRevisions.add(aa1);
    artifactRevisions.add(aa2);
    when(artifactAuditedRepository.findAllByIdOrderByRevDesc(artifact1.getId())).thenReturn(artifactRevisions);
    // When
    Page<ArtifactRevision> pagedAr = provider.getRevisions(0, 20, artifact1.getId().toString());
    // Then
    assertEquals(pagedAr.getContent().size(), 2);
    Iterator<ArtifactRevision> itARev = pagedAr.getContent().iterator();
    ArtifactRevision aRev1 = itARev.next();
    assertThat(aRev1.getId()).isEqualTo(artifact1.getId().toString());
    assertThat(aRev1.getRev()).isEqualTo(revision);
    ArtifactRevision aRev2 = itARev.next();
    assertThat(aRev2.getId()).isEqualTo(artifact1.getId().toString());
    assertThat(aRev2.getRev()).isEqualTo(revision + 1);
}
Also used : ArrayList(java.util.ArrayList) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) Test(org.junit.Test)

Example 3 with ArtifactRevision

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

the class ArtifactEndpointTest method shouldGetArtifactRevision.

@Test
public void shouldGetArtifactRevision() throws Exception {
    ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
    Iterator<ArtifactRevision> itOriginal = client.getRevisions(artifactRest1.getId()).iterator();
    // given latest revision
    ArtifactRevision lastRevOriginal = itOriginal.next();
    while (itOriginal.hasNext()) {
        ArtifactRevision candidate = itOriginal.next();
        if (candidate.getRev() > lastRevOriginal.getRev()) {
            lastRevOriginal = candidate;
        }
    }
    ArtifactRevision revision = client.getRevision(artifactRest1.getId(), lastRevOriginal.getRev());
    assertThat(revision.getId()).isEqualTo(artifactRest1.getId());
    assertThat(revision.getArtifactQuality()).isEqualTo(artifactRest1.getArtifactQuality());
    assertThat(revision.getModificationTime()).isEqualTo(artifactRest1.getModificationTime());
    assertThat(revision.getModificationUser()).isEqualTo(artifactRest1.getModificationUser());
    assertThat(revision.getQualityLevelReason()).isEqualTo(artifactRest1.getQualityLevelReason());
}
Also used : ArtifactClient(org.jboss.pnc.client.ArtifactClient) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 4 with ArtifactRevision

use of org.jboss.pnc.dto.ArtifactRevision 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 5 with ArtifactRevision

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

the class ArtifactProviderTest method testGetRevision.

@Test
public void testGetRevision() {
    // With
    final Integer revision = 1;
    ArtifactAudited aa = ArtifactAudited.fromArtifact(artifact1, revision);
    when(artifactAuditedRepository.queryById(new IdRev(artifact1.getId(), revision))).thenReturn(aa);
    // When
    ArtifactRevision ar = provider.getRevision(artifact1.getId().toString(), revision);
    // Then
    assertThat(ar).isNotNull();
    assertThat(ar.getId()).isEqualTo(artifact1.getId().toString());
    assertThat(ar.getRev()).isEqualTo(revision);
}
Also used : IdRev(org.jboss.pnc.model.IdRev) ArtifactAudited(org.jboss.pnc.model.ArtifactAudited) ArtifactRevision(org.jboss.pnc.dto.ArtifactRevision) Test(org.junit.Test)

Aggregations

ArtifactRevision (org.jboss.pnc.dto.ArtifactRevision)5 Test (org.junit.Test)5 ArtifactClient (org.jboss.pnc.client.ArtifactClient)3 ContainerTest (org.jboss.pnc.test.category.ContainerTest)3 Artifact (org.jboss.pnc.dto.Artifact)2 ArtifactAudited (org.jboss.pnc.model.ArtifactAudited)2 ArrayList (java.util.ArrayList)1 IdRev (org.jboss.pnc.model.IdRev)1