Search in sources :

Example 1 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class SessionValidatorTest method makeWindows.

private Session makeWindows(String time1, String exp1, String time2, String exp2, String time3, String exp3) {
    Session session = createValidSession();
    TimeWindow win1 = new TimeWindow();
    win1.setGuid(SESSION_GUID_1);
    win1.setStartTime(LocalTime.parse(time1));
    win1.setExpiration(Period.parse(exp1));
    TimeWindow win2 = new TimeWindow();
    win2.setGuid(SESSION_GUID_2);
    win2.setStartTime(LocalTime.parse(time2));
    win2.setExpiration(Period.parse(exp2));
    TimeWindow win3 = new TimeWindow();
    win3.setGuid(SESSION_GUID_3);
    win3.setStartTime(LocalTime.parse(time3));
    win3.setExpiration(Period.parse(exp3));
    session.setTimeWindows(ImmutableList.of(win1, win2, win3));
    return session;
}
Also used : TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session) SessionTest.createValidSession(org.sagebionetworks.bridge.models.schedules2.SessionTest.createValidSession)

Example 2 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class SessionValidatorTest method timeWindows_nullScheduleDurationPasses.

@Test
public void timeWindows_nullScheduleDurationPasses() {
    Session session = createValidSession();
    TimeWindow timeWindow = new TimeWindow();
    timeWindow.setGuid(SESSION_GUID_1);
    timeWindow.setStartTime(LocalTime.parse("08:00"));
    timeWindow.setExpiration(Period.parse("P4W"));
    session.setTimeWindows(ImmutableList.of(timeWindow));
    session.setInterval(Period.parse("P4W"));
    session.setDelay(Period.parse("P4WT1H"));
    SessionValidator validator = new SessionValidator(null, ImmutableSet.of("burst1"));
    Validate.entityThrowingException(validator, session);
}
Also used : TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session) SessionTest.createValidSession(org.sagebionetworks.bridge.models.schedules2.SessionTest.createValidSession) SessionTest(org.sagebionetworks.bridge.models.schedules2.SessionTest) Test(org.testng.annotations.Test)

Example 3 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class ScheduledSessionTest method copyWithoutAssessments.

@Test
public void copyWithoutAssessments() {
    Session session = new Session();
    session.setGuid(SESSION_GUID_1);
    session.setStartEventIds(ImmutableList.of("enrollment"));
    TimeWindow window = new TimeWindow();
    window.setGuid(SESSION_WINDOW_GUID_1);
    ScheduledAssessment asmt = new ScheduledAssessment.Builder().withRefKey("ref").withInstanceGuid("instanceGuid").build();
    ScheduledSession.Builder builder = new ScheduledSession.Builder().withSession(session).withTimeWindow(window).withStartEventId("timeline_retrieved").withInstanceGuid("instanceGuid").withStartDay(10).withEndDay(13).withDelayTime(Period.parse("PT3H")).withStartTime(LocalTime.parse("17:00")).withExpiration(Period.parse("PT30M")).withPersistent(true).withScheduledAssessment(asmt);
    ScheduledSession.Builder copy = builder.build().toBuilder();
    ScheduledSession schSession = copy.build();
    assertEquals(schSession.getRefGuid(), SESSION_GUID_1);
    assertEquals(schSession.getInstanceGuid(), "instanceGuid");
    assertEquals(schSession.getStartEventId(), "timeline_retrieved");
    assertEquals(schSession.getStartDay(), Integer.valueOf(10));
    assertEquals(schSession.getEndDay(), Integer.valueOf(13));
    assertEquals(schSession.getStartTime(), LocalTime.parse("17:00"));
    assertEquals(schSession.getDelayTime(), Period.parse("PT3H"));
    assertEquals(schSession.getExpiration(), Period.parse("PT30M"));
    assertEquals(schSession.getTimeWindow(), window);
    assertTrue(schSession.isPersistent());
    assertTrue(schSession.getAssessments().isEmpty());
    assertNull(schSession.getStudyBurstId());
    assertNull(schSession.getStudyBurstNum());
}
Also used : TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 4 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class ScheduledSessionTest method serializationHandlesNulls.

@Test
public void serializationHandlesNulls() {
    ScheduledSession schSession = new ScheduledSession.Builder().withSession(new Session()).withTimeWindow(new TimeWindow()).build();
    JsonNode node = BridgeObjectMapper.get().valueToTree(schSession);
    assertEquals(node.size(), 2);
    assertNull(node.get("startDay"));
    assertNull(node.get("endDay"));
    assertEquals(node.get("assessments").size(), 0);
    assertEquals(node.get("type").textValue(), "ScheduledSession");
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Example 5 with TimeWindow

use of com.google.cloud.asset.v1.TimeWindow in project BridgeServer2 by Sage-Bionetworks.

the class ScheduledSessionTest method reportsStudyBurstInformation.

@Test
public void reportsStudyBurstInformation() {
    Session session = new Session();
    session.setGuid(SESSION_GUID_1);
    TimeWindow window = new TimeWindow();
    window.setGuid(SESSION_WINDOW_GUID_1);
    ScheduledSession schSession = new ScheduledSession.Builder().withSession(session).withTimeWindow(window).withStartEventId("study_burst:foo:01").build();
    assertEquals(schSession.getStudyBurstId(), "foo");
    assertEquals(schSession.getStudyBurstNum(), Integer.valueOf(1));
}
Also used : TimeWindow(org.sagebionetworks.bridge.models.schedules2.TimeWindow) Session(org.sagebionetworks.bridge.models.schedules2.Session) Test(org.testng.annotations.Test)

Aggregations

TimeWindow (org.sagebionetworks.bridge.models.schedules2.TimeWindow)23 Session (org.sagebionetworks.bridge.models.schedules2.Session)21 Test (org.testng.annotations.Test)13 Schedule2 (org.sagebionetworks.bridge.models.schedules2.Schedule2)8 SessionTest (org.sagebionetworks.bridge.models.schedules2.SessionTest)6 SessionTest.createValidSession (org.sagebionetworks.bridge.models.schedules2.SessionTest.createValidSession)6 AssessmentReference (org.sagebionetworks.bridge.models.schedules2.AssessmentReference)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 LocalTime (org.joda.time.LocalTime)2 RequestContext (org.sagebionetworks.bridge.RequestContext)2 Label (org.sagebionetworks.bridge.models.Label)2 StudyBurst (org.sagebionetworks.bridge.models.schedules2.StudyBurst)2 Study (org.sagebionetworks.bridge.models.studies.Study)2 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)1 BatchGetAssetsHistoryRequest (com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest)1 BatchGetAssetsHistoryResponse (com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse)1 ContentType (com.google.cloud.asset.v1.ContentType)1