use of org.pmiops.workbench.model.UserRole in project workbench by all-of-us.
the class WorkspacesControllerTest method createDefaultWorkspace.
public Workspace createDefaultWorkspace() throws Exception {
ResearchPurpose researchPurpose = new ResearchPurpose();
researchPurpose.setDiseaseFocusedResearch(true);
researchPurpose.setDiseaseOfFocus("cancer");
researchPurpose.setMethodsDevelopment(true);
researchPurpose.setControlSet(true);
researchPurpose.setAggregateAnalysis(true);
researchPurpose.setAncestry(true);
researchPurpose.setCommercialPurpose(true);
researchPurpose.setPopulation(true);
researchPurpose.setPopulationOfFocus("population");
researchPurpose.setAdditionalNotes("additional notes");
researchPurpose.setTimeRequested(new Long(1000));
researchPurpose.setTimeReviewed(new Long(1500));
researchPurpose.setReviewRequested(true);
researchPurpose.setApproved(false);
Workspace workspace = new Workspace();
workspace.setId("name");
workspace.setName("name");
workspace.setNamespace("namespace");
workspace.setDescription("description");
workspace.setDataAccessLevel(DataAccessLevel.PROTECTED);
workspace.setResearchPurpose(researchPurpose);
workspace.setUserRoles(new ArrayList<UserRole>());
workspace.setCdrVersionId(cdrVersionId);
stubGetWorkspace("namespace", "name", LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
return workspace;
}
use of org.pmiops.workbench.model.UserRole 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());
}
use of org.pmiops.workbench.model.UserRole 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.UserRole in project workbench by all-of-us.
the class WorkspacesControllerTest method testUnshareWorkspace.
@Test
public void testUnshareWorkspace() 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);
WorkspaceACLUpdateResponseList responseValue = new WorkspaceACLUpdateResponseList();
responseValue.setUsersNotFound(new ArrayList<WorkspaceACLUpdate>());
// Simulate time between API calls to trigger last-modified/@Version changes.
CLOCK.increment(1000);
when(fireCloudService.updateWorkspaceACL(anyString(), anyString(), anyListOf(WorkspaceACLUpdate.class))).thenReturn(responseValue);
ShareWorkspaceResponse shareResp = workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest).getBody();
stubGetWorkspace(workspace.getNamespace(), workspace.getId(), workspace.getCreator(), WorkspaceAccessLevel.OWNER);
Workspace workspace2 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getId()).getBody().getWorkspace();
assertThat(shareResp.getWorkspaceEtag()).isEqualTo(workspace2.getEtag());
CLOCK.increment(1000);
shareWorkspaceRequest = new ShareWorkspaceRequest();
shareWorkspaceRequest.setWorkspaceEtag(workspace2.getEtag());
shareWorkspaceRequest.addItemsItem(creator);
shareWorkspaceRequest.addItemsItem(writer);
shareResp = workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest).getBody();
Workspace workspace3 = workspacesController.getWorkspace(workspace.getNamespace(), workspace.getId()).getBody().getWorkspace();
assertThat(shareResp.getWorkspaceEtag()).isEqualTo(workspace3.getEtag());
assertThat(workspace3.getUserRoles().size()).isEqualTo(2);
int numOwners = 0;
int numWriters = 0;
int numReaders = 0;
for (UserRole userRole : workspace3.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(0);
assertThat(workspace.getEtag()).isNotEqualTo(workspace2.getEtag());
assertThat(workspace2.getEtag()).isNotEqualTo(workspace3.getEtag());
}
use of org.pmiops.workbench.model.UserRole in project workbench by all-of-us.
the class WorkspacesControllerTest method testStaleShareWorkspace.
@Test
public void testStaleShareWorkspace() throws Exception {
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);
// 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);
workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest);
// Simulate time between API calls to trigger last-modified/@Version changes.
CLOCK.increment(1000);
shareWorkspaceRequest = new ShareWorkspaceRequest();
// Use the initial etag, not the updated value from shareWorkspace.
shareWorkspaceRequest.setWorkspaceEtag(workspace.getEtag());
try {
workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest);
fail("expected conflict exception when sharing with stale etag");
} catch (ConflictException e) {
// Expected
}
}
Aggregations