IsXmlIfPipe extends AbstractPipe { @Override public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException { String forward = ""; if (message==null) { if (isElseForwardOnEmptyInput()) { forward = elseForwardName; } else { forward = thenForwardName; } } else { String sInput; try { sInput = message.asString(); } catch (IOException e) { throw new PipeRunException(this, getLogPrefix(session)+"cannot open stream", e); } if (StringUtils.isEmpty(sInput)) { if (isElseForwardOnEmptyInput()) { forward = elseForwardName; } else { forward = thenForwardName; } } else { String firstChar = sInput.replaceAll("^\\s+", "").substring(0, 1); if (firstChar.equals("<")) { forward = thenForwardName; } else { forward = elseForwardName; } } } log.debug(getLogPrefix(session) + "determined forward [" + forward + "]"); PipeForward pipeForward = findForward(forward); if (pipeForward == null) { throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]"); } log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]"); return new PipeRunResult(pipeForward, message); }  @Override PipeRunResult doPipe(Message message, IPipeLineSession session); @IbisDoc({"forward returned when <code>'true'</code>", "then"}) void setThenForwardName(String thenForwardName); String getThenForwardName(); @IbisDoc({"forward returned when 'false'", "else"}) void setElseForwardName(String elseForwardName); String getElseForwardName(); boolean isElseForwardOnEmptyInput(); @IbisDoc({"return elseforward when input is empty (or thenforward)", "true"}) void setElseForwardOnEmptyInput(boolean b);  }
@Test public void validInputOnElsePipeTest() throws PipeRunException, ConfigurationException, PipeStartException{ pipe.configure(); pipe.start(); PipeRunResult prr = doPipe(pipe, "test", session); Assert.assertEquals(pipeForwardElse, prr.getPipeForward().getName()); }
@Test public void validInputOnThenPipeTest() throws PipeRunException, ConfigurationException, PipeStartException{ pipe.configure(); pipe.start(); PipeRunResult prr = doPipe(pipe, "<test", session); Assert.assertEquals(pipeForwardThen, prr.getPipeForward().getName()); }
@Test public void emptyInputOnElsePipeTest() throws PipeRunException, ConfigurationException, PipeStartException{ pipe.configure(); pipe.start(); PipeRunResult prr = doPipe(pipe, "", session); Assert.assertEquals(pipeForwardElse, prr.getPipeForward().getName()); }
@Test public void nullInputOnElsePipeTest() throws PipeRunException, ConfigurationException, PipeStartException{ pipe.configure(); pipe.start(); PipeRunResult prr = doPipe(pipe, null, session); Assert.assertEquals(pipeForwardElse, prr.getPipeForward().getName()); }