Search in sources :

Example 11 with WorkspaceAccessLevel

use of org.pmiops.workbench.model.WorkspaceAccessLevel 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 12 with WorkspaceAccessLevel

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

the class CohortReviewServiceImplTest method validateMatchingWorkspace.

@Test
public void validateMatchingWorkspace() throws Exception {
    String workspaceNamespace = "test-workspace";
    String workspaceName = "test";
    long workspaceId = 1;
    Workspace workspace = new Workspace();
    workspace.setWorkspaceId(workspaceId);
    WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
    when(workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceName, WorkspaceAccessLevel.READER)).thenReturn(owner);
    when(workspaceService.getRequired(workspaceNamespace, workspaceName)).thenReturn(workspace);
    cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceName, workspaceId, WorkspaceAccessLevel.READER);
    verify(workspaceService).enforceWorkspaceAccessLevel(workspaceNamespace, workspaceName, WorkspaceAccessLevel.READER);
    verify(workspaceService).getRequired(workspaceNamespace, workspaceName);
    verifyNoMoreMockInteractions();
}
Also used : WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 13 with WorkspaceAccessLevel

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

the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinition.

@Test
public void getCohortAnnotationDefinition() throws Exception {
    String namespace = "aou-test";
    String name = "test";
    long cohortId = 1;
    long workspaceId = 1;
    long annotationDefinitionId = 1;
    String columnName = "name";
    Cohort cohort = createCohort(workspaceId);
    Workspace workspace = createWorkspace(namespace, name, workspaceId);
    org.pmiops.workbench.db.model.CohortAnnotationDefinition cohortAnnotationDefinition = createDBCohortAnnotationDefinition(cohortId, annotationDefinitionId, AnnotationType.STRING, columnName);
    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);
    when(cohortAnnotationDefinitionDao.findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId)).thenReturn(cohortAnnotationDefinition);
    CohortAnnotationDefinition responseDefinition = cohortAnnotationDefinitionController.getCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId).getBody();
    CohortAnnotationDefinition expectedResponse = createClientCohortAnnotationDefinition(annotationDefinitionId, cohortId, columnName, AnnotationType.STRING);
    assertEquals(expectedResponse, responseDefinition);
    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.READER);
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.model.CohortAnnotationDefinition) Cohort(org.pmiops.workbench.db.model.Cohort) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 14 with WorkspaceAccessLevel

use of org.pmiops.workbench.model.WorkspaceAccessLevel 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)

Example 15 with WorkspaceAccessLevel

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

the class CohortAnnotationDefinitionControllerTest method createCohortAnnotationDefinition.

@Test
public void createCohortAnnotationDefinition() throws Exception {
    String namespace = "aou-test";
    String name = "test";
    long cohortId = 1;
    long workspaceId = 1;
    long annotationDefinitionId = 1;
    final String columnName = "testing";
    Cohort cohort = createCohort(workspaceId);
    Workspace workspace = createWorkspace(namespace, name, workspaceId);
    CohortAnnotationDefinition request = createClientCohortAnnotationDefinition(annotationDefinitionId, cohortId, columnName, AnnotationType.STRING);
    org.pmiops.workbench.db.model.CohortAnnotationDefinition dbCohortAnnotationDefinition = createDBCohortAnnotationDefinition(cohortId, annotationDefinitionId, request.getAnnotationType(), request.getColumnName());
    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.save(dbCohortAnnotationDefinition)).thenReturn(dbCohortAnnotationDefinition);
    when(cohortAnnotationDefinitionDao.findByCohortIdAndColumnName(cohortId, columnName)).thenReturn(null);
    CohortAnnotationDefinition expectedResponse = createClientCohortAnnotationDefinition(annotationDefinitionId, cohortId, columnName, AnnotationType.STRING);
    CohortAnnotationDefinition response = cohortAnnotationDefinitionController.createCohortAnnotationDefinition(namespace, name, cohortId, request).getBody();
    assertEquals(expectedResponse, response);
    verify(cohortDao, times(1)).findOne(cohortId);
    verify(workspaceService, times(1)).getRequired(namespace, name);
    verify(cohortAnnotationDefinitionDao, times(1)).save(dbCohortAnnotationDefinition);
    verify(cohortAnnotationDefinitionDao, times(1)).findByCohortIdAndColumnName(cohortId, columnName);
    verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.model.CohortAnnotationDefinition) Cohort(org.pmiops.workbench.db.model.Cohort) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Aggregations

WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)24 Test (org.junit.Test)23 Workspace (org.pmiops.workbench.db.model.Workspace)17 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)16 Cohort (org.pmiops.workbench.db.model.Cohort)15 CohortAnnotationDefinition (org.pmiops.workbench.model.CohortAnnotationDefinition)6 ModifyCohortAnnotationDefinitionRequest (org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest)5 ConflictException (org.pmiops.workbench.exceptions.ConflictException)2 ServerErrorException (org.pmiops.workbench.exceptions.ServerErrorException)1 ApiException (org.pmiops.workbench.firecloud.ApiException)1 Cohort (org.pmiops.workbench.model.Cohort)1 EmptyResponse (org.pmiops.workbench.model.EmptyResponse)1 MaterializeCohortRequest (org.pmiops.workbench.model.MaterializeCohortRequest)1 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)1