Search in sources :

Example 1 with Study

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Study(org.sagebionetworks.bridge.models.studies.Study) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test)

Example 2 with Study

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Study(org.sagebionetworks.bridge.models.studies.Study) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test)

Example 3 with Study

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));
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Study(org.sagebionetworks.bridge.models.studies.Study) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 4 with Study

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Study(org.sagebionetworks.bridge.models.studies.Study) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test)

Example 5 with Study

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);
}
Also used : Study(org.sagebionetworks.bridge.models.studies.Study) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) Test(org.testng.annotations.Test)

Aggregations

Study (org.sagebionetworks.bridge.models.studies.Study)169 Test (org.testng.annotations.Test)137 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)64 RequestContext (org.sagebionetworks.bridge.RequestContext)33 StudyActivityEvent (org.sagebionetworks.bridge.models.activities.StudyActivityEvent)26 Schedule2Test (org.sagebionetworks.bridge.models.schedules2.Schedule2Test)24 SessionTest (org.sagebionetworks.bridge.models.schedules2.SessionTest)24 Account (org.sagebionetworks.bridge.models.accounts.Account)20 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)18 App (org.sagebionetworks.bridge.models.apps.App)14 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)13 PagedResourceList (org.sagebionetworks.bridge.models.PagedResourceList)12 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)12 Timeline (org.sagebionetworks.bridge.models.schedules2.timelines.Timeline)12 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)11 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)11 StudyBurst (org.sagebionetworks.bridge.models.schedules2.StudyBurst)11 CacheKey (org.sagebionetworks.bridge.cache.CacheKey)10 ResourceList (org.sagebionetworks.bridge.models.ResourceList)9 DateTime (org.joda.time.DateTime)8