use of org.pmiops.workbench.exceptions.NotFoundException 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();
}
use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method updateCohortAnnotationDefinition_BadWorkspace.
@Test
public void updateCohortAnnotationDefinition_BadWorkspace() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long annotationDefinitionId = 1;
long workspaceId = 1;
long badWorkspaceId = 0;
Cohort cohort = createCohort(workspaceId);
Workspace workspace = createWorkspace(namespace, name, badWorkspaceId);
ModifyCohortAnnotationDefinitionRequest request = new ModifyCohortAnnotationDefinitionRequest();
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER)).thenReturn(owner);
when(cohortDao.findOne(cohortId)).thenReturn(cohort);
when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
try {
cohortAnnotationDefinitionController.updateCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId, request);
fail("Should have thrown a NotFoundException!");
} catch (NotFoundException e) {
assertEquals("Not Found: No workspace matching workspaceNamespace: " + namespace + ", workspaceId: " + name, e.getMessage());
}
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService, times(1)).getRequired(namespace, name);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method deleteCohortAnnotationDefinition_BadAnnotationDefinitionId.
@Test
public void deleteCohortAnnotationDefinition_BadAnnotationDefinitionId() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long workspaceId = 1;
long annotationDefinitionId = 1;
Cohort cohort = createCohort(workspaceId);
Workspace workspace = createWorkspace(namespace, name, workspaceId);
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER)).thenReturn(owner);
when(cohortDao.findOne(cohortId)).thenReturn(cohort);
when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
when(cohortAnnotationDefinitionDao.findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId)).thenReturn(null);
try {
cohortAnnotationDefinitionController.deleteCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId);
fail("Should have thrown a NotFoundException!");
} catch (NotFoundException e) {
assertEquals("Not Found: No Cohort Annotation Definition exists for annotationDefinitionId: " + annotationDefinitionId, e.getMessage());
}
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService, times(1)).getRequired(namespace, name);
verify(cohortAnnotationDefinitionDao, times(1)).findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method createCohortAnnotationDefinition_BadCohortId.
@Test
public void createCohortAnnotationDefinition_BadCohortId() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER)).thenReturn(owner);
when(cohortDao.findOne(cohortId)).thenReturn(null);
try {
cohortAnnotationDefinitionController.createCohortAnnotationDefinition(namespace, name, cohortId, new CohortAnnotationDefinition());
fail("Should have thrown a NotFoundException!");
} catch (NotFoundException e) {
assertEquals("Not Found: No Cohort exists for cohortId: " + cohortId, e.getMessage());
}
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinitions_NotFoundWorkspace.
@Test
public void getCohortAnnotationDefinitions_NotFoundWorkspace() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long workspaceId = 1;
long badWorkspaceId = 0;
Cohort cohort = createCohort(workspaceId);
Workspace workspace = createWorkspace(namespace, name, badWorkspaceId);
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(cohortDao.findOne(cohortId)).thenReturn(cohort);
when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER)).thenReturn(owner);
try {
cohortAnnotationDefinitionController.getCohortAnnotationDefinitions(namespace, name, cohortId);
fail("Should have thrown a NotFoundException!");
} catch (NotFoundException e) {
assertEquals("Not Found: No workspace matching workspaceNamespace: " + namespace + ", workspaceId: " + name, e.getMessage());
}
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService, times(1)).getRequired(namespace, name);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER);
verifyNoMoreMockInteractions();
}
Aggregations