ScheduleAction extends Action { @NonNull @Override public ActionResult perform(@NonNull ActionArguments arguments) { InAppAutomation automation; try { automation = actionAutomationCallable.call(); } catch (Exception e) { return ActionResult.newErrorResult(e); } try { Schedule<Actions> schedule = parseSchedule(arguments.getValue().toJsonValue()); Boolean result = automation.schedule(schedule).get(); return (result != null && result) ? ActionResult.newResult(ActionValue.wrap(schedule.getId())) : ActionResult.newEmptyResult(); } catch (JsonException | InterruptedException | ExecutionException e) { return ActionResult.newErrorResult(e); } } ScheduleAction(); @VisibleForTesting  ScheduleAction(@NonNull Callable<InAppAutomation> actionAutomationCallable); @Override boolean acceptsArguments(@NonNull ActionArguments arguments); @NonNull @Override ActionResult perform(@NonNull ActionArguments arguments); @NonNull
    static final String DEFAULT_REGISTRY_NAME; @NonNull
    static final String DEFAULT_REGISTRY_SHORT_NAME; }
@Test public void testPerform() throws JsonException { PendingResult<Boolean> pendingResult = new PendingResult<>(); pendingResult.setResult(true); when(automation.schedule(any(Schedule.class))).thenReturn(pendingResult); ActionResult result = action.perform(createArgs(Action.SITUATION_MANUAL_INVOCATION, scheduleJson)); assertNotNull(result.getValue().getString()); }
@Test public void testPerformInvalidJson() throws JsonException { ActionResult result = action.perform(createArgs(Action.SITUATION_MANUAL_INVOCATION, JsonMap.EMPTY_MAP)); assertNotNull(result.getException()); assertEquals(ActionResult.STATUS_EXECUTION_ERROR, result.getStatus()); }