use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.
the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollectionAfterCancelingEarlierElections.
@Test
public void testCreateElectionsForDarCollectionAfterCancelingEarlierElections() throws Exception {
initService();
DarCollection collection = setUpDarCollectionWithDacDataset();
DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
assertNotNull(dar);
// create elections & votes:
serviceDAO.createElectionsForDarCollection(collection);
// cancel those elections:
electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId())).forEach(e -> electionDAO.updateElectionById(e.getElectionId(), ElectionStatus.CANCELED.getValue(), new Date()));
// re-create elections & new votes:
serviceDAO.createElectionsForDarCollection(collection);
List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId()));
// Ensure that we have the right number of access and rp elections, i.e. 1 each
assertFalse(createdElections.isEmpty());
assertEquals(2, createdElections.size());
assertEquals(1, createdElections.stream().filter(e -> e.getElectionType().equals(ElectionType.DATA_ACCESS.getValue())).count());
assertEquals(1, createdElections.stream().filter(e -> e.getElectionType().equals(ElectionType.RP.getValue())).count());
}
use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.
the class DarCollectionServiceDAOTest method testCreateElectionsForDarCollection.
@Test
public void testCreateElectionsForDarCollection() throws Exception {
initService();
DarCollection collection = setUpDarCollectionWithDacDataset();
DataAccessRequest dar = collection.getDars().values().stream().findFirst().orElse(null);
assertNotNull(dar);
serviceDAO.createElectionsForDarCollection(collection);
List<Election> createdElections = electionDAO.findLastElectionsByReferenceIds(List.of(dar.getReferenceId()));
List<Vote> createdVotes = voteDAO.findVotesByElectionIds(createdElections.stream().map(Election::getElectionId).collect(Collectors.toList()));
// Ensure that we have an access and rp election
assertFalse(createdElections.isEmpty());
assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.DATA_ACCESS.getValue())));
assertTrue(createdElections.stream().anyMatch(e -> e.getElectionType().equals(ElectionType.RP.getValue())));
// Ensure that we have primary vote types
assertFalse(createdVotes.isEmpty());
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.CHAIRPERSON.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.FINAL.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.DAC.getValue())));
assertTrue(createdVotes.stream().anyMatch(v -> v.getType().equals(VoteType.AGREEMENT.getValue())));
}
use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.
the class DarCollectionResourceTest method testCancelDarCollection_InternalErrorStatus.
@Test
public void testCancelDarCollection_InternalErrorStatus() {
DarCollection collection = mockDarCollection();
collection.setCreateUserId(researcher.getDacUserId());
when(userService.findUserByEmail(anyString())).thenReturn(researcher);
when(darCollectionService.getByCollectionId(anyInt())).thenReturn(collection);
when(darCollectionService.cancelDarCollectionAsResearcher(any(DarCollection.class))).thenThrow(new InternalServerErrorException());
initResource();
Response response = resource.cancelDarCollectionByCollectionId(authUser, 1, null);
assertEquals(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, response.getStatus());
}
use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.
the class DarCollectionResourceTest method testCancelDarCollection_BadRequestStatus.
@Test
public void testCancelDarCollection_BadRequestStatus() {
DarCollection collection = mockDarCollection();
collection.setCreateUserId(researcher.getDacUserId());
when(userService.findUserByEmail(anyString())).thenReturn(researcher);
when(darCollectionService.getByCollectionId(anyInt())).thenReturn(collection);
when(darCollectionService.cancelDarCollectionAsResearcher(any(DarCollection.class))).thenThrow(new BadRequestException());
initResource();
Response response = resource.cancelDarCollectionByCollectionId(authUser, 1, null);
assertEquals(HttpStatusCodes.STATUS_CODE_BAD_REQUEST, response.getStatus());
}
use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.
the class DarCollectionResourceTest method testResubmitDarCollection_CollectionNotCanceled.
@Test
public void testResubmitDarCollection_CollectionNotCanceled() {
int userId = 1;
User user = mock(User.class);
when(userService.findUserByEmail(anyString())).thenReturn(user);
when(user.getDacUserId()).thenReturn(userId);
DarCollection collection = mock(DarCollection.class);
when(collection.getCreateUserId()).thenReturn(userId);
DataAccessRequest dar = mock(DataAccessRequest.class);
DataAccessRequestData data = mock(DataAccessRequestData.class);
String referenceId = UUID.randomUUID().toString();
when(data.getStatus()).thenReturn("Not Canceled");
when(dar.getData()).thenReturn(data);
when(dar.getReferenceId()).thenReturn(referenceId);
Map<String, DataAccessRequest> darMap = Map.of(dar.getReferenceId(), dar);
when(collection.getDars()).thenReturn(darMap);
when(darCollectionService.getByCollectionId(any())).thenReturn(collection);
initResource();
Response response = resource.resubmitDarCollection(authUser, 1);
assertEquals(HttpStatusCodes.STATUS_CODE_BAD_REQUEST, response.getStatus());
}
Aggregations