private void verifyEvalUpdateFromAwaitingToClosed(int timeZone) throws Exception { EvaluationAttributes eval = getTypicalDataBundle().evaluations.get("evaluation1InCourse1"); int milliSecondsPerMinute = 60 * 1000; // first, make it AWAITING eval.timeZone = timeZone; eval.gracePeriod = 15; eval.startTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone(milliSecondsPerMinute, timeZone); eval.endTime = TimeHelper.getDateOffsetToCurrentTime(2); eval.published = false; eval.activated = false; assertEquals(EvalStatus.AWAITING, eval.getStatus()); // then, make it CLOSED eval.startTime = TimeHelper.getDateOffsetToCurrentTime(-2); eval.endTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone( -milliSecondsPerMinute * (eval.gracePeriod + 1), timeZone); eval.setDerivedAttributes(); // check if derived attributes are set correctly assertEquals(true, eval.activated); assertEquals(false, eval.published); assertEquals(EvalStatus.CLOSED, eval.getStatus()); }
@Test public void testCalculateEvalStatus() throws InterruptedException { double timeZone; int gracePeriod; EvaluationAttributes evaluation = new EvaluationAttributes(); int safetyMargin = 1000; // we use this to compensate for test execution time ______TS("in the awaiting period"); evaluation.startTime = TimeHelper.getMsOffsetToCurrentTime(safetyMargin); evaluation.endTime = TimeHelper.getDateOffsetToCurrentTime(1); timeZone = 0.0; evaluation.timeZone = timeZone; gracePeriod = 0; ; evaluation.gracePeriod = gracePeriod; evaluation.published = false; AssertJUnit.assertEquals(EvalStatus.AWAITING, evaluation.getStatus()); ______TS("in the middle of open period"); evaluation.startTime = TimeHelper.getDateOffsetToCurrentTime(-1); AssertJUnit.assertEquals(EvalStatus.OPEN, evaluation.getStatus()); ______TS("just before grace period expires"); gracePeriod = 5; int gracePeriodInMs = gracePeriod * 60 * 1000; evaluation.gracePeriod = gracePeriod; evaluation.endTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone(gracePeriodInMs - safetyMargin, timeZone); timeZone = 0.0; evaluation.timeZone = timeZone; AssertJUnit.assertEquals(EvalStatus.OPEN, evaluation.getStatus()); ______TS("just after the grace period expired"); gracePeriod = 5; gracePeriodInMs = gracePeriod * 60 * 1000; evaluation.gracePeriod = gracePeriod; timeZone = 0.0; evaluation.timeZone = timeZone; evaluation.endTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone( -gracePeriodInMs - safetyMargin, timeZone); AssertJUnit.assertEquals(EvalStatus.CLOSED, evaluation.getStatus()); ______TS("already published"); evaluation.published = true; AssertJUnit.assertEquals(EvalStatus.PUBLISHED, evaluation.getStatus()); evaluation.published = false; ______TS("checking for user in different time zone"); // do similar testing for +1.0 time zone timeZone = 1.0; evaluation.timeZone = timeZone; // in AWAITING period evaluation.startTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone(safetyMargin, timeZone); evaluation.endTime = TimeHelper.getDateOffsetToCurrentTime(1); AssertJUnit.assertEquals(EvalStatus.AWAITING, evaluation.getStatus()); // in OPEN period evaluation.startTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone(-safetyMargin, timeZone); AssertJUnit.assertEquals(EvalStatus.OPEN, evaluation.getStatus()); // TODO: just before grace period expired gracePeriod = 5; evaluation.gracePeriod = gracePeriod; timeZone = 1.0; evaluation.timeZone = timeZone; evaluation.startTime = TimeHelper.getDateOffsetToCurrentTime(-2); evaluation.endTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone( -gracePeriodInMs + safetyMargin, timeZone); AssertJUnit.assertEquals(EvalStatus.OPEN, evaluation.getStatus()); // just after grace period gracePeriod = 5; evaluation.gracePeriod = gracePeriod; timeZone = 1.0; evaluation.timeZone = timeZone; evaluation.startTime = TimeHelper.getDateOffsetToCurrentTime(-2); evaluation.endTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone( -gracePeriodInMs - safetyMargin, timeZone); AssertJUnit.assertEquals(EvalStatus.CLOSED, evaluation.getStatus()); // already PUBLISHED evaluation.published = true; AssertJUnit.assertEquals(EvalStatus.PUBLISHED, evaluation.getStatus()); }
@Test public void testIsReady() throws InvalidParametersException { // Create evaluation object to use as the test object Calendar start = Calendar.getInstance(TimeZone.getTimeZone("UTC")); Calendar end = Calendar.getInstance(TimeZone.getTimeZone("UTC")); EvaluationAttributes e = new EvaluationAttributes( new Evaluation( "course1", "evalution 1", new Text("instructions"), true, start.getTime(), end.getTime(), 0.0, 0)); int oneSecInMilliSeconds = 1 * 1000; double timeZone = 0.0; ______TS("ready, just after start time"); // start time set to 1 sec before current time e.startTime = TimeHelper.getMsOffsetToCurrentTime(-oneSecInMilliSeconds); e.endTime = TimeHelper.getDateOffsetToCurrentTime(1); e.activated = false; e.timeZone = 0.0; assertEquals(true, e.isReadyToActivate()); // negative time zone, starting just before current time timeZone = -2.0; e.startTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone(-oneSecInMilliSeconds, timeZone); e.endTime = TimeHelper.getDateOffsetToCurrentTime(1); e.activated = false; e.timeZone = timeZone; assertEquals(true, e.isReadyToActivate()); // positive time zone, starting just before current time timeZone = 2.0; e.startTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone(-oneSecInMilliSeconds, timeZone); e.endTime = TimeHelper.getDateOffsetToCurrentTime(1); e.activated = false; e.timeZone = timeZone; assertEquals(true, e.isReadyToActivate()); ______TS("not ready, just before start time"); // start time set to 1 sec after current time oneSecInMilliSeconds = 1 * 1000; e.startTime = TimeHelper.getMsOffsetToCurrentTime(+oneSecInMilliSeconds); e.endTime = TimeHelper.getDateOffsetToCurrentTime(1); e.activated = false; e.timeZone = 0.0; assertEquals(false, e.isReadyToActivate()); // negative time zone, starting just after current time timeZone = -2.0; e.startTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone(oneSecInMilliSeconds, timeZone); e.endTime = TimeHelper.getDateOffsetToCurrentTime(1); e.activated = false; e.timeZone = timeZone; assertEquals(false, e.isReadyToActivate()); // positive time zone, starting just after current time timeZone = 2.0; e.startTime = TimeHelper.getMsOffsetToCurrentTimeInUserTimeZone(oneSecInMilliSeconds, timeZone); e.endTime = TimeHelper.getDateOffsetToCurrentTime(1); e.activated = false; e.timeZone = timeZone; assertEquals(false, e.isReadyToActivate()); ______TS("not ready, already activated"); // start time set to 1 sec before current time e.startTime = TimeHelper.getMsOffsetToCurrentTime(-oneSecInMilliSeconds); e.endTime = TimeHelper.getDateOffsetToCurrentTime(1); e.activated = true; e.timeZone = 0.0; assertEquals(false, e.isReadyToActivate()); // start time set to 1 sec after current time e.startTime = TimeHelper.getMsOffsetToCurrentTime(+oneSecInMilliSeconds); e.endTime = TimeHelper.getDateOffsetToCurrentTime(1); e.activated = true; e.timeZone = 0.0; assertEquals(false, e.isReadyToActivate()); }