InAppAutomation extends AirshipComponent implements InAppAutomationScheduler { private void executeActions(@NonNull Schedule<? extends ScheduleData> schedule, @NonNull Actions actions, AutomationDriver.ExecutionCallback callback) { Bundle metadata = new Bundle(); metadata.putString(ActionArguments.ACTION_SCHEDULE_ID_METADATA, schedule.getId()); ActionCallback actionCallback = new ActionCallback(callback, actions.getActionsMap().size()); for (Map.Entry<String, JsonValue> entry : actions.getActionsMap().entrySet()) { actionRunRequestFactory.createActionRequest(entry.getKey()) .setValue(entry.getValue()) .setSituation(Action.SITUATION_AUTOMATION) .setMetadata(metadata) .run(Looper.getMainLooper(), actionCallback); } } @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  InAppAutomation(@NonNull Context context,
                           @NonNull PreferenceDataStore preferenceDataStore,
                           @NonNull AirshipRuntimeConfig runtimeConfig,
                           @NonNull Analytics analytics,
                           @NonNull RemoteData remoteData,
                           @NonNull AirshipChannel airshipChannel,
                           @NonNull NamedUser namedUser); @VisibleForTesting  InAppAutomation(@NonNull Context context,
                    @NonNull PreferenceDataStore preferenceDataStore,
                    @NonNull AutomationEngine engine,
                    @NonNull AirshipChannel airshipChannel,
                    @NonNull AudienceManager audienceManager,
                    @NonNull InAppRemoteDataObserver observer,
                    @NonNull InAppMessageManager inAppMessageManager,
                    @NonNull RetryingExecutor retryingExecutor,
                    @NonNull ActionRunRequestFactory actionRunRequestFactory,
                    @NonNull DeferredScheduleClient deferredScheduleClient); @NonNull static InAppAutomation shared(); @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @AirshipComponentGroups.Group int getComponentGroup(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @Override void onAirshipReady(@NonNull UAirship airship); @Override void onNewConfig(@Nullable JsonMap configValue); InAppMessageManager getInAppMessageManager(); @NonNull @Override PendingResult<Boolean> schedule(@NonNull List<Schedule<? extends ScheduleData>> schedules); @NonNull @Override PendingResult<Boolean> schedule(@NonNull Schedule<? extends ScheduleData> schedule); @NonNull PendingResult<Boolean> cancelSchedule(@NonNull String scheduleId); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) PendingResult<Boolean> cancelSchedules(@NonNull @Schedule.Type String type); @NonNull PendingResult<Boolean> cancelScheduleGroup(@NonNull String group); @NonNull @Override PendingResult<Collection<Schedule<Actions>>> getActionScheduleGroup(@NonNull final String group); @NonNull @Override PendingResult<Schedule<Actions>> getActionSchedule(@NonNull String scheduleId); @NonNull @Override PendingResult<Collection<Schedule<Actions>>> getActionSchedules(); @NonNull @Override PendingResult<Collection<Schedule<InAppMessage>>> getMessageScheduleGroup(@NonNull String group); @NonNull @Override PendingResult<Schedule<InAppMessage>> getMessageSchedule(@NonNull String scheduleId); @NonNull @Override PendingResult<Collection<Schedule<InAppMessage>>> getMessageSchedules(); @NonNull @Override @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) PendingResult<Collection<Schedule<? extends ScheduleData>>> getSchedules(); @NonNull @Override PendingResult<Boolean> editSchedule(@NonNull String scheduleId, @NonNull ScheduleEdits<? extends ScheduleData> edits); void setPaused(boolean paused); boolean isPaused(); void setEnabled(boolean enabled); boolean isEnabled();  }
@Test public void testExecuteActions() { JsonMap actionsMap = JsonMap.newBuilder() .put("cool", "story") .build(); final Schedule schedule = Schedule.newBuilder(new Actions(actionsMap)) .addTrigger(Triggers.newAppInitTriggerBuilder().setGoal(1).build()) .build(); StubbedActionRunRequest stubbedActionRunRequest = new StubbedActionRunRequest() { @Override public void run(Looper looper, ActionCompletionCallback callback) { callback.onFinish(new ActionArguments(Action.SITUATION_AUTOMATION, ActionValue.wrap("cool"), new Bundle()), ActionResult.newEmptyResult()); } }; stubbedActionRunRequest = spy(stubbedActionRunRequest); when(mockActionRunRequestFactory.createActionRequest("cool")).thenReturn(stubbedActionRunRequest); AutomationDriver.ExecutionCallback callback = mock(AutomationDriver.ExecutionCallback.class); driver.onExecuteTriggeredSchedule(schedule, callback); verify(stubbedActionRunRequest).setValue(JsonValue.wrapOpt("story")); verify(stubbedActionRunRequest).setSituation(Action.SITUATION_AUTOMATION); verify(stubbedActionRunRequest).setMetadata(ArgumentMatchers.argThat(new ArgumentMatcher<Bundle>() { @Override public boolean matches(Bundle argument) { return argument.get(ActionArguments.ACTION_SCHEDULE_ID_METADATA).equals(schedule.getId()); } })); }