Search in sources :

Example 11 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.

the class DarCollectionResourceTest method testGetCollectionByReferenceIdNotFound.

@Test
public void testGetCollectionByReferenceIdNotFound() {
    DarCollection collection = mockDarCollection();
    collection.setCreateUserId(researcher.getDacUserId() + 1);
    when(userService.findUserByEmail(anyString())).thenReturn(researcher);
    when(darCollectionService.getByReferenceId(any())).thenReturn(collection);
    initResource();
    Response response = resource.getCollectionByReferenceId(authUser, "1");
    assertEquals(HttpStatusCodes.STATUS_CODE_NOT_FOUND, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 12 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection 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 13 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection 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)

Example 14 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.

the class DarCollectionResourceTest method testQueryCollectionsByFiltersAndUserRoles.

@Test
public void testQueryCollectionsByFiltersAndUserRoles() {
    PaginationResponse<DarCollection> paginationResponse = new PaginationResponse<>();
    when(userService.findUserByEmail(anyString())).thenReturn(researcher);
    when(darCollectionService.queryCollectionsByFiltersAndUserRoles(any(User.class), any(PaginationToken.class), anyString())).thenReturn(paginationResponse);
    initResource();
    Response response = resource.queryCollectionsByFiltersAndUserRoles(authUser, "researcher", "DESC", "filterTerm", "projectTitle", 10);
    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) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) PaginationToken(org.broadinstitute.consent.http.models.PaginationToken) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 15 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.

the class DarCollectionResourceTest method testGetCollectionByIdSO.

@Test
public void testGetCollectionByIdSO() {
    DarCollection collection = mockDarCollection();
    signingOfficial.setInstitutionId(1);
    researcher.setInstitutionId(1);
    collection.setCreateUser(researcher);
    collection.setCreateUserId(researcher.getDacUserId());
    when(darCollectionService.getByCollectionId(any())).thenReturn(collection);
    when(userService.findUserByEmail(anyString())).thenReturn(signingOfficial);
    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) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Aggregations

DarCollection (org.broadinstitute.consent.http.models.DarCollection)127 Test (org.junit.Test)110 User (org.broadinstitute.consent.http.models.User)71 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)43 AuthUser (org.broadinstitute.consent.http.models.AuthUser)33 PaginationResponse (org.broadinstitute.consent.http.models.PaginationResponse)33 Response (javax.ws.rs.core.Response)32 UserRole (org.broadinstitute.consent.http.models.UserRole)21 Date (java.util.Date)20 DataAccessRequestData (org.broadinstitute.consent.http.models.DataAccessRequestData)18 DataSet (org.broadinstitute.consent.http.models.DataSet)18 Election (org.broadinstitute.consent.http.models.Election)16 PaginationToken (org.broadinstitute.consent.http.models.PaginationToken)14 NotFoundException (javax.ws.rs.NotFoundException)13 BadRequestException (javax.ws.rs.BadRequestException)11 ForbiddenException (javax.ws.rs.ForbiddenException)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 Dac (org.broadinstitute.consent.http.models.Dac)8