ExecutionDAOFacade { public Workflow getWorkflowById(String workflowId, boolean includeTasks) { Workflow workflow = executionDAO.getWorkflow(workflowId, includeTasks); if (workflow == null) { LOGGER.debug("Workflow {} not found in executionDAO, checking indexDAO", workflowId); String json = indexDAO.get(workflowId, RAW_JSON_FIELD); if (json == null) { String errorMsg = String.format("No such workflow found by id: %s", workflowId); LOGGER.error(errorMsg); throw new ApplicationException(ApplicationException.Code.NOT_FOUND, errorMsg); } try { workflow = objectMapper.readValue(json, Workflow.class); if (!includeTasks) { workflow.getTasks().clear(); } } catch (IOException e) { String errorMsg = String.format("Error reading workflow: %s", workflowId); LOGGER.error(errorMsg); throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, errorMsg, e); } } return workflow; } @Inject  ExecutionDAOFacade(ExecutionDAO executionDAO, QueueDAO queueDAO, IndexDAO indexDAO,
        RateLimitingDAO rateLimitingDao, PollDataDAO pollDataDAO, ObjectMapper objectMapper, Configuration config); @PreDestroy void shutdownExecutorService(); Workflow getWorkflowById(String workflowId, boolean includeTasks); List<Workflow> getWorkflowsByCorrelationId(String workflowName, String correlationId, boolean includeTasks); List<Workflow> getWorkflowsByName(String workflowName, Long startTime, Long endTime); List<Workflow> getPendingWorkflowsByName(String workflowName, int version); List<String> getRunningWorkflowIds(String workflowName, int version); long getPendingWorkflowCount(String workflowName); String createWorkflow(Workflow workflow); String updateWorkflow(Workflow workflow); void removeFromPendingWorkflow(String workflowType, String workflowId); void removeWorkflow(String workflowId, boolean archiveWorkflow); void removeWorkflowWithExpiry(String workflowId, boolean archiveWorkflow, int ttlSeconds); void resetWorkflow(String workflowId); List<Task> createTasks(List<Task> tasks); List<Task> getTasksForWorkflow(String workflowId); Task getTaskById(String taskId); List<Task> getTasksByName(String taskName, String startKey, int count); List<Task> getPendingTasksForTaskType(String taskType); long getInProgressTaskCount(String taskDefName); void updateTask(Task task); void updateTasks(List<Task> tasks); void removeTask(String taskId); List<PollData> getTaskPollData(String taskName); List<PollData> getAllPollData(); PollData getTaskPollDataByDomain(String taskName, String domain); void updateTaskLastPoll(String taskName, String domain, String workerId); boolean addEventExecution(EventExecution eventExecution); void updateEventExecution(EventExecution eventExecution); void removeEventExecution(EventExecution eventExecution); boolean exceedsInProgressLimit(Task task); boolean exceedsRateLimitPerFrequency(Task task, TaskDef taskDef); void addTaskExecLog(List<TaskExecLog> logs); void addMessage(String queue, Message message); SearchResult<String> searchWorkflows(String query, String freeText, int start, int count, List<String> sort); SearchResult<String> searchTasks(String query, String freeText, int start, int count, List<String> sort); List<TaskExecLog> getTaskExecutionLogs(String taskId);  }
@Test public void tesGetWorkflowById() throws Exception { when(executionDAO.getWorkflow(any(), anyBoolean())).thenReturn(new Workflow()); Workflow workflow = executionDAOFacade.getWorkflowById("workflowId", true); assertNotNull(workflow); verify(indexDAO, never()).get(any(), any()); when(executionDAO.getWorkflow(any(), anyBoolean())).thenReturn(null); InputStream stream = ExecutionDAOFacadeTest.class.getResourceAsStream("/test.json"); byte[] bytes = IOUtils.toByteArray(stream); String jsonString = new String(bytes); when(indexDAO.get(any(), any())).thenReturn(jsonString); workflow = executionDAOFacade.getWorkflowById("workflowId", true); assertNotNull(workflow); verify(indexDAO, times(1)).get(any(), any()); }