Search in sources :

Example 6 with UserRole

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());
    }
}
Also used : AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) SimplifiedUser(org.broadinstitute.consent.http.service.UserService.SimplifiedUser) UserRole(org.broadinstitute.consent.http.models.UserRole) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.Test)

Example 7 with UserRole

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());
}
Also used : Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) UserRole(org.broadinstitute.consent.http.models.UserRole) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 8 with UserRole

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());
}
Also used : Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) UserRole(org.broadinstitute.consent.http.models.UserRole) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 9 with UserRole

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());
}
Also used : Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) UserRole(org.broadinstitute.consent.http.models.UserRole) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 10 with UserRole

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());
}
Also used : Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataSet(org.broadinstitute.consent.http.models.DataSet) UserRole(org.broadinstitute.consent.http.models.UserRole) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Aggregations

UserRole (org.broadinstitute.consent.http.models.UserRole)88 User (org.broadinstitute.consent.http.models.User)78 Test (org.junit.Test)71 AuthUser (org.broadinstitute.consent.http.models.AuthUser)54 Response (javax.ws.rs.core.Response)40 DarCollection (org.broadinstitute.consent.http.models.DarCollection)20 Vote (org.broadinstitute.consent.http.models.Vote)18 DataSet (org.broadinstitute.consent.http.models.DataSet)13 Date (java.util.Date)12 PaginationResponse (org.broadinstitute.consent.http.models.PaginationResponse)11 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)10 SimplifiedUser (org.broadinstitute.consent.http.service.UserService.SimplifiedUser)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 GoogleUser (org.broadinstitute.consent.http.authentication.GoogleUser)8 Consent (org.broadinstitute.consent.http.models.Consent)7 Dac (org.broadinstitute.consent.http.models.Dac)7 NotFoundException (javax.ws.rs.NotFoundException)6 BadRequestException (javax.ws.rs.BadRequestException)5 DataAccessRequestManage (org.broadinstitute.consent.http.models.DataAccessRequestManage)4 Election (org.broadinstitute.consent.http.models.Election)4