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);
}
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);
}
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();
}
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);
}
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);
}
Aggregations