use of bio.terra.workspace.model.EnumeratedJob in project terra-workspace-manager by DataBiosphere.
the class EnumerateJobs method doUserJourney.
@Override
public void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
// Case 1: fetch all
EnumerateJobsResult fetchall = alpha1Api.enumerateJobs(getWorkspaceId(), null, null, null, null, null, null);
logResult("fetchall", fetchall);
// TODO: [PF-1281] we need another type of filtering to be able to do better validation of the
// result return.
// Case 2: fetch by pages
String pageToken = null;
for (int pageCount = 1; true; pageCount++) {
EnumerateJobsResult page = alpha1Api.enumerateJobs(getWorkspaceId(), PAGE_SIZE, pageToken, null, null, null, null);
logResult("page " + pageCount, page);
assertThat("Not more than page size items returned", page.getResults().size(), lessThanOrEqualTo(PAGE_SIZE));
pageToken = page.getPageToken();
if (page.getResults().size() == 0) {
break;
}
}
// Case 4: filter by resource type
EnumerateJobsResult buckets = alpha1Api.enumerateJobs(getWorkspaceId(), /*limit=*/
null, /*pageToken=*/
null, ResourceType.GCS_BUCKET, /*stewardship=*/
null, /*name=*/
null, /*jobState=*/
null);
logResult("buckets", buckets);
for (EnumeratedJob job : buckets.getResults()) {
assertThat("Job is a bucket", job.getResourceType(), equalTo(ResourceType.GCS_BUCKET));
assertNotNull(job.getResource().getGcpGcsBucket(), "Bucket resource present");
assertThat("Resource is a bucket", job.getResource().getGcpGcsBucket().getMetadata().getResourceType(), equalTo(ResourceType.GCS_BUCKET));
}
// Case 5: filter by stewardship type
EnumerateJobsResult controlled = alpha1Api.enumerateJobs(getWorkspaceId(), null, null, null, StewardshipType.CONTROLLED, null, null);
logResult("controlled", controlled);
for (EnumeratedJob job : controlled.getResults()) {
ResourceMetadata metadata = getResourceMetadata(job);
assertNotNull(metadata, "Resource has metadata");
assertThat("Resource is controlled", metadata.getStewardshipType(), equalTo(StewardshipType.CONTROLLED));
}
// Case 6: filter by resource and stewardship
EnumerateJobsResult controlledBuckets = alpha1Api.enumerateJobs(getWorkspaceId(), null, null, ResourceType.GCS_BUCKET, StewardshipType.CONTROLLED, null, null);
logResult("controlledBuckets", controlledBuckets);
for (EnumeratedJob job : controlledBuckets.getResults()) {
ResourceMetadata metadata = getResourceMetadata(job);
assertNotNull(metadata, "Resource has metadata");
assertThat("Resource is controlled", metadata.getStewardshipType(), equalTo(StewardshipType.CONTROLLED));
assertThat("Resource is a bucket", metadata.getResourceType(), equalTo(ResourceType.GCS_BUCKET));
}
// Case 7: validate error on invalid pagination params
ApiException invalidPaginationException = assertThrows(ApiException.class, () -> alpha1Api.enumerateJobs(getWorkspaceId(), -5, null, null, null, null, null));
assertThat(invalidPaginationException.getMessage(), containsString("Invalid pagination"));
invalidPaginationException = assertThrows(ApiException.class, () -> alpha1Api.enumerateJobs(getWorkspaceId(), 22, "junktoken", null, null, null, null));
assertThat(invalidPaginationException.getMessage(), containsString("Invalid page token"));
}
Aggregations