Search in sources :

Example 11 with Workspace

use of org.pmiops.workbench.db.model.Workspace 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();
}
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 12 with Workspace

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

the class CohortAnnotationDefinitionControllerTest method updateCohortAnnotationDefinition.

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

use of org.pmiops.workbench.db.model.Workspace 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();
}
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 14 with Workspace

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

the class CohortAnnotationDefinitionControllerTest method createCohortAnnotationDefinition_NameConflict.

@Test
public void createCohortAnnotationDefinition_NameConflict() 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 existingDefinition = 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.findByCohortIdAndColumnName(cohortId, columnName)).thenReturn(existingDefinition);
    CohortAnnotationDefinition expectedResponse = createClientCohortAnnotationDefinition(annotationDefinitionId, cohortId, columnName, AnnotationType.STRING);
    try {
        cohortAnnotationDefinitionController.createCohortAnnotationDefinition(namespace, name, cohortId, request);
        fail("Should have thrown a ConflictException!");
    } catch (ConflictException e) {
        assertEquals("Conflict: Cohort Annotation Definition name exists for: " + columnName, e.getMessage());
    }
    verify(cohortDao, times(1)).findOne(cohortId);
    verify(workspaceService, times(1)).getRequired(namespace, name);
    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) ConflictException(org.pmiops.workbench.exceptions.ConflictException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 15 with Workspace

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

the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinition_NotFoundAnnotationDefinition.

@Test
public void getCohortAnnotationDefinition_NotFoundAnnotationDefinition() 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.READER)).thenReturn(owner);
    when(cohortDao.findOne(cohortId)).thenReturn(cohort);
    when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
    when(cohortAnnotationDefinitionDao.findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId)).thenReturn(null);
    try {
        cohortAnnotationDefinitionController.getCohortAnnotationDefinition(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.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)

Aggregations

Workspace (org.pmiops.workbench.db.model.Workspace)38 Cohort (org.pmiops.workbench.db.model.Cohort)23 Test (org.junit.Test)21 WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)18 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)15 CohortReview (org.pmiops.workbench.db.model.CohortReview)7 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)6 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)5 CohortAnnotationDefinition (org.pmiops.workbench.model.CohortAnnotationDefinition)5 Gson (com.google.gson.Gson)4 Timestamp (java.sql.Timestamp)4 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)4 org.pmiops.workbench.model (org.pmiops.workbench.model)4 ModifyCohortAnnotationDefinitionRequest (org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest)4 Before (org.junit.Before)3 ConflictException (org.pmiops.workbench.exceptions.ConflictException)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)2 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)2 EmptyResponse (org.pmiops.workbench.model.EmptyResponse)2