use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testCloneWorkspaceBadRequest.
@Test(expected = BadRequestException.class)
public void testCloneWorkspaceBadRequest() throws Exception {
Workspace workspace = createDefaultWorkspace();
workspace = workspacesController.createWorkspace(workspace).getBody();
stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
CloneWorkspaceRequest req = new CloneWorkspaceRequest();
Workspace modWorkspace = new Workspace();
modWorkspace.setName("cloned");
modWorkspace.setNamespace("cloned-ns");
req.setWorkspace(modWorkspace);
// Missing research purpose.
workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req);
}
use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testCloneWorkspaceWithCohorts.
@Test
public void testCloneWorkspaceWithCohorts() throws Exception {
CdrVersionContext.setCdrVersion(cdrVersion);
Workspace workspace = createDefaultWorkspace();
workspace = workspacesController.createWorkspace(workspace).getBody();
Cohort c1 = createDefaultCohort("c1");
c1 = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), c1).getBody();
Cohort c2 = createDefaultCohort("c2");
c2 = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), c2).getBody();
stubBigQueryCohortCalls();
CreateReviewRequest reviewReq = new CreateReviewRequest();
reviewReq.setSize(1);
CohortReview cr1 = cohortReviewController.createCohortReview(workspace.getNamespace(), workspace.getId(), c1.getId(), cdrVersion.getCdrVersionId(), reviewReq).getBody();
reviewReq.setSize(2);
CohortReview cr2 = cohortReviewController.createCohortReview(workspace.getNamespace(), workspace.getId(), c2.getId(), cdrVersion.getCdrVersionId(), reviewReq).getBody();
stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
CloneWorkspaceRequest req = new CloneWorkspaceRequest();
Workspace modWorkspace = new Workspace();
modWorkspace.setName("cloned");
modWorkspace.setNamespace("cloned-ns");
ResearchPurpose modPurpose = new ResearchPurpose();
modPurpose.setAncestry(true);
modWorkspace.setResearchPurpose(modPurpose);
req.setWorkspace(modWorkspace);
stubGetWorkspace(modWorkspace.getNamespace(), modWorkspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
Workspace cloned = workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
List<Cohort> cohorts = cohortsController.getCohortsInWorkspace(cloned.getNamespace(), cloned.getId()).getBody().getItems();
Map<String, Cohort> cohortsByName = Maps.uniqueIndex(cohorts, c -> c.getName());
assertThat(cohortsByName.keySet()).containsExactlyElementsIn(ImmutableSet.of("c1", "c2"));
assertThat(cohorts.stream().map(c -> c.getId()).collect(Collectors.toList())).containsNoneOf(c1.getId(), c2.getId());
CohortReview gotCr1 = cohortReviewController.getParticipantCohortStatuses(cloned.getNamespace(), cloned.getId(), cohortsByName.get("c1").getId(), cdrVersion.getCdrVersionId(), new ParticipantCohortStatuses().pageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES)).getBody();
assertThat(gotCr1.getReviewSize()).isEqualTo(cr1.getReviewSize());
assertThat(gotCr1.getParticipantCohortStatuses()).isEqualTo(cr1.getParticipantCohortStatuses());
CohortReview gotCr2 = cohortReviewController.getParticipantCohortStatuses(cloned.getNamespace(), cloned.getId(), cohortsByName.get("c2").getId(), cdrVersion.getCdrVersionId(), new ParticipantCohortStatuses().pageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES)).getBody();
assertThat(gotCr2.getReviewSize()).isEqualTo(cr2.getReviewSize());
assertThat(gotCr2.getParticipantCohortStatuses()).isEqualTo(cr2.getParticipantCohortStatuses());
assertThat(ImmutableSet.of(gotCr1.getCohortReviewId(), gotCr2.getCohortReviewId())).containsNoneOf(cr1.getCohortReviewId(), cr2.getCohortId());
}
use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testUnableToShareWithNonExistentUser.
@Test(expected = BadRequestException.class)
public void testUnableToShareWithNonExistentUser() throws Exception {
Workspace workspace = createDefaultWorkspace();
workspacesController.createWorkspace(workspace);
ShareWorkspaceRequest shareWorkspaceRequest = new ShareWorkspaceRequest();
UserRole creator = new UserRole();
creator.setEmail(LOGGED_IN_USER_EMAIL);
creator.setRole(WorkspaceAccessLevel.OWNER);
shareWorkspaceRequest.addItemsItem(creator);
UserRole writer = new UserRole();
writer.setEmail("writerfriend@gmail.com");
writer.setRole(WorkspaceAccessLevel.WRITER);
shareWorkspaceRequest.addItemsItem(writer);
workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest);
}
use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testUpdateWorkspaceStaleThrows.
@Test(expected = ConflictException.class)
public void testUpdateWorkspaceStaleThrows() throws Exception {
Workspace ws = createDefaultWorkspace();
ws = workspacesController.createWorkspace(ws).getBody();
UpdateWorkspaceRequest request = new UpdateWorkspaceRequest();
request.setWorkspace(new Workspace().name("updated-name").etag(ws.getEtag()));
stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
// Still using the initial now-stale etag; this should throw.
stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
request.setWorkspace(new Workspace().name("updated-name2").etag(ws.getEtag()));
workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
}
use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testUpdateWorkspace.
@Test
public void testUpdateWorkspace() throws Exception {
Workspace ws = createDefaultWorkspace();
ws = workspacesController.createWorkspace(ws).getBody();
ws.setName("updated-name");
stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
UpdateWorkspaceRequest request = new UpdateWorkspaceRequest();
request.setWorkspace(ws);
Workspace updated = workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
ws.setEtag(updated.getEtag());
assertThat(updated).isEqualTo(ws);
ws.setName("updated-name2");
stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
updated = workspacesController.updateWorkspace(ws.getNamespace(), ws.getId(), request).getBody();
ws.setEtag(updated.getEtag());
assertThat(updated).isEqualTo(ws);
stubGetWorkspace(ws.getNamespace(), ws.getId(), ws.getCreator(), WorkspaceAccessLevel.OWNER);
Workspace got = workspacesController.getWorkspace(ws.getNamespace(), ws.getId()).getBody().getWorkspace();
assertThat(got).isEqualTo(ws);
}
Aggregations