Search in sources :

Example 1 with HibernateEnrollment

use of org.sagebionetworks.bridge.hibernate.HibernateEnrollment in project BridgeServer2 by Sage-Bionetworks.

the class Enrollment method create.

static Enrollment create(String appId, String studyId, String accountId, String externalId) {
    checkNotNull(appId);
    checkNotNull(studyId);
    checkNotNull(accountId);
    HibernateEnrollment enrollment = new HibernateEnrollment();
    enrollment.setAppId(appId);
    enrollment.setStudyId(studyId);
    enrollment.setAccountId(accountId);
    // it's ok for external ID to be null
    enrollment.setExternalId(externalId);
    return enrollment;
}
Also used : HibernateEnrollment(org.sagebionetworks.bridge.hibernate.HibernateEnrollment)

Example 2 with HibernateEnrollment

use of org.sagebionetworks.bridge.hibernate.HibernateEnrollment in project BridgeServer2 by Sage-Bionetworks.

the class EnrollmentControllerTest method enroll.

@Test
public void enroll() throws Exception {
    Enrollment enrollment = new HibernateEnrollment();
    enrollment.setEnrolledOn(CREATED_ON);
    enrollment.setExternalId("anExternalId");
    enrollment.setAccountId(TEST_USER_ID);
    enrollment.setConsentRequired(true);
    TestUtils.mockRequestBody(mockRequest, enrollment);
    Enrollment completed = new HibernateEnrollment();
    when(mockService.enroll(any())).thenReturn(completed);
    Enrollment retValue = controller.enroll(TEST_STUDY_ID);
    assertSame(retValue, completed);
    verify(mockService).enroll(enrollmentCaptor.capture());
    Enrollment value = enrollmentCaptor.getValue();
    assertEquals(value.getAppId(), TEST_APP_ID);
    assertEquals(value.getStudyId(), TEST_STUDY_ID);
    assertEquals(value.getEnrolledOn(), CREATED_ON);
    assertEquals(value.getExternalId(), "anExternalId");
    assertEquals(value.getAccountId(), TEST_USER_ID);
    assertTrue(value.isConsentRequired());
}
Also used : HibernateEnrollment(org.sagebionetworks.bridge.hibernate.HibernateEnrollment) HibernateEnrollment(org.sagebionetworks.bridge.hibernate.HibernateEnrollment) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test)

Example 3 with HibernateEnrollment

use of org.sagebionetworks.bridge.hibernate.HibernateEnrollment in project BridgeServer2 by Sage-Bionetworks.

the class EnrollmentControllerTest method unenroll.

@Test
public void unenroll() throws Exception {
    Enrollment completed = new HibernateEnrollment();
    when(mockService.unenroll(any())).thenReturn(completed);
    Enrollment retValue = controller.unenroll(TEST_STUDY_ID, TEST_USER_ID, "This is a note");
    assertSame(retValue, completed);
    verify(mockService).unenroll(enrollmentCaptor.capture());
    Enrollment value = enrollmentCaptor.getValue();
    assertEquals(value.getWithdrawalNote(), "This is a note");
    assertEquals(value.getAppId(), TEST_APP_ID);
    assertEquals(value.getStudyId(), TEST_STUDY_ID);
    assertEquals(value.getAccountId(), TEST_USER_ID);
}
Also used : HibernateEnrollment(org.sagebionetworks.bridge.hibernate.HibernateEnrollment) HibernateEnrollment(org.sagebionetworks.bridge.hibernate.HibernateEnrollment) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test)

Example 4 with HibernateEnrollment

use of org.sagebionetworks.bridge.hibernate.HibernateEnrollment in project BridgeServer2 by Sage-Bionetworks.

the class EnrollmentControllerTest method updateEnrollmentNote.

@Test
public void updateEnrollmentNote() throws Exception {
    UserSession session = new UserSession();
    session.setAppId(TEST_APP_ID);
    doReturn(session).when(controller).getAdministrativeSession();
    Enrollment enrollment = new HibernateEnrollment();
    enrollment.setAppId("otherAppId");
    enrollment.setStudyId("otherStudyId");
    enrollment.setAccountId("otherUserId");
    enrollment.setNote(TEST_NOTE);
    mockRequestBody(mockRequest, enrollment);
    controller.updateEnrollment(TEST_STUDY_ID, TEST_USER_ID);
    verify(mockService).updateEnrollment(enrollmentCaptor.capture());
    Enrollment captured = enrollmentCaptor.getValue();
    assertEquals(captured.getAppId(), TEST_APP_ID);
    assertEquals(captured.getStudyId(), TEST_STUDY_ID);
    assertEquals(captured.getAccountId(), TEST_USER_ID);
    assertEquals(captured.getNote(), TEST_NOTE);
}
Also used : HibernateEnrollment(org.sagebionetworks.bridge.hibernate.HibernateEnrollment) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) HibernateEnrollment(org.sagebionetworks.bridge.hibernate.HibernateEnrollment) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Test(org.testng.annotations.Test)

Aggregations

HibernateEnrollment (org.sagebionetworks.bridge.hibernate.HibernateEnrollment)4 Enrollment (org.sagebionetworks.bridge.models.studies.Enrollment)3 Test (org.testng.annotations.Test)3 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)1