use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class UserServiceTest method createUserTest.
@Test
public void createUserTest() {
User u = generateUser();
List<UserRole> roles = List.of(generateRole(UserRoles.RESEARCHER.getRoleId()));
u.setRoles(roles);
when(userDAO.findUserById(any())).thenReturn(u);
when(roleDAO.findRolesByUserId(any())).thenReturn(roles);
when(libraryCardDAO.findAllLibraryCardsByUserEmail(any())).thenReturn(Collections.emptyList());
initService();
try {
service.createUser(u);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class DarCollectionResourceTest method testGetCollectionByIdDacMemberNoDatasetIdMatch.
@Test
public void testGetCollectionByIdDacMemberNoDatasetIdMatch() {
List<UserRole> chairRole = List.of(new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName()));
User chair = new User(3, authUser.getEmail(), "Display Name", new Date(), chairRole, authUser.getEmail());
DarCollection collection = mockDarCollection();
collection.setCreateUser(researcher);
collection.setCreateUserId(researcher.getDacUserId());
DataSet dataSet = new DataSet();
dataSet.setDataSetId(3);
collection.addDataset(dataSet);
when(darCollectionService.getByCollectionId(any())).thenReturn(collection);
when(userService.findUserByEmail(anyString())).thenReturn(chair);
when(darCollectionService.findDatasetIdsByUser(any())).thenReturn(Arrays.asList(1, 2));
initResource();
Response response = resource.getCollectionById(authUser, collection.getDarCollectionId());
assertEquals(HttpStatusCodes.STATUS_CODE_NOT_FOUND, response.getStatus());
}
use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class DarCollectionResourceTest method testGetCollectionByIdChair.
@Test
public void testGetCollectionByIdChair() {
List<UserRole> chairRole = List.of(new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName()));
User chair = new User(3, authUser.getEmail(), "Display Name", new Date(), chairRole, authUser.getEmail());
DarCollection collection = mockDarCollection();
collection.setCreateUser(researcher);
collection.setCreateUserId(researcher.getDacUserId());
DataSet dataSet = new DataSet();
dataSet.setDataSetId(2);
collection.addDataset(dataSet);
when(darCollectionService.getByCollectionId(any())).thenReturn(collection);
when(userService.findUserByEmail(anyString())).thenReturn(chair);
when(darCollectionService.findDatasetIdsByUser(any())).thenReturn(Arrays.asList(1, 2));
initResource();
Response response = resource.getCollectionById(authUser, collection.getDarCollectionId());
assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
}
use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class DarCollectionResourceTest method testGetCollectionsForUserByRoleAdminWithSORole.
@Test
public void testGetCollectionsForUserByRoleAdminWithSORole() {
// Test that a user who has access can access as a different role they have.
List<DarCollection> mockCollectionsList = List.of(mockDarCollection());
UserRole adminRole = new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName());
UserRole soRole = new UserRole(UserRoles.SIGNINGOFFICIAL.getRoleId(), UserRoles.SIGNINGOFFICIAL.getRoleName());
User admin = new User(1, authUser.getEmail(), "Display Name", new Date(), List.of(adminRole, soRole), authUser.getEmail());
when(userService.findUserByEmail(anyString())).thenReturn(admin);
when(darCollectionService.getAllCollections()).thenReturn(mockCollectionsList);
initResource();
Response response = resource.getCollectionsForUserByRole(authUser, UserRoles.SIGNINGOFFICIAL.getRoleName());
assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
}
use of org.broadinstitute.consent.http.models.UserRole in project consent by DataBiosphere.
the class DarCollectionResourceTest method testGetCollectionByIdDacMember.
@Test
public void testGetCollectionByIdDacMember() {
List<UserRole> chairRole = List.of(new UserRole(UserRoles.MEMBER.getRoleId(), UserRoles.MEMBER.getRoleName()));
User chair = new User(3, authUser.getEmail(), "Display Name", new Date(), chairRole, authUser.getEmail());
DarCollection collection = mockDarCollection();
collection.setCreateUser(researcher);
collection.setCreateUserId(researcher.getDacUserId());
DataSet dataSet = new DataSet();
dataSet.setDataSetId(2);
collection.addDataset(dataSet);
when(darCollectionService.getByCollectionId(any())).thenReturn(collection);
when(userService.findUserByEmail(anyString())).thenReturn(chair);
when(darCollectionService.findDatasetIdsByUser(any())).thenReturn(Arrays.asList(1, 2));
initResource();
Response response = resource.getCollectionById(authUser, collection.getDarCollectionId());
assertEquals(HttpStatusCodes.STATUS_CODE_OK, response.getStatus());
}
Aggregations