@Test public void testPostCreationFailure() throws Exception { doThrow(BaleenException.class) .when(pipelineManager) .create(anyString(), anyPiplieConfiguration(), anyInt()); String yaml = "yaml"; ServletCaller caller = new ServletCaller(); caller.setRequestUri(ROOT); caller.addParameter(NAME, yaml); caller.addParameter(YAML, yaml); caller.doPost(new PipelineManagerServlet(pipelineManager)); assertEquals(400, caller.getSentError().intValue()); }
private void create(HttpServletRequest req, HttpServletResponse resp) throws IOException { String name = req.getParameter(PARAM_NAME); String yaml = req.getParameter(PARAM_YAML); String multi = req.getParameter(PARAM_MULTIPLICITY); int multiplicity = Strings.isNullOrEmpty(multi) ? 1 : Integer.parseInt(multi); if (!parametersPresent(name, yaml) || manager.has(name)) { respondWithBadArguments(resp); return; } List<BaleenPipeline> t; try { t = manager.create(name, new YamlPipelineConfiguration(yaml), multiplicity); } catch (BaleenException e) { LOGGER.error("Unable to create", e); respondWithError( resp, HttpStatus.BAD_REQUEST_400, "Creation of pipeline(s) from yaml failed"); return; } if (multiplicity == 1) { respondWithJson(resp, t.get(0)); } else { respondWithJson(resp, t); } }
PipelineManagerServlet extends AbstractApiServlet { private void create(HttpServletRequest req, HttpServletResponse resp) throws IOException { String name = req.getParameter(PARAM_NAME); String yaml = req.getParameter(PARAM_YAML); String multi = req.getParameter(PARAM_MULTIPLICITY); int multiplicity = Strings.isNullOrEmpty(multi) ? 1 : Integer.parseInt(multi); if (!parametersPresent(name, yaml) || manager.has(name)) { respondWithBadArguments(resp); return; } List<BaleenPipeline> t; try { t = manager.create(name, new YamlPipelineConfiguration(yaml), multiplicity); } catch (BaleenException e) { LOGGER.error("Unable to create", e); respondWithError( resp, HttpStatus.BAD_REQUEST_400, "Creation of pipeline(s) from yaml failed"); return; } if (multiplicity == 1) { respondWithJson(resp, t.get(0)); } else { respondWithJson(resp, t); } } }
PipelineManagerServlet extends AbstractApiServlet { private void create(HttpServletRequest req, HttpServletResponse resp) throws IOException { String name = req.getParameter(PARAM_NAME); String yaml = req.getParameter(PARAM_YAML); String multi = req.getParameter(PARAM_MULTIPLICITY); int multiplicity = Strings.isNullOrEmpty(multi) ? 1 : Integer.parseInt(multi); if (!parametersPresent(name, yaml) || manager.has(name)) { respondWithBadArguments(resp); return; } List<BaleenPipeline> t; try { t = manager.create(name, new YamlPipelineConfiguration(yaml), multiplicity); } catch (BaleenException e) { LOGGER.error("Unable to create", e); respondWithError( resp, HttpStatus.BAD_REQUEST_400, "Creation of pipeline(s) from yaml failed"); return; } if (multiplicity == 1) { respondWithJson(resp, t.get(0)); } else { respondWithJson(resp, t); } } PipelineManagerServlet(BaleenPipelineManager manager);  PipelineManagerServlet(Logger logger, Class<?> clazz, BaleenPipelineManager manager); }
PipelineManagerServlet extends AbstractApiServlet { private void create(HttpServletRequest req, HttpServletResponse resp) throws IOException { String name = req.getParameter(PARAM_NAME); String yaml = req.getParameter(PARAM_YAML); String multi = req.getParameter(PARAM_MULTIPLICITY); int multiplicity = Strings.isNullOrEmpty(multi) ? 1 : Integer.parseInt(multi); if (!parametersPresent(name, yaml) || manager.has(name)) { respondWithBadArguments(resp); return; } List<BaleenPipeline> t; try { t = manager.create(name, new YamlPipelineConfiguration(yaml), multiplicity); } catch (BaleenException e) { LOGGER.error("Unable to create", e); respondWithError( resp, HttpStatus.BAD_REQUEST_400, "Creation of pipeline(s) from yaml failed"); return; } if (multiplicity == 1) { respondWithJson(resp, t.get(0)); } else { respondWithJson(resp, t); } } PipelineManagerServlet(BaleenPipelineManager manager);  PipelineManagerServlet(Logger logger, Class<?> clazz, BaleenPipelineManager manager); @Override WebPermission[] getPermissions(); }
PipelineManagerServlet extends AbstractApiServlet { private void create(HttpServletRequest req, HttpServletResponse resp) throws IOException { String name = req.getParameter(PARAM_NAME); String yaml = req.getParameter(PARAM_YAML); String multi = req.getParameter(PARAM_MULTIPLICITY); int multiplicity = Strings.isNullOrEmpty(multi) ? 1 : Integer.parseInt(multi); if (!parametersPresent(name, yaml) || manager.has(name)) { respondWithBadArguments(resp); return; } List<BaleenPipeline> t; try { t = manager.create(name, new YamlPipelineConfiguration(yaml), multiplicity); } catch (BaleenException e) { LOGGER.error("Unable to create", e); respondWithError( resp, HttpStatus.BAD_REQUEST_400, "Creation of pipeline(s) from yaml failed"); return; } if (multiplicity == 1) { respondWithJson(resp, t.get(0)); } else { respondWithJson(resp, t); } } PipelineManagerServlet(BaleenPipelineManager manager);  PipelineManagerServlet(Logger logger, Class<?> clazz, BaleenPipelineManager manager); @Override WebPermission[] getPermissions(); static final String PARAM_NAME; static final String PARAM_YAML; static final String PARAM_MULTIPLICITY; }