use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortReviewControllerTest method getParticipantCohortAnnotations.
@Test
public void getParticipantCohortAnnotations() throws Exception {
long cohortReviewId = 1;
when(cohortReviewService.findCohort(cohortId)).thenReturn(createCohort(cohortId, workspaceId, null));
when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.READER)).thenReturn(new Workspace());
when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(createCohortReview(0, cohortId, cohortReviewId, cdrVersionId, null));
when(cohortReviewService.findParticipantCohortAnnotations(cohortReviewId, participantId)).thenReturn(new ArrayList<>());
reviewController.getParticipantCohortAnnotations(namespace, name, cohortId, cdrVersionId, participantId);
verify(cohortReviewService).findCohort(cohortId);
verify(cohortReviewService).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.READER);
verify(cohortReviewService).findCohortReview(cohortId, cdrVersionId);
verify(cohortReviewService).findParticipantCohortAnnotations(cohortReviewId, participantId);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortReviewControllerTest method assertFindByCohortIdAndCdrVersionId.
private void assertFindByCohortIdAndCdrVersionId(String namespace, String name, long cohortId, long cdrVersionId, Integer page, Integer pageSize, SortOrder sortOrder, ParticipantCohortStatusColumns sortColumn) {
Integer pageParam = page == null ? 0 : page;
Integer pageSizeParam = pageSize == null ? 25 : pageSize;
sortColumn = (sortColumn == null || sortColumn.name().equals(sortColumn.PARTICIPANTID)) ? ParticipantCohortStatusColumns.PARTICIPANTID : sortColumn;
sortOrder = sortOrder == null ? SortOrder.ASC : sortOrder;
ParticipantCohortStatusKey key = new ParticipantCohortStatusKey().cohortReviewId(cohortId).participantId(participantId);
final Date dob = new Date(System.currentTimeMillis());
ParticipantCohortStatus dbParticipant = new ParticipantCohortStatus().participantKey(key).status(CohortStatus.INCLUDED).birthDate(dob).ethnicityConceptId(1L).genderConceptId(1L).raceConceptId(1L);
org.pmiops.workbench.model.ParticipantCohortStatus respParticipant = new org.pmiops.workbench.model.ParticipantCohortStatus().participantId(1L).status(CohortStatus.INCLUDED).birthDate(dob.getTime()).ethnicityConceptId(1L).genderConceptId(1L).raceConceptId(1L);
org.pmiops.workbench.model.CohortReview respCohortReview = new org.pmiops.workbench.model.CohortReview().cohortReviewId(1L).cohortId(cohortId).cdrVersionId(cdrVersionId).matchedParticipantCount(1000L).reviewedCount(0L).reviewSize(200L).page(pageParam).pageSize(pageSizeParam).sortOrder(sortOrder.toString()).sortColumn(sortColumn.toString()).participantCohortStatuses(Arrays.asList(respParticipant));
List<ParticipantCohortStatus> participants = new ArrayList<ParticipantCohortStatus>();
participants.add(dbParticipant);
CohortReview cohortReviewAfter = new CohortReview();
cohortReviewAfter.setCohortReviewId(1L);
cohortReviewAfter.setCohortId(cohortId);
cohortReviewAfter.setCdrVersionId(cdrVersionId);
cohortReviewAfter.setMatchedParticipantCount(1000);
cohortReviewAfter.setReviewSize(200);
cohortReviewAfter.setCreationTime(new Timestamp(System.currentTimeMillis()));
Cohort cohort = new Cohort();
cohort.setWorkspaceId(1);
Map<String, Map<Long, String>> concepts = new HashMap<>();
concepts.put(GenderRaceEthnicityType.RACE.name(), new HashMap<>());
concepts.put(GenderRaceEthnicityType.GENDER.name(), new HashMap<>());
concepts.put(GenderRaceEthnicityType.ETHNICITY.name(), new HashMap<>());
GenderRaceEthnicityConcept greConcept = new GenderRaceEthnicityConcept(concepts);
when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(cohortReviewAfter);
when(cohortReviewService.findAll(key.getCohortReviewId(), Collections.<Filter>emptyList(), new PageRequest(pageParam, pageSizeParam, sortOrder, sortColumn.toString()))).thenReturn(participants);
when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.READER)).thenReturn(new Workspace());
when(cohortReviewService.findCohort(cohortId)).thenReturn(cohort);
ParticipantCohortStatuses request = new ParticipantCohortStatuses();
request.page(page);
request.pageSize(pageSize);
request.sortOrder(sortOrder);
request.sortColumn(sortColumn);
request.pageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES);
ResponseEntity<org.pmiops.workbench.model.CohortReview> response = reviewController.getParticipantCohortStatuses(namespace, name, cohortId, cdrVersionId, request);
org.pmiops.workbench.model.CohortReview actualCohortReview = response.getBody();
respCohortReview.setCreationTime(actualCohortReview.getCreationTime());
assertEquals(respCohortReview, response.getBody());
verify(cohortReviewService, atLeast(1)).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.READER);
verify(cohortReviewService, atLeast(1)).findCohortReview(cohortId, cdrVersionId);
verify(cohortReviewService, times(1)).findAll(key.getCohortReviewId(), Collections.<Filter>emptyList(), new PageRequest(pageParam, pageSizeParam, sortOrder, sortColumn.toString()));
verify(cohortReviewService, atLeast(1)).findCohort(cohortId);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortReviewControllerTest method createWorkspace.
private Workspace createWorkspace(long workspaceId, String namespace, String name) {
Workspace workspace = new Workspace();
workspace.setWorkspaceId(workspaceId);
workspace.setWorkspaceNamespace(namespace);
workspace.setFirecloudName(name);
return workspace;
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortReviewControllerTest method deleteParticipantCohortAnnotation.
@Test
public void deleteParticipantCohortAnnotation() throws Exception {
when(cohortReviewService.findCohort(cohortId)).thenReturn(createCohort(cohortId, workspaceId, null));
when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER)).thenReturn(new Workspace());
when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(createCohortReview(0, cohortId, cohortReviewId, cdrVersionId, null));
when(cohortReviewService.findParticipantCohortStatus(cohortReviewId, participantId)).thenReturn(new ParticipantCohortStatus());
doNothing().when(cohortReviewService).deleteParticipantCohortAnnotation(1L, cohortReviewId, participantId);
reviewController.deleteParticipantCohortAnnotation(namespace, name, cohortId, cdrVersionId, participantId, 1L);
verify(cohortReviewService).findCohort(cohortId);
verify(cohortReviewService).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER);
verify(cohortReviewService).findCohortReview(cohortId, cdrVersionId);
verify(cohortReviewService).findParticipantCohortStatus(cohortReviewId, participantId);
verify(cohortReviewService).deleteParticipantCohortAnnotation(1L, cohortReviewId, participantId);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method updateCohortAnnotationDefinition_BadWorkspace.
@Test
public void updateCohortAnnotationDefinition_BadWorkspace() 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);
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);
try {
cohortAnnotationDefinitionController.updateCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId, request);
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();
}
Aggregations