Search in sources :

Example 1 with ScheduledActivity

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());
}
Also used : ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.testng.annotations.Test)

Example 2 with ScheduledActivity

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);
}
Also used : ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) RequestInfo(org.sagebionetworks.bridge.models.RequestInfo) ScheduleContext(org.sagebionetworks.bridge.models.schedules.ScheduleContext) DateTimeZone(org.joda.time.DateTimeZone) CriteriaContext(org.sagebionetworks.bridge.models.CriteriaContext) Test(org.testng.annotations.Test)

Example 3 with ScheduledActivity

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()));
}
Also used : ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.testng.annotations.Test)

Example 4 with ScheduledActivity

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());
}
Also used : ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.testng.annotations.Test)

Example 5 with ScheduledActivity

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);
}
Also used : ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) ScheduledActivity(org.sagebionetworks.bridge.models.schedules.ScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity) DynamoScheduledActivity(org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity)

Aggregations

ScheduledActivity (org.sagebionetworks.bridge.models.schedules.ScheduledActivity)101 Test (org.testng.annotations.Test)69 DynamoScheduledActivity (org.sagebionetworks.bridge.dynamodb.DynamoScheduledActivity)55 ScheduleContext (org.sagebionetworks.bridge.models.schedules.ScheduleContext)30 DateTime (org.joda.time.DateTime)24 Activity (org.sagebionetworks.bridge.models.schedules.Activity)23 SchedulePlan (org.sagebionetworks.bridge.models.schedules.SchedulePlan)20 DynamoSchedulePlan (org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan)18 LocalDateTime (org.joda.time.LocalDateTime)16 CompoundActivity (org.sagebionetworks.bridge.models.schedules.CompoundActivity)16 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)13 SchemaReference (org.sagebionetworks.bridge.models.schedules.SchemaReference)11 Schedule (org.sagebionetworks.bridge.models.schedules.Schedule)10 SurveyReference (org.sagebionetworks.bridge.models.schedules.SurveyReference)9 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)7 ArrayList (java.util.ArrayList)7 Mockito.anyString (org.mockito.Mockito.anyString)6 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)5