use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method addEnrollment_updatesRequestContext.
@Test
public void addEnrollment_updatesRequestContext() {
RequestContext.set(new RequestContext.Builder().withCallerUserId("123").withOrgSponsoredStudies(ImmutableSet.of(TEST_STUDY_ID)).withCallerRoles(ImmutableSet.of(STUDY_COORDINATOR)).build());
Account account = Account.create();
account.setId(TEST_USER_ID);
Study study = Study.create();
study.setPhase(RECRUITMENT);
when(mockStudyService.getStudy(TEST_APP_ID, TEST_STUDY_ID, true)).thenReturn(study);
Enrollment en = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
en.setExternalId("externalId");
service.addEnrollment(account, en, true);
assertEquals(account.getEnrollments().size(), 1);
Enrollment updated = Iterables.getFirst(account.getEnrollments(), null);
assertEquals(updated.getAccountId(), TEST_USER_ID);
assertEquals(updated.getAppId(), TEST_APP_ID);
assertEquals(updated.getEnrolledBy(), "123");
assertEquals(updated.getEnrolledOn(), CREATED_ON);
assertEquals(updated.getStudyId(), TEST_STUDY_ID);
assertEquals(updated.getExternalId(), "externalId");
assertEquals(RequestContext.get().getCallerEnrolledStudies(), ImmutableSet.of(TEST_STUDY_ID));
}
use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method unenroll_byThirdPartyAdmin.
@Test
public void unenroll_byThirdPartyAdmin() {
RequestContext.set(new RequestContext.Builder().withCallerUserId("adminUser").withCallerRoles(ImmutableSet.of(ADMIN)).build());
Enrollment existing = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
Account account = Account.create();
account.setId(TEST_USER_ID);
account.setEnrollments(Sets.newHashSet(existing));
TestUtils.mockEditAccount(mockAccountService, account);
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
enrollment.setWithdrawnOn(MODIFIED_ON);
enrollment.setWithdrawalNote("Withdrawal reason");
Enrollment retValue = service.unenroll(enrollment);
assertEquals(retValue.getWithdrawnOn(), MODIFIED_ON);
assertEquals(retValue.getWithdrawnBy(), "adminUser");
assertEquals(retValue.getWithdrawalNote(), "Withdrawal reason");
verify(mockAccountService).editAccount(any(), any());
Enrollment captured = Iterables.getFirst(account.getEnrollments(), null);
assertEquals(captured.getWithdrawnOn(), MODIFIED_ON);
assertEquals(captured.getWithdrawnBy(), "adminUser");
assertEquals(captured.getWithdrawalNote(), "Withdrawal reason");
}
use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method updateEnrollment_incomingEnrollmentIsValidated.
@Test(expectedExceptions = InvalidEntityException.class)
public void updateEnrollment_incomingEnrollmentIsValidated() {
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
enrollment.setAccountId(null);
service.updateEnrollment(enrollment);
}
use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method unenroll_doesNotExists.
@Test(expectedExceptions = EntityNotFoundException.class)
public void unenroll_doesNotExists() {
RequestContext.set(new RequestContext.Builder().withCallerRoles(ImmutableSet.of(ADMIN)).build());
Account account = Account.create();
account.setId(TEST_USER_ID);
TestUtils.mockEditAccount(mockAccountService, account);
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
service.unenroll(enrollment);
}
use of org.sagebionetworks.bridge.models.studies.Enrollment in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantServiceTest method researcherCanAddExternalIdOnCreate.
@Test
public void researcherCanAddExternalIdOnCreate() {
RequestContext.set(new RequestContext.Builder().withCallerUserId("id").withCallerRoles(ImmutableSet.of(RESEARCHER)).build());
when(studyService.getStudy(TEST_APP_ID, STUDY_ID, false)).thenReturn(Study.create());
when(participantService.generateGUID()).thenReturn(ID, HEALTH_CODE);
StudyParticipant participant = new StudyParticipant.Builder().copyOf(PARTICIPANT).withExternalIds(ENROLLMENT_MAP).build();
participantService.createParticipant(APP, participant, false);
verify(accountService).createAccount(eq(APP), accountCaptor.capture());
verify(enrollmentService).addEnrollment(any(), enrollmentCaptor.capture(), eq(false));
Enrollment enrollment = enrollmentCaptor.getValue();
assertEquals(enrollment.getAppId(), TEST_APP_ID);
assertEquals(enrollment.getStudyId(), STUDY_ID);
assertEquals(enrollment.getExternalId(), EXTERNAL_ID);
assertEquals(enrollment.getAccountId(), ID);
}
Aggregations