Search in sources :

Example 1 with DarCollection

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());
}
Also used : DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) Date(java.util.Date) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 2 with DarCollection

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())));
}
Also used : ElectionStatus(org.broadinstitute.consent.http.enumeration.ElectionStatus) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) DataSet(org.broadinstitute.consent.http.models.DataSet) Date(java.util.Date) Assert.assertNotNull(org.junit.Assert.assertNotNull) Vote(org.broadinstitute.consent.http.models.Vote) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Collectors(java.util.stream.Collectors) Dac(org.broadinstitute.consent.http.models.Dac) DAOTestHelper(org.broadinstitute.consent.http.db.DAOTestHelper) List(java.util.List) VoteType(org.broadinstitute.consent.http.enumeration.VoteType) Election(org.broadinstitute.consent.http.models.Election) Assert.assertFalse(org.junit.Assert.assertFalse) ElectionType(org.broadinstitute.consent.http.enumeration.ElectionType) Assert.assertEquals(org.junit.Assert.assertEquals) Consent(org.broadinstitute.consent.http.models.Consent) Vote(org.broadinstitute.consent.http.models.Vote) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) Election(org.broadinstitute.consent.http.models.Election) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 3 with DarCollection

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());
}
Also used : Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 4 with DarCollection

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());
}
Also used : Response(javax.ws.rs.core.Response) PaginationResponse(org.broadinstitute.consent.http.models.PaginationResponse) BadRequestException(javax.ws.rs.BadRequestException) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Test(org.junit.Test)

Example 5 with DarCollection

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());
}
Also used : DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) 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) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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