Search in sources :

Example 21 with NotFoundException

use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.

the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinition_NotFoundWorkspace.

@Test
public void getCohortAnnotationDefinition_NotFoundWorkspace() 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);
    WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
    when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER)).thenReturn(owner);
    when(cohortDao.findOne(cohortId)).thenReturn(cohort);
    when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
    try {
        cohortAnnotationDefinitionController.getCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId);
        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();
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 22 with NotFoundException

use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.

the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinitions_NotFoundCohort.

@Test
public void getCohortAnnotationDefinitions_NotFoundCohort() throws Exception {
    String namespace = "aou-test";
    String name = "test";
    long cohortId = 1;
    WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
    when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER)).thenReturn(owner);
    when(cohortDao.findOne(cohortId)).thenReturn(null);
    try {
        cohortAnnotationDefinitionController.getCohortAnnotationDefinitions(namespace, name, cohortId);
        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.READER);
    verifyNoMoreMockInteractions();
}
Also used : NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Test(org.junit.Test)

Example 23 with NotFoundException

use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.

the class CohortAnnotationDefinitionControllerTest method updateCohortAnnotationDefinition_BadAnnotationDefinitionId.

@Test
public void updateCohortAnnotationDefinition_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);
    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);
    when(cohortAnnotationDefinitionDao.findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId)).thenReturn(null);
    try {
        cohortAnnotationDefinitionController.updateCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId, request);
        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();
}
Also used : ModifyCohortAnnotationDefinitionRequest(org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest) Cohort(org.pmiops.workbench.db.model.Cohort) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 24 with NotFoundException

use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.

the class CohortAnnotationDefinitionControllerTest method deleteCohortAnnotationDefinition_BadWorkspace.

@Test
public void deleteCohortAnnotationDefinition_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);
    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.deleteCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId);
        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();
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 25 with NotFoundException

use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.

the class CohortAnnotationDefinitionControllerTest method updateCohortAnnotationDefinition_BadCohortId.

@Test
public void updateCohortAnnotationDefinition_BadCohortId() throws Exception {
    String namespace = "aou-test";
    String name = "test";
    long cohortId = 1;
    long annotationDefinitionId = 1;
    ModifyCohortAnnotationDefinitionRequest request = new ModifyCohortAnnotationDefinitionRequest();
    WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
    when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER)).thenReturn(owner);
    when(cohortDao.findOne(cohortId)).thenReturn(null);
    try {
        cohortAnnotationDefinitionController.updateCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId, request);
        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();
}
Also used : ModifyCohortAnnotationDefinitionRequest(org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Test(org.junit.Test)

Aggregations

NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)32 Test (org.junit.Test)18 WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)16 Workspace (org.pmiops.workbench.db.model.Workspace)14 Cohort (org.pmiops.workbench.db.model.Cohort)10 ApiException (org.pmiops.workbench.firecloud.ApiException)5 ParticipantCohortAnnotation (org.pmiops.workbench.db.model.ParticipantCohortAnnotation)4 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)4 ServerErrorException (org.pmiops.workbench.exceptions.ServerErrorException)4 CohortReview (org.pmiops.workbench.db.model.CohortReview)3 Blob (com.google.cloud.storage.Blob)2 Gson (com.google.gson.Gson)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)2 User (org.pmiops.workbench.db.model.User)2 WorkspaceUserRole (org.pmiops.workbench.db.model.WorkspaceUserRole)2 org.pmiops.workbench.model (org.pmiops.workbench.model)2 ClusterListResponse (org.pmiops.workbench.model.ClusterListResponse)2 ModifyCohortAnnotationDefinitionRequest (org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest)2