use of org.sagebionetworks.bridge.models.schedules.ScheduledActivity in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityControllerTest method activityHistoryWithDefaults.
@Test
public void activityHistoryWithDefaults() throws Exception {
doReturn(createActivityResultsV2(77, null)).when(mockScheduledActivityService).getActivityHistory(eq(HEALTH_CODE), eq(ACTIVITY_GUID), eq(null), eq(null), eq(null), eq(API_DEFAULT_PAGE_SIZE));
JsonNode result = controller.getActivityHistory(ACTIVITY_GUID, null, null, null, null, null);
verify(mockScheduledActivityService).getActivityHistory(eq(HEALTH_CODE), eq(ACTIVITY_GUID), eq(null), eq(null), eq(null), eq(API_DEFAULT_PAGE_SIZE));
ForwardCursorPagedResourceList<ScheduledActivity> list = MAPPER.readValue(MAPPER.treeAsTokens(result), ACTIVITY_TYPE_REF);
assertNull(list.getItems().get(0).getHealthCode());
}
use of org.sagebionetworks.bridge.models.schedules.ScheduledActivity in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityControllerTest method getScheduledActivtiesAssemblesCorrectContext.
@SuppressWarnings("deprecation")
@Test
public void getScheduledActivtiesAssemblesCorrectContext() throws Exception {
mockEditAccount(mockAccountService, mockAccount);
DateTimeZone MSK = DateTimeZone.forOffsetHours(3);
List<ScheduledActivity> list = ImmutableList.of();
when(mockScheduledActivityService.getScheduledActivities(eq(APP), any(ScheduleContext.class))).thenReturn(list);
controller.getScheduledActivities(null, "+03:00", "3", "5");
verify(mockScheduledActivityService).getScheduledActivities(eq(APP), contextCaptor.capture());
ScheduleContext context = contextCaptor.getValue();
assertEquals(context.getInitialTimeZone(), MSK);
assertEquals(context.getCriteriaContext().getUserDataGroups(), USER_DATA_GROUPS);
assertEquals(context.getMinimumPerSchedule(), 5);
CriteriaContext critContext = context.getCriteriaContext();
assertEquals(critContext.getHealthCode(), HEALTH_CODE);
assertEquals(critContext.getLanguages(), LANGUAGES);
assertEquals(critContext.getUserStudyIds(), USER_STUDY_IDS);
assertEquals(critContext.getAppId(), TEST_APP_ID);
assertEquals(critContext.getClientInfo(), CLIENT_INFO);
verify(mockRequestInfoService).updateRequestInfo(requestInfoCaptor.capture());
RequestInfo requestInfo = requestInfoCaptor.getValue();
assertEquals(requestInfo.getUserId(), "id");
assertEquals(requestInfo.getLanguages(), LANGUAGES);
assertEquals(requestInfo.getUserDataGroups(), USER_DATA_GROUPS);
assertEquals(requestInfo.getUserStudyIds(), USER_STUDY_IDS);
assertEquals(requestInfo.getAppId(), TEST_APP_ID);
assertEquals(requestInfo.getUserAgent(), USER_AGENT);
assertEquals(requestInfo.getClientInfo(), CLIENT_INFO);
assertNotNull(requestInfo.getActivitiesAccessedOn());
assertEquals(requestInfo.getActivitiesAccessedOn().getZone(), MSK);
verify(sessionUpdateService).updateTimeZone(session, MSK);
// Verify that the account mock was updated with the anticipated time zone (however
// it's a mock as is sessionUpdateService, so this doesn't change RequestInfo, as it's
// based on changes to the session.
verify(mockAccount).setTimeZone(MSK);
}
use of org.sagebionetworks.bridge.models.schedules.ScheduledActivity in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityControllerTest method activityHistoryWithOffsetKey.
@Test
public void activityHistoryWithOffsetKey() throws Exception {
doReturn(createActivityResultsV2(77, "2000")).when(mockScheduledActivityService).getActivityHistory(eq(HEALTH_CODE), eq(ACTIVITY_GUID), any(), any(), eq("2000"), eq(77));
JsonNode result = controller.getActivityHistory(ACTIVITY_GUID, STARTS_ON.toString(), ENDS_ON.toString(), null, OFFSET_BY, PAGE_SIZE);
ForwardCursorPagedResourceList<ScheduledActivity> page = MAPPER.readValue(MAPPER.treeAsTokens(result), ACTIVITY_TYPE_REF);
assertEquals(page.getItems().size(), 1);
assertEquals(page.getNextPageOffsetKey(), "777");
assertEquals(page.getRequestParams().get("pageSize"), 77);
assertEquals(page.getRequestParams().get("offsetKey"), OFFSET_BY);
verify(mockScheduledActivityService).getActivityHistory(eq(HEALTH_CODE), eq(ACTIVITY_GUID), startsOnCaptor.capture(), endsOnCaptor.capture(), eq("2000"), eq(77));
assertTrue(STARTS_ON.isEqual(startsOnCaptor.getValue()));
assertTrue(ENDS_ON.isEqual(endsOnCaptor.getValue()));
}
use of org.sagebionetworks.bridge.models.schedules.ScheduledActivity in project BridgeServer2 by Sage-Bionetworks.
the class ParticipantControllerTest method getActivityHistoryV3.
@Test
public void getActivityHistoryV3() throws Exception {
doReturn(createActivityResultsV2("offsetKey", 15)).when(mockParticipantService).getActivityHistory(eq(app), eq(TEST_USER_ID), eq(ActivityType.SURVEY), eq("referentGuid"), any(), any(), eq("offsetKey"), eq(15));
String result = controller.getActivityHistoryV3(TEST_USER_ID, "surveys", "referentGuid", START_TIME.toString(), END_TIME.toString(), "offsetKey", "15");
JsonNode node = MAPPER.readTree(result);
assertEquals(node.get("requestParams").get("pageSize").intValue(), 15);
assertEquals(node.get("requestParams").get("offsetKey").asText(), "offsetKey");
// The fact this can be converted to a forward cursor object is ideal
ForwardCursorPagedResourceList<ScheduledActivity> page = MAPPER.readValue(node.toString(), FORWARD_CURSOR_PAGED_ACTIVITIES_REF);
assertEquals((int) page.getRequestParams().get("pageSize"), 15);
verify(mockParticipantService).getActivityHistory(eq(app), eq(TEST_USER_ID), eq(ActivityType.SURVEY), eq("referentGuid"), startTimeCaptor.capture(), endTimeCaptor.capture(), eq("offsetKey"), eq(15));
assertEquals(startTimeCaptor.getValue().toString(), START_TIME.toString());
assertEquals(endTimeCaptor.getValue().toString(), END_TIME.toString());
}
use of org.sagebionetworks.bridge.models.schedules.ScheduledActivity 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);
}
Aggregations