use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testCreateWorkspaceAlreadyApproved.
@Test
public void testCreateWorkspaceAlreadyApproved() throws Exception {
Workspace workspace = createDefaultWorkspace();
workspace.getResearchPurpose().setApproved(true);
workspacesController.createWorkspace(workspace);
stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
Workspace workspace2 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getId()).getBody().getWorkspace();
assertThat(workspace2.getResearchPurpose().getApproved()).isNotEqualTo(true);
}
use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testCloneWorkspaceWithNotebooks.
@Test
public void testCloneWorkspaceWithNotebooks() 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);
String f1 = "notebooks/f1.ipynb";
String f2 = "notebooks/f2.ipynb";
String f3 = "notebooks/f3.vcf";
// Note: mockBlob cannot be inlined into thenReturn() due to Mockito nuances.
List<Blob> blobs = ImmutableList.of(mockBlob(BUCKET_NAME, f1), mockBlob(BUCKET_NAME, f2), mockBlob(BUCKET_NAME, f3));
when(cloudStorageService.getBlobList(BUCKET_NAME, "notebooks")).thenReturn(blobs);
workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
verify(cloudStorageService).copyBlob(BlobId.of(BUCKET_NAME, f1), BlobId.of("bucket2", f1));
verify(cloudStorageService).copyBlob(BlobId.of(BUCKET_NAME, f2), BlobId.of("bucket2", f2));
verify(cloudStorageService, never()).copyBlob(BlobId.of(BUCKET_NAME, f3), BlobId.of("bucket2", f3));
}
use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testRejectAfterApproveThrows.
@Test(expected = BadRequestException.class)
public void testRejectAfterApproveThrows() throws Exception {
Workspace ws = createDefaultWorkspace();
ResearchPurpose researchPurpose = ws.getResearchPurpose();
workspacesController.createWorkspace(ws);
ResearchPurposeReviewRequest request = new ResearchPurposeReviewRequest();
request.setApproved(true);
workspacesController.reviewWorkspace(ws.getNamespace(), ws.getName(), request);
request.setApproved(false);
workspacesController.reviewWorkspace(ws.getNamespace(), ws.getName(), request);
}
use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class CohortsControllerTest method setUp.
@Before
public void setUp() throws Exception {
User user = new User();
user.setEmail("bob@gmail.com");
user.setUserId(123L);
user.setDisabled(false);
user.setEmailVerificationStatus(EmailVerificationStatus.SUBSCRIBED);
user = userDao.save(user);
when(userProvider.get()).thenReturn(user);
cdrVersion = new CdrVersion();
cdrVersion.setName(CDR_VERSION_NAME);
cdrVersionDao.save(cdrVersion);
searchRequest = SearchRequests.males();
cohortCriteria = new Gson().toJson(searchRequest);
workspace = new Workspace();
workspace.setName(WORKSPACE_NAME);
workspace.setNamespace(WORKSPACE_NAMESPACE);
workspace.setDataAccessLevel(DataAccessLevel.PROTECTED);
workspace.setResearchPurpose(new ResearchPurpose());
workspace.setCdrVersionId(String.valueOf(cdrVersion.getCdrVersionId()));
CLOCK.setInstant(NOW);
WorkspacesController workspacesController = new WorkspacesController(workspaceService, cdrVersionDao, userDao, userProvider, fireCloudService, cloudStorageService, CLOCK, "https://api.blah.com", userService);
stubGetWorkspace(WORKSPACE_NAMESPACE, WORKSPACE_NAME, "bob@gmail.com", WorkspaceAccessLevel.OWNER);
workspace = workspacesController.createWorkspace(workspace).getBody();
this.cohortsController = new CohortsController(workspaceService, cohortDao, cdrVersionDao, cohortReviewDao, cohortMaterializationService, userProvider, CLOCK);
}
use of org.pmiops.workbench.model.Workspace in project workbench by all-of-us.
the class WorkspacesControllerTest method testShareWorkspace.
@Test
public void testShareWorkspace() throws Exception {
User writerUser = new User();
writerUser.setEmail("writerfriend@gmail.com");
writerUser.setUserId(124L);
writerUser.setFreeTierBillingProjectName("TestBillingProject2");
writerUser.setDisabled(false);
writerUser = userDao.save(writerUser);
User readerUser = new User();
readerUser.setEmail("readerfriend@gmail.com");
readerUser.setUserId(125L);
readerUser.setFreeTierBillingProjectName("TestBillingProject3");
readerUser.setDisabled(false);
readerUser = userDao.save(readerUser);
Workspace workspace = createDefaultWorkspace();
workspace = workspacesController.createWorkspace(workspace).getBody();
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("writerfriend@gmail.com");
writer.setRole(WorkspaceAccessLevel.WRITER);
shareWorkspaceRequest.addItemsItem(writer);
UserRole reader = new UserRole();
reader.setEmail("readerfriend@gmail.com");
reader.setRole(WorkspaceAccessLevel.READER);
shareWorkspaceRequest.addItemsItem(reader);
// Simulate time between API calls to trigger last-modified/@Version changes.
CLOCK.increment(1000);
WorkspaceACLUpdateResponseList responseValue = new WorkspaceACLUpdateResponseList();
when(fireCloudService.updateWorkspaceACL(anyString(), anyString(), anyListOf(WorkspaceACLUpdate.class))).thenReturn(responseValue);
ShareWorkspaceResponse shareResp = workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest).getBody();
stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
Workspace workspace2 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getName()).getBody().getWorkspace();
assertThat(shareResp.getWorkspaceEtag()).isEqualTo(workspace2.getEtag());
assertThat(workspace2.getUserRoles().size()).isEqualTo(3);
int numOwners = 0;
int numWriters = 0;
int numReaders = 0;
for (UserRole userRole : workspace2.getUserRoles()) {
if (userRole.getRole().equals(WorkspaceAccessLevel.OWNER)) {
assertThat(userRole.getEmail()).isEqualTo(LOGGED_IN_USER_EMAIL);
numOwners++;
} else if (userRole.getRole().equals(WorkspaceAccessLevel.WRITER)) {
assertThat(userRole.getEmail()).isEqualTo("writerfriend@gmail.com");
numWriters++;
} else {
assertThat(userRole.getEmail()).isEqualTo("readerfriend@gmail.com");
numReaders++;
}
}
assertThat(numOwners).isEqualTo(1);
assertThat(numWriters).isEqualTo(1);
assertThat(numReaders).isEqualTo(1);
assertThat(workspace.getEtag()).isNotEqualTo(workspace2.getEtag());
}
Aggregations