Search in sources :

Example 6 with CohortAnnotationDefinition

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

Example 7 with CohortAnnotationDefinition

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

the class CohortAnnotationDefinitionControllerTest method createClientCohortAnnotationDefinition.

private CohortAnnotationDefinition createClientCohortAnnotationDefinition(long annotationDefinitionId, long cohortId, String columnName, AnnotationType annotationType) {
    CohortAnnotationDefinition request = new CohortAnnotationDefinition();
    request.setCohortAnnotationDefinitionId(annotationDefinitionId);
    request.setCohortId(cohortId);
    request.setColumnName(columnName);
    request.setAnnotationType(AnnotationType.STRING);
    request.setEnumValues(new ArrayList<>());
    return request;
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.model.CohortAnnotationDefinition)

Aggregations

CohortAnnotationDefinition (org.pmiops.workbench.model.CohortAnnotationDefinition)7 Test (org.junit.Test)6 WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)6 Cohort (org.pmiops.workbench.db.model.Cohort)5 Workspace (org.pmiops.workbench.db.model.Workspace)5 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 ConflictException (org.pmiops.workbench.exceptions.ConflictException)1 ModifyCohortAnnotationDefinitionRequest (org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest)1