use of org.pmiops.workbench.model.CloneWorkspaceRequest 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.CloneWorkspaceRequest in project workbench by all-of-us.
the class WorkspacesControllerTest method testCloneWorkspace.
@Test
public void testCloneWorkspace() throws Exception {
Workspace workspace = createDefaultWorkspace();
workspace = workspacesController.createWorkspace(workspace).getBody();
// The original workspace is shared with one other user.
User writerUser = new User();
writerUser.setEmail("writerfriend@gmail.com");
writerUser.setUserId(124L);
writerUser.setFreeTierBillingProjectName("TestBillingProject2");
writerUser.setDisabled(false);
writerUser = userDao.save(writerUser);
ShareWorkspaceRequest shareWorkspaceRequest = new ShareWorkspaceRequest();
shareWorkspaceRequest.setWorkspaceEtag(workspace.getEtag());
UserRole creator = new UserRole();
creator.setEmail(LOGGED_IN_USER_EMAIL);
creator.setRole(WorkspaceAccessLevel.OWNER);
shareWorkspaceRequest.addItemsItem(creator);
UserRole writer = new UserRole();
writer.setEmail(writerUser.getEmail());
writer.setRole(WorkspaceAccessLevel.WRITER);
shareWorkspaceRequest.addItemsItem(writer);
when(fireCloudService.updateWorkspaceACL(anyString(), anyString(), anyListOf(WorkspaceACLUpdate.class))).thenReturn(new WorkspaceACLUpdateResponseList());
workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest);
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 workspace2 = workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
assertWithMessage("get and clone responses are inconsistent").that(workspace2).isEqualTo(workspacesController.getWorkspace(workspace2.getNamespace(), workspace2.getId()).getBody().getWorkspace());
assertThat(workspace2.getName()).isEqualTo(modWorkspace.getName());
assertThat(workspace2.getNamespace()).isEqualTo(modWorkspace.getNamespace());
assertThat(workspace2.getResearchPurpose()).isEqualTo(modPurpose);
// Original description should have been copied.
assertThat(workspace2.getDescription()).isEqualTo(workspace.getDescription());
// User roles should *not* be copied.
assertThat(workspace2.getUserRoles().size()).isEqualTo(1);
assertThat(workspace2.getUserRoles().get(0).getRole()).isEqualTo(WorkspaceAccessLevel.OWNER);
}
use of org.pmiops.workbench.model.CloneWorkspaceRequest in project workbench by all-of-us.
the class WorkspacesControllerTest method testCloneWithMassiveNotebook.
@Test(expected = FailedPreconditionException.class)
public void testCloneWithMassiveNotebook() 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");
ResearchPurpose modPurpose = new ResearchPurpose();
modPurpose.setAncestry(true);
modWorkspace.setResearchPurpose(modPurpose);
req.setWorkspace(modWorkspace);
org.pmiops.workbench.firecloud.model.Workspace fcWorkspace = createFcWorkspace(modWorkspace.getNamespace(), modWorkspace.getName(), LOGGED_IN_USER_EMAIL);
fcWorkspace.setBucketName("bucket2");
stubGetWorkspace(fcWorkspace, WorkspaceAccessLevel.OWNER);
Blob bigNotebook = mockBlob(BUCKET_NAME, "notebooks/nb.ipynb");
// 5 GB.
when(bigNotebook.getSize()).thenReturn(5_000_000_000L);
when(cloudStorageService.getBlobList(BUCKET_NAME, "notebooks")).thenReturn(ImmutableList.of(bigNotebook));
workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
}
Aggregations