use of org.pmiops.workbench.db.model.Workspace 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();
}
use of org.pmiops.workbench.db.model.Workspace 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();
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method deleteCohortAnnotationDefinition.
@Test
public void deleteCohortAnnotationDefinition() 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.WRITER)).thenReturn(owner);
when(cohortDao.findOne(cohortId)).thenReturn(cohort);
when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
when(cohortAnnotationDefinitionDao.findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId)).thenReturn(cohortAnnotationDefinition);
doNothing().when(cohortAnnotationDefinitionDao).delete(annotationDefinitionId);
EmptyResponse response = cohortAnnotationDefinitionController.deleteCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId).getBody();
assertEquals(new EmptyResponse(), response);
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService, times(1)).getRequired(namespace, name);
verify(cohortAnnotationDefinitionDao, times(1)).findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId);
verify(cohortAnnotationDefinitionDao, times(1)).delete(annotationDefinitionId);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.db.model.Workspace 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();
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method updateCohortAnnotationDefinition_NameConflict.
@Test
public void updateCohortAnnotationDefinition_NameConflict() 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");
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(definition);
try {
cohortAnnotationDefinitionController.updateCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId, 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)).findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId);
verify(cohortAnnotationDefinitionDao, times(1)).findByCohortIdAndColumnName(cohortId, columnName);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
verifyNoMoreMockInteractions();
}
Aggregations