use of org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityControllerTest method createActivityResultsV2.
private ForwardCursorPagedResourceList<ScheduledActivity> createActivityResultsV2(int pageSize, String offsetKey) {
DynamoScheduledActivity activity = new DynamoScheduledActivity();
activity.setActivity(ACTIVITY_1);
activity.setHealthCode("healthCode");
activity.setSchedulePlanGuid("schedulePlanGuid");
return new ForwardCursorPagedResourceList<ScheduledActivity>(ImmutableList.of(activity), "777").withRequestParam(ResourceList.PAGE_SIZE, pageSize).withRequestParam(ResourceList.OFFSET_KEY, offsetKey);
}
use of org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantControllerTest method createActivityResultsV2.
private ForwardCursorPagedResourceList<ScheduledActivity> createActivityResultsV2(String offsetKey, int pageSize) {
DynamoScheduledActivity activity = new DynamoScheduledActivity();
activity.setActivity(ACTIVITY_1);
activity.setHealthCode(HEALTH_CODE);
activity.setSchedulePlanGuid("schedulePlanGuid");
List<ScheduledActivity> list = ImmutableList.of(activity);
return new ForwardCursorPagedResourceList<>(list, null).withRequestParam("pageSize", pageSize).withRequestParam("offsetKey", offsetKey);
}
use of org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList in project BridgeServer2 by Sage-Bionetworks.
the class HealthDataEx3ControllerTest method getRecordsForStudy.
@Test
public void getRecordsForStudy() {
// Set up mocks.
Study study = Study.create();
study.setAppId(TestConstants.TEST_APP_ID);
study.setIdentifier(STUDY_ID);
when(mockStudyService.getStudy(TestConstants.TEST_APP_ID, STUDY_ID, true)).thenReturn(study);
ForwardCursorPagedResourceList<HealthDataRecordEx3> recordList = new ForwardCursorPagedResourceList<>(ImmutableList.of(HealthDataRecordEx3.create()), null);
when(mockHealthDataEx3Service.getRecordsForAppAndStudy(TestConstants.TEST_APP_ID, STUDY_ID, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, OFFSET_KEY)).thenReturn(recordList);
// Execute and verify.
ResourceList<HealthDataRecordEx3> outputList = controller.getRecordsForStudy(TestConstants.TEST_APP_ID, STUDY_ID, CREATED_ON_START_STRING, CREATED_ON_END_STRING, PAGE_SIZE_STRING, OFFSET_KEY);
assertSame(outputList, recordList);
assertEquals(outputList.getRequestParams().size(), 5);
assertEquals(outputList.getRequestParams().get(ResourceList.START_TIME), CREATED_ON_START_STRING);
assertEquals(outputList.getRequestParams().get(ResourceList.END_TIME), CREATED_ON_END_STRING);
assertEquals(outputList.getRequestParams().get(ResourceList.PAGE_SIZE), BridgeConstants.API_DEFAULT_PAGE_SIZE);
assertEquals(outputList.getRequestParams().get(ResourceList.OFFSET_KEY), OFFSET_KEY);
assertEquals(outputList.getRequestParams().get(ResourceList.TYPE), ResourceList.REQUEST_PARAMS);
verify(mockHealthDataEx3Service).getRecordsForAppAndStudy(TestConstants.TEST_APP_ID, STUDY_ID, CREATED_ON_START, CREATED_ON_END, BridgeConstants.API_DEFAULT_PAGE_SIZE, OFFSET_KEY);
}
use of org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantControllerTest method getActivityHistoryForWorkerV2.
@Test
public void getActivityHistoryForWorkerV2() throws Exception {
session.setParticipant(new StudyParticipant.Builder().copyOf(session.getParticipant()).withRoles(ImmutableSet.of(Roles.WORKER)).build());
ForwardCursorPagedResourceList<ScheduledActivity> cursor = new ForwardCursorPagedResourceList<>(ImmutableList.of(ScheduledActivity.create()), "asdf");
when(mockParticipantService.getActivityHistory(eq(app), eq(TEST_USER_ID), eq("activityGuid"), any(), any(), eq("asdf"), eq(50))).thenReturn(cursor);
JsonNode result = controller.getActivityHistoryForWorkerV2(TEST_APP_ID, TEST_USER_ID, "activityGuid", START_TIME.toString(), END_TIME.toString(), null, "asdf", "50");
verify(mockParticipantService).getActivityHistory(eq(app), eq(TEST_USER_ID), eq("activityGuid"), any(), any(), eq("asdf"), eq(50));
ForwardCursorPagedResourceList<ScheduledActivity> retrieved = MAPPER.readValue(result.toString(), new TypeReference<ForwardCursorPagedResourceList<ScheduledActivity>>() {
});
assertFalse(retrieved.getItems().isEmpty());
}
use of org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityServiceTest method taskNotStartedIsUpdatedV4.
@Test
public void taskNotStartedIsUpdatedV4() {
// Activity in DDB has survey reference pointing to createdOn 1234. Newly created activity has survey reference
// pointing to createdOn 5678. Activity in DDB hasn't been started. We should update the activity in DDB.
// Create task references and activities.
// Schedule plan has been updated with a new activity that will be used in scheduled activity
Activity newActivity = new Activity.Builder().withGuid("CCC").withSurvey("my-survey", "my-survey-guid", new DateTime(5678)).build();
SchedulePlan ccc = schedulePlan(newActivity);
// This is the schedule plan returned from the DB with the new Activity
when(schedulePlanService.getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, TEST_APP_ID, false)).thenReturn(Lists.newArrayList(ccc));
// This is the persisted activity with the oldActivity
Activity oldActivity = new Activity.Builder().withGuid("CCC").withSurvey("my-survey", "my-survey-guid", new DateTime(1234)).build();
List<ScheduledActivity> db = createNewActivities("CCC" + TIME_PORTION);
db.get(0).setActivity(oldActivity);
ForwardCursorPagedResourceList<ScheduledActivity> page = new ForwardCursorPagedResourceList<>(db, null);
when(activityDao.getActivityHistoryV2(any(), any(), any(), any(), any(), anyInt())).thenReturn(page);
List<ScheduledActivity> returnedActivities = service.getScheduledActivitiesV4(app, createScheduleContext(NOW).build());
assertEquals(returnedActivities.size(), 1);
assertEquals(returnedActivities.get(0).getActivity().getSurvey().getCreatedOn().getMillis(), 5678);
verify(activityDao).getActivityHistoryV2(any(), any(), any(), any(), any(), anyInt());
}
Aggregations