use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.
the class BuildEndpointTest method shouldSortResults.
@Test
public void shouldSortResults() throws Exception {
BuildClient bc = new BuildClient(RestClientConfiguration.asAnonymous());
String sort = "=asc=submitTime";
List<Long> notSorted = bc.getAll(null, null).getAll().stream().map(BuildRef::getSubmitTime).map(Instant::getEpochSecond).collect(Collectors.toList());
List<Long> sorted = bc.getAll(null, null, Optional.of(sort), Optional.empty()).getAll().stream().map(BuildRef::getSubmitTime).map(Instant::getEpochSecond).collect(Collectors.toList());
assertThat(notSorted).isNotEqualTo(sorted);
assertThat(sorted).isSorted();
}
use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.
the class BuildEndpointTest method shouldFailAsRegularUser.
@Test
public void shouldFailAsRegularUser() {
BuildClient client = new BuildClient(RestClientConfiguration.asUser());
String buildRecordId = buildId;
assertThatThrownBy(() -> client.setBuiltArtifacts(buildRecordId, Collections.emptyList())).hasCauseInstanceOf(ForbiddenException.class);
assertThatThrownBy(() -> client.setDependentArtifacts(buildRecordId, Collections.emptyList())).hasCauseInstanceOf(ForbiddenException.class);
assertThatThrownBy(() -> client.update(buildRecordId, Build.builder().build())).hasCauseInstanceOf(ForbiddenException.class);
}
use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.
the class BuildEndpointTest method shouldBeAbleToReachAllBuildsWhenPaging.
@Test
public void shouldBeAbleToReachAllBuildsWhenPaging() throws Exception {
BuildClient bc = new BuildClient(RestClientConfiguration.asAnonymous());
List<String> buildIds = bc.getAll(null, null).getAll().stream().map(Build::getId).collect(Collectors.toList());
List<String> pagedBuildIds = new ArrayList<>();
int pageSize = 1;
for (int pageIndex = 0; pageIndex < buildIds.size(); pageIndex++) {
final io.restassured.response.Response response = given().redirects().follow(false).port(8080).when().get(String.format(BASE_REST_PATH + "/builds/?pageIndex=%d&pageSize=%d", pageIndex, pageSize));
List<Build> builds = response.getBody().jsonPath().getList("content", Build.class);
pagedBuildIds.add(builds.get(0).getId());
}
assertThat(pagedBuildIds).containsExactlyInAnyOrderElementsOf(buildIds);
}
use of org.jboss.pnc.client.BuildClient in project pnc by project-ncl.
the class BuildEndpointTest method shouldFilterByBuildConfigurationName.
@Test
public void shouldFilterByBuildConfigurationName() throws Exception {
BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
String buildConfigName = DatabaseDataInitializer.PNC_PROJECT_BUILD_CFG_ID;
BuildsFilterParameters filter = new BuildsFilterParameters();
filter.setBuildConfigName(buildConfigName);
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 BuildEndpointTest method shouldFilterByBuildConfigurationNameAndUserId.
@Test
public void shouldFilterByBuildConfigurationNameAndUserId() throws Exception {
BuildClient client = new BuildClient(RestClientConfiguration.asAnonymous());
String buildConfigName = DatabaseDataInitializer.PNC_PROJECT_BUILD_CFG_ID;
String username = "pnc-admin";
String rsql = "user.username==" + username;
BuildsFilterParameters filter = new BuildsFilterParameters();
filter.setBuildConfigName(buildConfigName);
List<Build> builds = new ArrayList<>(client.getAll(filter, null, Optional.empty(), Optional.of(rsql)).getAll());
assertThat(builds).hasSize(2);
assertThat(builds.stream().map(Build::getBuildConfigRevision).map(BuildConfigurationRevisionRef::getName).allMatch(name -> name.equals(buildConfigName)));
assertThat(builds.stream().map(Build::getUser).map(User::getUsername).allMatch(name -> name.equals(username)));
}
Aggregations