CheckpointRegularRepeatStrategy extends CheckpointRepeatStrategy { @Override public void init(final ISchedulerEntry entry, final IObject args) throws SchedulingStrategyExecutionException { try { Duration interval = Duration.parse((String) args.getValue(intervalFieldName)); entry.getState().setValue(intervalFieldName, interval.toString()); } catch (ReadValueException | ChangeValueException | InvalidArgumentException e) { throw new SchedulingStrategyExecutionException("Error occurred initializing scheduling strategy.", e); } super.init(entry, args); } CheckpointRegularRepeatStrategy(); @Override void init(final ISchedulerEntry entry, final IObject args);  }
@Test public void Should_copyArgumentsToEntryState() throws Exception { ISchedulingStrategy strategy = new CheckpointRegularRepeatStrategy(); makeEntry("{}"); strategy.init(entryMock, makeArgs("{" + "'times':2," + "'interval':'PT3H'" + "}")); verify(entryMock).save(); verify(entryMock).scheduleNext(anyLong()); assertEquals("PT3H", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "interval"))); assertEquals("PT3H", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "postRestoreDelay"))); assertEquals("PT3H", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "postCompletionDelay"))); assertEquals(2, entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "times"))); assertEquals(1, entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "remainingTimes"))); makeEntry("{}"); strategy.init(entryMock, makeArgs("{" + "'times':3," + "'interval':'PT2H'," + "'postRestoreDelay':'PT3H'," + "'postCompletionDelay':'PT4H'" + "}")); verify(entryMock).save(); verify(entryMock).scheduleNext(anyLong()); assertEquals("PT2H", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "interval"))); assertEquals("PT3H", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "postRestoreDelay"))); assertEquals("PT4H", entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "postCompletionDelay"))); assertEquals(3, entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "times"))); assertEquals(2, entryState.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "remainingTimes"))); }
@Test public void Should_notSaveEntryWith0TimesToRepeat() throws Exception { ISchedulingStrategy strategy = new CheckpointRegularRepeatStrategy(); makeEntry("{}"); strategy.init(entryMock, makeArgs("{" + "'times':0," + "'interval':'PT3H'" + "}")); verify(entryMock, never()).save(); verify(entryMock, never()).scheduleNext(anyLong()); }