Search in sources :

Example 1 with ModifyParticipantCohortAnnotationRequest

use of org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest in project workbench by all-of-us.

the class CohortReviewServiceImplTest method updateParticipantCohortAnnotationModifyNotFoundCohortAnnotationDefinition.

@Test
public void updateParticipantCohortAnnotationModifyNotFoundCohortAnnotationDefinition() throws Exception {
    long annotationId = 1;
    long cohortAnnotationDefinitionId = 1;
    long cohortReviewId = 1;
    long participantId = 1;
    ParticipantCohortAnnotation participantCohortAnnotation = new ParticipantCohortAnnotation().annotationValueBoolean(Boolean.TRUE).cohortAnnotationDefinitionId(cohortAnnotationDefinitionId).cohortReviewId(cohortReviewId).participantId(participantId);
    ModifyParticipantCohortAnnotationRequest modifyRequest = new ModifyParticipantCohortAnnotationRequest().annotationValueBoolean(Boolean.FALSE);
    when(participantCohortAnnotationDao.findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId)).thenReturn(participantCohortAnnotation);
    when(cohortAnnotationDefinitionDao.findOne(cohortAnnotationDefinitionId)).thenReturn(null);
    try {
        cohortReviewService.updateParticipantCohortAnnotation(annotationId, cohortReviewId, participantId, modifyRequest);
        fail("Should have thrown NotFoundException!");
    } catch (NotFoundException e) {
        assertEquals("Not Found: No cohort annotation definition found for id: " + cohortAnnotationDefinitionId, e.getMessage());
    }
    verify(participantCohortAnnotationDao).findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId);
    verify(cohortAnnotationDefinitionDao).findOne(cohortAnnotationDefinitionId);
    verifyNoMoreMockInteractions();
}
Also used : NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) ModifyParticipantCohortAnnotationRequest(org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest) Test(org.junit.Test)

Example 2 with ModifyParticipantCohortAnnotationRequest

use of org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest in project workbench by all-of-us.

the class CohortReviewServiceImplTest method assertParticipantCohortAnnotationModifyBadRequest.

private void assertParticipantCohortAnnotationModifyBadRequest(Long annotationId, ParticipantCohortAnnotation participantCohortAnnotation, AnnotationType annotationType) {
    Long cohortAnnotationDefinitionId = participantCohortAnnotation.getCohortAnnotationDefinitionId();
    Long cohortReviewId = participantCohortAnnotation.getCohortReviewId();
    Long participantId = participantCohortAnnotation.getParticipantId();
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition(cohortAnnotationDefinitionId, annotationType);
    when(participantCohortAnnotationDao.findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId)).thenReturn(participantCohortAnnotation);
    when(cohortAnnotationDefinitionDao.findOne(cohortAnnotationDefinitionId)).thenReturn(cohortAnnotationDefinition);
    try {
        cohortReviewService.updateParticipantCohortAnnotation(annotationId, cohortReviewId, participantId, new ModifyParticipantCohortAnnotationRequest());
        fail("Should have thrown BadRequestExcpetion!");
    } catch (BadRequestException e) {
        assertEquals("Invalid Request: Please provide a valid " + cohortAnnotationDefinition.getAnnotationType().name() + " value for annotation defintion id: " + cohortAnnotationDefinition.getCohortAnnotationDefinitionId(), e.getMessage());
    }
    verify(participantCohortAnnotationDao, atLeastOnce()).findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId);
    verify(cohortAnnotationDefinitionDao, atLeastOnce()).findOne(cohortAnnotationDefinitionId);
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) ModifyParticipantCohortAnnotationRequest(org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest)

Example 3 with ModifyParticipantCohortAnnotationRequest

use of org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest in project workbench by all-of-us.

the class CohortReviewServiceImplTest method updateParticipantCohortAnnotationModifyNotFoundParticipantCohortAnnotation.

@Test
public void updateParticipantCohortAnnotationModifyNotFoundParticipantCohortAnnotation() throws Exception {
    long annotationId = 1;
    long cohortAnnotationDefinitionId = 1;
    long cohortReviewId = 1;
    long participantId = 1;
    ModifyParticipantCohortAnnotationRequest modifyRequest = new ModifyParticipantCohortAnnotationRequest().annotationValueBoolean(Boolean.FALSE);
    when(participantCohortAnnotationDao.findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId)).thenReturn(null);
    try {
        cohortReviewService.updateParticipantCohortAnnotation(annotationId, cohortReviewId, participantId, modifyRequest);
        fail("Should have thrown NotFoundException!");
    } catch (NotFoundException e) {
        assertEquals("Not Found: Participant Cohort Annotation does not exist for annotationId: " + annotationId + ", cohortReviewId: " + cohortReviewId + ", participantId: " + cohortAnnotationDefinitionId, e.getMessage());
    }
    verify(participantCohortAnnotationDao).findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId);
    verifyNoMoreMockInteractions();
}
Also used : NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) ModifyParticipantCohortAnnotationRequest(org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest) Test(org.junit.Test)

Example 4 with ModifyParticipantCohortAnnotationRequest

use of org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest in project workbench by all-of-us.

the class CohortReviewServiceImplTest method updateParticipantCohortAnnotationModify.

@Test
public void updateParticipantCohortAnnotationModify() throws Exception {
    long annotationId = 1;
    long cohortAnnotationDefinitionId = 1;
    long cohortReviewId = 1;
    long participantId = 1;
    ParticipantCohortAnnotation participantCohortAnnotation = new ParticipantCohortAnnotation().annotationValueBoolean(Boolean.TRUE).cohortAnnotationDefinitionId(cohortAnnotationDefinitionId).cohortReviewId(cohortReviewId).participantId(participantId);
    ModifyParticipantCohortAnnotationRequest modifyRequest = new ModifyParticipantCohortAnnotationRequest().annotationValueBoolean(Boolean.FALSE);
    CohortAnnotationDefinition cohortAnnotationDefinition = createCohortAnnotationDefinition(cohortAnnotationDefinitionId, AnnotationType.BOOLEAN);
    when(participantCohortAnnotationDao.findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId)).thenReturn(participantCohortAnnotation);
    when(cohortAnnotationDefinitionDao.findOne(cohortAnnotationDefinitionId)).thenReturn(cohortAnnotationDefinition);
    cohortReviewService.updateParticipantCohortAnnotation(annotationId, cohortReviewId, participantId, modifyRequest);
    verify(participantCohortAnnotationDao).findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId);
    verify(cohortAnnotationDefinitionDao).findOne(cohortAnnotationDefinitionId);
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) ParticipantCohortAnnotation(org.pmiops.workbench.db.model.ParticipantCohortAnnotation) ModifyParticipantCohortAnnotationRequest(org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest) Test(org.junit.Test)

Aggregations

ModifyParticipantCohortAnnotationRequest (org.pmiops.workbench.model.ModifyParticipantCohortAnnotationRequest)4 Test (org.junit.Test)3 CohortAnnotationDefinition (org.pmiops.workbench.db.model.CohortAnnotationDefinition)2 ParticipantCohortAnnotation (org.pmiops.workbench.db.model.ParticipantCohortAnnotation)2 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)1