use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.
the class TestUtils method getSchedulePlans.
public static List<SchedulePlan> getSchedulePlans(String appId) {
List<SchedulePlan> plans = Lists.newArrayListWithCapacity(3);
SchedulePlan plan = new DynamoSchedulePlan();
plan.setGuid("DDD");
plan.setStrategy(getStrategy("P3D", getActivity1()));
plan.setAppId(appId);
plans.add(plan);
plan = new DynamoSchedulePlan();
plan.setGuid("BBB");
plan.setStrategy(getStrategy("P1D", getActivity2()));
plan.setAppId(appId);
plans.add(plan);
plan = new DynamoSchedulePlan();
plan.setGuid("CCC");
plan.setStrategy(getStrategy("P2D", getActivity3()));
plan.setAppId(appId);
plans.add(plan);
return plans;
}
use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.
the class ScheduleControllerTest method getSchedulesV3AdjustsScheduleTypes.
@SuppressWarnings("deprecation")
@Test
public void getSchedulesV3AdjustsScheduleTypes() throws Exception {
List<SchedulePlan> plans = Lists.newArrayList();
Schedule schedule = new Schedule();
schedule.addActivity(new Activity.Builder().withLabel("Label").withTask("foo").build());
schedule.setScheduleType(ScheduleType.RECURRING);
schedule.setCronTrigger("0 0 12 1/1 * ? *");
SimpleScheduleStrategy strategy = new SimpleScheduleStrategy();
strategy.setSchedule(schedule);
SchedulePlan plan = new DynamoSchedulePlan();
plan.setLabel("Label");
plan.setGuid("BBB");
plan.setAppId(TEST_APP_ID);
plan.setStrategy(strategy);
plans.add(plan);
schedule = new Schedule();
schedule.addActivity(new Activity.Builder().withLabel("Label").withTask("foo").build());
schedule.setScheduleType(ScheduleType.RECURRING);
schedule.setCronTrigger("0 0 12 1/1 * ? *");
strategy = new SimpleScheduleStrategy();
strategy.setSchedule(schedule);
plan = new DynamoSchedulePlan();
plan.setLabel("Label");
plan.setGuid("BBB");
plan.setAppId(TEST_APP_ID);
plan.setStrategy(strategy);
plans.add(plan);
when(mockSchedulePlanService.getSchedulePlans(any(), any(), anyBoolean())).thenReturn(plans);
controller.setSchedulePlanService(mockSchedulePlanService);
String result = controller.getSchedulesV3();
JsonNode node = BridgeObjectMapper.get().readTree(result);
ArrayNode array = (ArrayNode) node.get("items");
// Verify that both objects have been adjusted so that despite the fact that they are
// marked as persistent, they are also marked as recurring.
ObjectNode schedule1 = (ObjectNode) array.get(0);
assertTrue(schedule1.get("persistent").asBoolean());
assertEquals(schedule1.get("scheduleType").asText(), "recurring");
ObjectNode schedule2 = (ObjectNode) array.get(1);
assertTrue(schedule2.get("persistent").asBoolean());
assertEquals(schedule2.get("scheduleType").asText(), "recurring");
}
use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.
the class ScheduleControllerTest method before.
@BeforeMethod
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
appId = TestUtils.randomName(ScheduleControllerTest.class);
ClientInfo clientInfo = ClientInfo.fromUserAgentCache("app name/9");
List<SchedulePlan> plans = TestUtils.getSchedulePlans(appId);
// Add a plan that will returns null for a schedule, this is not included in the final list.
// This is now possible and should not cause an error or a gap in the returned array.
SchedulePlan plan = new DynamoSchedulePlan();
plan.setStrategy(new ScheduleStrategy() {
@Override
public Schedule getScheduleForUser(SchedulePlan plan, ScheduleContext context) {
return null;
}
@Override
public void validate(Set<String> dataGroups, Set<String> studyIds, Set<String> taskIdentifiers, Errors errors) {
}
@Override
public List<Schedule> getAllPossibleSchedules() {
return ImmutableList.of();
}
});
plans.add(plan);
when(mockSchedulePlanService.getSchedulePlans(clientInfo, appId, false)).thenReturn(plans);
UserSession session = new UserSession();
session.setAppId(appId);
doReturn(session).when(controller).getAuthenticatedAndConsentedSession();
RequestContext.set(new RequestContext.Builder().withCallerClientInfo(clientInfo).build());
doReturn(mockRequest).when(controller).request();
doReturn(mockResponse).when(controller).response();
}
use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityServiceTest method firstTimeStampFor.
private String firstTimeStampFor(int initialTZOffset, int requestTZOffset, Schedule schedule) {
// Tests calling this method set up different mocked environment from other tests.
reset(schedulePlanService);
reset(activityEventService);
DateTime enrollment = DateTime.parse("2017-02-20T01:00:00.000Z");
DateTimeZone initialTimeZone = DateTimeZone.forOffsetHours(initialTZOffset);
DateTimeZone requestTimeZone = DateTimeZone.forOffsetHours(requestTZOffset);
DateTime startsOn = DateTime.parse("2017-04-06T17:10:10.000Z").withZone(requestTimeZone);
Map<String, DateTime> eventMap = Maps.newHashMap();
eventMap.put("enrollment", enrollment);
when(activityEventService.getActivityEventMap(TEST_APP_ID, "healthCode")).thenReturn(eventMap);
SchedulePlan plan = new DynamoSchedulePlan();
plan.setGuid("BBB");
SimpleScheduleStrategy strategy = new SimpleScheduleStrategy();
strategy.setSchedule(schedule);
plan.setStrategy(strategy);
when(schedulePlanService.getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, TEST_APP_ID, false)).thenReturn(Lists.newArrayList(plan));
ScheduleContext context = new ScheduleContext.Builder().withAppId(TEST_APP_ID).withUserId("userId").withStartsOn(startsOn).withAccountCreatedOn(enrollment).withInitialTimeZone(initialTimeZone).withEndsOn(startsOn.plusDays(4).withZone(requestTimeZone)).withHealthCode("healthCode").build();
List<ScheduledActivity> activities = service.getScheduledActivities(app, context);
verify(activityEventService).getActivityEventMap(TEST_APP_ID, "healthCode");
verify(schedulePlanService).getSchedulePlans(ClientInfo.UNKNOWN_CLIENT, TEST_APP_ID, false);
return activities.get(0).getScheduledOn().toString();
}
use of org.sagebionetworks.bridge.dynamodb.DynamoSchedulePlan in project BridgeServer2 by Sage-Bionetworks.
the class ScheduledActivityServiceTest method schedulePlan.
private SchedulePlan schedulePlan(Activity activity) {
Schedule schedule = new Schedule();
schedule.setScheduleType(ScheduleType.RECURRING);
schedule.setInterval(Period.parse("P1D"));
schedule.addActivity(activity);
schedule.setExpires(Period.parse("P1D"));
schedule.addTimes("10:00");
schedule.setLabel("Test label for the user");
SimpleScheduleStrategy strategy = new SimpleScheduleStrategy();
strategy.setSchedule(schedule);
DynamoSchedulePlan plan = new DynamoSchedulePlan();
plan.setGuid(BridgeUtils.generateGuid());
plan.setModifiedOn(DateUtils.getCurrentMillisFromEpoch());
plan.setAppId(TEST_APP_ID);
plan.setStrategy(strategy);
return plan;
}
Aggregations