use of org.sagebionetworks.bridge.models.studies.Study in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method enroll_byAdmin.
@Test
public void enroll_byAdmin() {
RequestContext.set(new RequestContext.Builder().withCallerUserId("adminUser").withCallerRoles(ImmutableSet.of(ADMIN)).build());
Account account = Account.create();
account.setId(TEST_USER_ID);
TestUtils.mockEditAccount(mockAccountService, account);
Study study = Study.create();
study.setPhase(RECRUITMENT);
when(mockStudyService.getStudy(TEST_APP_ID, TEST_STUDY_ID, true)).thenReturn(study);
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
enrollment.setNote(TEST_NOTE);
Enrollment retValue = service.enroll(enrollment);
assertEquals(retValue.getAccountId(), TEST_USER_ID);
assertEquals(retValue.getEnrolledBy(), "adminUser");
assertEquals(retValue.getNote(), TEST_NOTE);
}
use of org.sagebionetworks.bridge.models.studies.Study in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method enroll_byResearcher.
@Test
public void enroll_byResearcher() {
RequestContext.set(new RequestContext.Builder().withCallerUserId("adminUser").withCallerRoles(ImmutableSet.of(RESEARCHER)).build());
when(mockSponsorService.isStudySponsoredBy(TEST_STUDY_ID, TEST_ORG_ID)).thenReturn(Boolean.TRUE);
Account account = Account.create();
account.setId(TEST_USER_ID);
TestUtils.mockEditAccount(mockAccountService, account);
Study study = Study.create();
study.setPhase(RECRUITMENT);
when(mockStudyService.getStudy(TEST_APP_ID, TEST_STUDY_ID, true)).thenReturn(study);
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
enrollment.setNote(TEST_NOTE);
Enrollment retValue = service.enroll(enrollment);
assertEquals(retValue.getAccountId(), TEST_USER_ID);
assertEquals(retValue.getEnrolledBy(), "adminUser");
assertEquals(retValue.getNote(), TEST_NOTE);
}
use of org.sagebionetworks.bridge.models.studies.Study in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method enroll_bySelf.
@Test
public void enroll_bySelf() {
RequestContext.set(new RequestContext.Builder().withCallerUserId(TEST_USER_ID).withCallerRoles(ImmutableSet.of(ADMIN)).build());
// This should not effect the behavior of the enrollment.
Enrollment otherStudy = Enrollment.create(TEST_APP_ID, "otherStudy", TEST_USER_ID);
Account account = Account.create();
account.setId(TEST_USER_ID);
account.setEnrollments(Sets.newHashSet(otherStudy));
TestUtils.mockEditAccount(mockAccountService, account);
Study study = Study.create();
study.setPhase(RECRUITMENT);
when(mockStudyService.getStudy(TEST_APP_ID, TEST_STUDY_ID, true)).thenReturn(study);
DateTime timestamp = DateTime.now();
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
enrollment.setExternalId("extId");
enrollment.setEnrolledOn(timestamp);
enrollment.setNote(TEST_NOTE);
Enrollment retValue = service.enroll(enrollment);
assertEquals(retValue.getAppId(), TEST_APP_ID);
assertEquals(retValue.getStudyId(), TEST_STUDY_ID);
assertEquals(retValue.getAccountId(), TEST_USER_ID);
assertEquals(retValue.getExternalId(), "extId");
assertEquals(retValue.getEnrolledOn(), timestamp);
assertNull(retValue.getEnrolledBy());
assertNull(retValue.getWithdrawnOn());
assertNull(retValue.getWithdrawnBy());
assertNull(retValue.getWithdrawalNote());
assertFalse(retValue.isConsentRequired());
assertEquals(retValue.getNote(), TEST_NOTE);
assertTrue(account.getEnrollments().contains(retValue));
}
use of org.sagebionetworks.bridge.models.studies.Study in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method enroll_alreadyExists.
@Test
public void enroll_alreadyExists() {
RequestContext.set(new RequestContext.Builder().withCallerUserId(TEST_USER_ID).withCallerRoles(ImmutableSet.of(ADMIN)).build());
Account account = Account.create();
account.setId(TEST_USER_ID);
TestUtils.mockEditAccount(mockAccountService, account);
Study study = Study.create();
study.setPhase(RECRUITMENT);
when(mockStudyService.getStudy(TEST_APP_ID, TEST_STUDY_ID, true)).thenReturn(study);
Enrollment existing = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
Enrollment otherStudy = Enrollment.create(TEST_APP_ID, "otherStudy", TEST_USER_ID);
account.setEnrollments(ImmutableSet.of(existing, otherStudy));
when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
Enrollment enrollment = Enrollment.create(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
service.enroll(enrollment);
}
use of org.sagebionetworks.bridge.models.studies.Study in project BridgeServer2 by Sage-Bionetworks.
the class EnrollmentServiceTest method getEnrollmentsForUser_studyNotFound.
@Test(expectedExceptions = EntityNotFoundException.class, expectedExceptionsMessageRegExp = "Study not found.")
public void getEnrollmentsForUser_studyNotFound() {
when(mockStudyService.getStudy(TEST_APP_ID, TEST_STUDY_ID, true)).thenThrow(new EntityNotFoundException(Study.class));
service.getEnrollmentsForUser(TEST_APP_ID, TEST_STUDY_ID, TEST_USER_ID);
}
Aggregations