ExecutorServlet extends LoginAbstractAzkabanServlet { @Override protected void handlePost(final HttpServletRequest req, final HttpServletResponse resp, final Session session) throws ServletException, IOException { if (hasParam(req, "ajax")) { handleAJAXAction(req, resp, session); } } ExecutorServlet(); @Override void init(final ServletConfig config);  }
@Test public void postAjaxExecuteFlowWithSlaSettings() throws Exception { mockTestProjectAndFlow(); mockSubmitExecution(); this.req.addParameter("ajax", "executeFlow"); this.req.addParameter("project", "testProject"); this.req.addParameter("flow", "testFlow"); this.req.addParameter("slaSettings[1]", ",FINISH,2:30,true,false"); this.req.addParameter("slaEmails", "sla1@example.com,sla2@example.com"); this.executorServlet.handlePost(this.req, this.res, this.session); assertEquals(200, this.res.getStatus()); final JsonNode json = this.res.getResponseJson(); assertEquals("testProject", json.path("project").asText()); assertEquals("testFlow", json.path("flow").asText()); assertEquals("Submitted (mocked)", json.path("message").asText()); assertEquals(99, json.path("execid").asInt()); final List<SlaOption> slaOptions = this.exFlow.getValue().getExecutionOptions().getSlaOptions(); final List<SlaOption> expected = Arrays.asList(new SlaOption(SlaType.FLOW_FINISH, "testFlow", "", Duration.ofMinutes(150), ImmutableSet.of(SlaAction.ALERT), ImmutableList.of("sla1@example.com", "sla2@example.com"))); Assert.assertEquals(expected, slaOptions); }
@Test public void postAjaxExecuteFlowWithInvalidSlaSettings() throws Exception { mockTestProjectAndFlow(); mockSubmitExecution(); this.req.addParameter("ajax", "executeFlow"); this.req.addParameter("project", "testProject"); this.req.addParameter("flow", "testFlow"); this.req.addParameter("slaSettings[1]", "broken-syntax-for-sla"); this.executorServlet.handlePost(this.req, this.res, this.session); assertEquals(200, this.res.getStatus()); assertEquals("Error parsing flow options: Error parsing SLA setting 'broken-syntax-for-sla': " + "java.lang.ArrayIndexOutOfBoundsException: 1", this.res.getResponseJson().path("error").asText()); }
@Test public void postAjaxExecuteFlowWithMissingProjectParameter() throws Exception { this.req.addParameter("ajax", "executeFlow"); try { this.executorServlet.handlePost(this.req, this.res, this.session); fail("Expected exception was not thrown"); } catch (final ServletException e) { assertEquals("Missing required parameter 'project'.", e.getMessage()); } }
@Test public void postAjaxFlowInfoErrorFetching() throws Exception { this.req.addParameter("ajax", "flowInfo"); this.req.addParameter("execid", "123"); this.executorServlet.handlePost(this.req, this.res, this.session); assertEquals(200, this.res.getStatus()); assertEquals("Cannot find execution '123'", this.res.getResponseJson().path("error").asText()); }