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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations