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