Search in sources :

Example 16 with NotFoundException

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

the class CohortsControllerTest method testMaterializeCohortWorkspaceNotFound.

@Test(expected = NotFoundException.class)
public void testMaterializeCohortWorkspaceNotFound() throws Exception {
    Cohort cohort = createDefaultCohort();
    cohort = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), cohort).getBody();
    WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
    String workspaceName = "badWorkspace";
    org.pmiops.workbench.firecloud.model.WorkspaceResponse fcResponse = new org.pmiops.workbench.firecloud.model.WorkspaceResponse();
    fcResponse.setAccessLevel(owner.toString());
    when(fireCloudService.getWorkspace(WORKSPACE_NAMESPACE, workspaceName)).thenReturn(fcResponse);
    when(workspaceService.getWorkspaceAccessLevel(WORKSPACE_NAMESPACE, workspaceName)).thenThrow(new NotFoundException());
    MaterializeCohortRequest request = new MaterializeCohortRequest();
    request.setCohortName(cohort.getName());
    cohortsController.materializeCohort(WORKSPACE_NAMESPACE, workspaceName, request);
}
Also used : Cohort(org.pmiops.workbench.model.Cohort) MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 17 with NotFoundException

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

the class CohortReviewServiceImplTest method validateMatchingWorkspaceNotFound.

@Test
public void validateMatchingWorkspaceNotFound() throws Exception {
    String workspaceNamespace = "test-workspace";
    String workspaceName = "test";
    long workspaceId = 1;
    long badWorkspaceId = 99;
    Workspace workspace = new Workspace();
    workspace.setWorkspaceId(badWorkspaceId);
    WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
    when(workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceName, WorkspaceAccessLevel.READER)).thenReturn(owner);
    when(workspaceService.getRequired(workspaceNamespace, workspaceName)).thenReturn(workspace);
    try {
        cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceName, workspaceId, WorkspaceAccessLevel.READER);
        fail("Should have thrown NotFoundException!");
    } catch (NotFoundException e) {
        assertEquals("Not Found: No workspace matching workspaceNamespace: " + workspaceNamespace + ", workspaceId: " + workspaceName, e.getMessage());
    }
    verify(workspaceService).enforceWorkspaceAccessLevel(workspaceNamespace, workspaceName, WorkspaceAccessLevel.READER);
    verify(workspaceService).getRequired(workspaceNamespace, workspaceName);
    verifyNoMoreMockInteractions();
}
Also used : NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 18 with NotFoundException

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

the class WorkspacesControllerTest method mockObjectsForBuckFileList.

private void mockObjectsForBuckFileList() throws ApiException {
    org.pmiops.workbench.firecloud.model.WorkspaceResponse fcResponse = new org.pmiops.workbench.firecloud.model.WorkspaceResponse();
    org.pmiops.workbench.firecloud.model.WorkspaceResponse fcResponseWithException = new org.pmiops.workbench.firecloud.model.WorkspaceResponse();
    org.pmiops.workbench.firecloud.model.Workspace mockWorkspace = new org.pmiops.workbench.firecloud.model.Workspace();
    org.pmiops.workbench.firecloud.model.Workspace mockWorkspaceEmpty = new org.pmiops.workbench.firecloud.model.Workspace();
    mockWorkspace.setBucketName("MockBucketName");
    fcResponse.setWorkspace(mockWorkspace);
    fcResponseWithException.setWorkspace(mockWorkspaceEmpty);
    when(fireCloudService.getWorkspace("mockProjectName", "mockWorkspaceName")).thenReturn(fcResponse);
    Blob mockBlob = mock(Blob.class);
    Blob mockBlob1 = mock(Blob.class);
    when(mockBlob.getName()).thenReturn("notebooks/mockFile.ipynb");
    when(mockBlob1.getName()).thenReturn("notebooks/mockFile.text");
    List<Blob> blobList = ImmutableList.of(mockBlob, mockBlob1);
    when(cloudStorageService.getBlobList("MockBucketName", "notebooks")).thenReturn(blobList);
    when(fireCloudService.getWorkspace("mockProject", "mockWorkspace")).thenThrow(new NotFoundException());
}
Also used : ShareWorkspaceResponse(org.pmiops.workbench.model.ShareWorkspaceResponse) Blob(com.google.cloud.storage.Blob) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) Workspace(org.pmiops.workbench.model.Workspace)

Example 19 with NotFoundException

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

the class CohortReviewServiceImplTest method saveParticipantCohortAnnotationNotFoundCohortAnnotationDefinition.

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

Example 20 with NotFoundException

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

the class CohortAnnotationDefinitionControllerTest method createCohortAnnotationDefinition_BadWorkspace.

@Test
public void createCohortAnnotationDefinition_BadWorkspace() 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(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER)).thenReturn(owner);
    when(cohortDao.findOne(cohortId)).thenReturn(cohort);
    when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
    try {
        cohortAnnotationDefinitionController.createCohortAnnotationDefinition(namespace, name, cohortId, new CohortAnnotationDefinition());
        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 : CohortAnnotationDefinition(org.pmiops.workbench.model.CohortAnnotationDefinition) 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)

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