Search in sources :

Example 16 with DarCollection

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

the class DarCollectionResourceTest method testGetCollectionByIdMultipleRoles.

@Test
public void testGetCollectionByIdMultipleRoles() {
    UserRole chairRole = new UserRole(UserRoles.CHAIRPERSON.getRoleId(), UserRoles.CHAIRPERSON.getRoleName());
    researcher.addRole(chairRole);
    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(researcher);
    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) DataSet(org.broadinstitute.consent.http.models.DataSet) UserRole(org.broadinstitute.consent.http.models.UserRole) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 17 with DarCollection

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

the class DarCollectionResourceTest method testGetCollectionByIdAdmin.

@Test
public void testGetCollectionByIdAdmin() {
    DarCollection collection = mockDarCollection();
    UserRole adminRole = new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName());
    User admin = new User(1, authUser.getEmail(), "Display Name", new Date(), List.of(adminRole), authUser.getEmail());
    collection.setCreateUser(researcher);
    collection.setCreateUserId(researcher.getDacUserId());
    when(darCollectionService.getByCollectionId(any())).thenReturn(collection);
    when(userService.findUserByEmail(anyString())).thenReturn(admin);
    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) UserRole(org.broadinstitute.consent.http.models.UserRole) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 18 with DarCollection

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

the class DarCollectionResourceTest method testCancelDarCollection_asAdmin.

@Test
public void testCancelDarCollection_asAdmin() {
    List<UserRole> adminRole = List.of(new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName()));
    User admin = new User(1, authUser.getEmail(), "Display Name", new Date(), adminRole, authUser.getEmail());
    DarCollection collection = mockDarCollection();
    collection.setCreateUserId(admin.getDacUserId());
    when(userService.findUserByEmail(anyString())).thenReturn(admin);
    when(darCollectionService.getByCollectionId(anyInt())).thenReturn(collection);
    initResource();
    Response response = resource.cancelDarCollectionByCollectionId(authUser, 1, Resource.ADMIN);
    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 19 with DarCollection

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

the class DarCollectionResourceTest method testCancelDarCollection_OKStatus.

@Test
public void testCancelDarCollection_OKStatus() {
    DarCollection collection = mockDarCollection();
    collection.setCreateUserId(researcher.getDacUserId());
    when(userService.findUserByEmail(anyString())).thenReturn(researcher);
    when(darCollectionService.getByReferenceId(any())).thenReturn(collection);
    initResource();
    Response response = resource.getCollectionByReferenceId(authUser, "1");
    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)

Example 20 with DarCollection

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

the class DarCollectionResourceTest method testGetCollectionsForUserByRoleAdmin.

@Test
public void testGetCollectionsForUserByRoleAdmin() {
    List<DarCollection> mockCollectionsList = List.of(mockDarCollection());
    UserRole adminRole = new UserRole(UserRoles.ADMIN.getRoleId(), UserRoles.ADMIN.getRoleName());
    User admin = new User(1, authUser.getEmail(), "Display Name", new Date(), List.of(adminRole), authUser.getEmail());
    when(userService.findUserByEmail(anyString())).thenReturn(admin);
    when(darCollectionService.getAllCollections()).thenReturn(mockCollectionsList);
    initResource();
    Response response = resource.getCollectionsForUserByRole(authUser, UserRoles.ADMIN.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)

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