Search in sources :

Example 11 with BuildClient

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

the class BuildEndpointTest method shouldFilterByUsername.

@Test
public void shouldFilterByUsername() throws Exception {
    BuildClient bc = new BuildClient(RestClientConfiguration.asAnonymous());
    String username = "demo-user";
    String rsql = "user.username==" + username;
    List<String> userNames = bc.getAll(null, null, Optional.empty(), Optional.of(rsql)).getAll().stream().map(Build::getUser).map(User::getUsername).collect(Collectors.toList());
    // from DatabaseDataInitializer
    assertThat(userNames).hasSize(2);
    assertThat(userNames).containsOnly(username);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 12 with BuildClient

use of org.jboss.pnc.client.BuildClient 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)

Example 13 with BuildClient

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

the class BuildEndpointTest method shouldGetSpecificBuild.

@Test
@InSequence(10)
public void shouldGetSpecificBuild() throws ClientException {
    BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
    Build dto = client.getSpecific(buildId);
    // from DatabaseDataInitializer
    assertThat(dto.getId()).isEqualTo(buildId);
    // from DatabaseDataInitializer
    assertThat(dto.getStatus()).isEqualTo(BuildStatus.SUCCESS);
    assertThat(dto.getBuildConfigRevision()).isNotNull();
    assertThat(dto.getBuildConfigRevision().getName()).isNotNull();
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 14 with BuildClient

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

the class BuildEndpointTest method shouldFilterByBuildConfigurationNameLike.

@Test
public void shouldFilterByBuildConfigurationNameLike() throws Exception {
    BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
    String buildConfigName = DatabaseDataInitializer.PNC_PROJECT_BUILD_CFG_ID;
    BuildsFilterParameters filter = new BuildsFilterParameters();
    filter.setBuildConfigName("*" + buildConfigName.substring(1, buildConfigName.length() - 2) + "*");
    List<String> buildConfigNames = client.getAll(filter, null).getAll().stream().map(Build::getBuildConfigRevision).map(BuildConfigurationRevisionRef::getName).collect(Collectors.toList());
    // from DatabaseDataInitializer
    assertThat(buildConfigNames).hasSize(2);
    assertThat(buildConfigNames).containsOnly(buildConfigName);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) BuildsFilterParameters(org.jboss.pnc.rest.api.parameters.BuildsFilterParameters) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 15 with BuildClient

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

the class BuildPushTest method shouldPushBuild.

@Test
public void shouldPushBuild() throws ClientException {
    BuildClient client = new BuildClient(RestClientConfiguration.asUser());
    Build build = client.getSpecific(buildId);
    // first push accepted
    BuildPushParameters parameters = BuildPushParameters.builder().reimport(false).tagPrefix("test-tag").build();
    BuildPushResult result = client.push(build.getId(), parameters);
    String buildPushResultId = result.getId();
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(BuildPushStatus.ACCEPTED);
    // second push rejected because already in process
    assertThatThrownBy(() -> client.push(build.getId(), parameters)).hasCauseInstanceOf(ClientErrorException.class);
    // should reject completion with invalid result id
    assertThatThrownBy(() -> client.completePush(buildId, returnSuccessfulResult(buildId, "1111"))).hasCauseInstanceOf(ClientErrorException.class);
    // successful complete of first push
    client.completePush(buildId, returnSuccessfulResult(buildId, buildPushResultId));
    // get result from db
    BuildPushResult successPushResult = client.getPushResult(buildId);
    assertThat(successPushResult.getStatus()).isEqualTo(BuildPushStatus.SUCCESS);
    assertThat(successPushResult.getLogContext()).isEqualTo(buildPushResultId);
    // next push should accept again
    BuildPushResult result2 = client.push(build.getId(), parameters);
    assertThat(result2).isNotNull();
    assertThat(result2.getStatus()).isEqualTo(BuildPushStatus.ACCEPTED);
}
Also used : Build(org.jboss.pnc.dto.Build) BuildClient(org.jboss.pnc.client.BuildClient) BuildPushParameters(org.jboss.pnc.dto.requests.BuildPushParameters) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

BuildClient (org.jboss.pnc.client.BuildClient)37 ContainerTest (org.jboss.pnc.test.category.ContainerTest)33 Test (org.junit.Test)33 Build (org.jboss.pnc.dto.Build)20 BuildsFilterParameters (org.jboss.pnc.rest.api.parameters.BuildsFilterParameters)7 InputStream (java.io.InputStream)5 Artifact (org.jboss.pnc.dto.Artifact)5 InSequence (org.jboss.arquillian.junit.InSequence)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Response (javax.ws.rs.core.Response)3 ArtifactClient (org.jboss.pnc.client.ArtifactClient)3 BuildPushParameters (org.jboss.pnc.dto.requests.BuildPushParameters)3 Field (java.lang.reflect.Field)2 ApacheHttpClient43EngineWithRetry (org.jboss.pnc.client.ApacheHttpClient43EngineWithRetry)2 ClientException (org.jboss.pnc.client.ClientException)2 Configuration (org.jboss.pnc.client.Configuration)2 BuildConfigurationRevision (org.jboss.pnc.dto.BuildConfigurationRevision)2 BuildRef (org.jboss.pnc.dto.BuildRef)2 BeforeClass (org.junit.BeforeClass)2