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;
}
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());
}
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);
}
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);
}
Aggregations