ForEachChildElementPipe extends StringIteratorPipe implements IThreadCreator { @Override public void start() throws PipeStartException { try { if (extractElementsTp!=null) { extractElementsTp.open(); } } catch (Exception e) { throw new PipeStartException(e); } super.start(); }  @Override void configure(); @Override void start(); @Override void stop(); @Override boolean canProvideOutputStream(); @Override MessageOutputStream provideOutputStream(IPipeLineSession session); @IbisDoc({"1", "When set <code>true</code>, the input is assumed to be the name of a file to be processed. Otherwise, the input itself is transformed. The character encoding will be read from the XML declaration", "false"}) void setProcessFile(boolean b); boolean isProcessFile(); @IbisDoc({"2", "Element name (not an XPath-expression), qualified via attribute <code>namespaceDefs</code>, used to determine the 'root' of elements to be iterated over, i.e. the root of the set of child elements. " + "When empty, the pipe will iterate over each direct child element of the root", ""}) void setContainerElement(String containerElement); String getContainerElement(); @IbisDoc({"3", "Element name (not an XPath-expression), qualified via attribute <code>namespaceDefs</code>, used to determine the type of elements to be iterated over, i.e. the element name of each of the child elements. " + "When empty, the pipe will iterate over any direct child element of the root or specified containerElement", ""}) void setTargetElement(String targetElement); String getTargetElement(); @IbisDoc({"4", "XPath-expression used to determine the set of elements to be iterated over, i.e. the set of child elements. When empty, the effective value is /*/*, i.e. the pipe will iterate over each direct child element of the root. " +"Be aware that memory consumption appears to increase with file size when this attribute is used. When possible, use containerElement and/or targetElement instead.", ""}) void setElementXPathExpression(String string); String getElementXPathExpression(); @IbisDoc({"5", "Characterset used for reading file or inputstream, only used when {@link #setProcessFile(boolean) processFile} is <code>true</code>, or the input is of type InputStream", "utf-8"}) void setCharset(String string); String getCharset(); @IbisDoc({"6", "When set to <code>2</code> xslt processor 2.0 (net.sf.saxon) will be used, supporting XPath 2.0, otherwise xslt processor 1.0 (org.apache.xalan), supporting XPath 1.0. N.B. Be aware that setting this other than 1 might cause the input file being read as a whole in to memory, as Xslt Streaming is currently only supported by the XsltProcessor that is used for xsltVersion=1", "1"}) void setXsltVersion(int xsltVersion); int getXsltVersion(); @IbisDoc({"7", "when set <code>true</code> xslt processor 2.0 (net.sf.saxon) will be used, otherwise xslt processor 1.0 (org.apache.xalan)", "false"}) /** * @deprecated Please remove setting of xslt2, it will be auto detected. Or use xsltVersion. */ @Deprecated @ConfigurationWarning("It's value is now auto detected. If necessary, replace with a setting of xsltVersion") void setXslt2(boolean b); @IbisDoc({"8", "When set <code>true</code> namespaces (and prefixes) in the input message are removed before transformation", "true"}) void setRemoveNamespaces(boolean b); boolean isRemoveNamespaces(); @Override void setThreadLifeCycleEventListener(ThreadLifeCycleEventListener<Object> threadLifeCycleEventListener); final int DEFAULT_XSLT_VERSION; }
@Test public void testBasic() throws Exception { pipe.setSender(getElementRenderer()); configurePipe(); pipe.start(); PipeRunResult prr = doPipe(pipe, messageBasicNoNS, session); String actual = Message.asString(prr.getResult()); assertEquals(expectedBasicNoNS, actual); }
@Test public void testBlockSize() throws Exception { pipe.setSender(getElementRenderer()); pipe.setBlockSize(2); pipe.setBlockPrefix("<block>"); pipe.setBlockSuffix("</block>"); configurePipe(); pipe.start(); PipeRunResult prr = doPipe(pipe, messageBasicNoNS, session); String actual = Message.asString(prr.getResult()); assertEquals(expectedBasicNoNSBlock, actual); }
@Test public void testError() throws Exception { Exception targetException = new NullPointerException("FakeException"); pipe.setSender(getElementRenderer(targetException)); configurePipe(); pipe.start(); try { PipeRunResult prr = doPipe(pipe, messageError, session); fail("Expected exception to be thrown"); } catch (Exception e) { assertThat(e.getMessage(),StringContains.containsString("(NullPointerException) FakeException")); assertCauseChainEndsAtOriginalException(targetException,e); } }
@Test public void testTimeout() throws Exception { Exception targetException = new TimeOutException("FakeTimeout"); pipe.setSender(getElementRenderer(targetException)); configurePipe(); pipe.start(); try { PipeRunResult prr = doPipe(pipe, messageError, session); fail("Expected exception to be thrown"); } catch (Exception e) { assertThat(e.getMessage(),StringContains.containsString("FakeTimeout")); assertCauseChainEndsAtOriginalException(targetException,e); } }
@Test public void testBasicWithStopExpression() throws Exception { SwitchCounter sc = new SwitchCounter(); pipe.setSender(getElementRenderer()); pipe.setStopConditionXPathExpression("*[@name='p & Q']"); configurePipe(); pipe.start(); ByteArrayInputStream bais = new ByteArrayInputStream(messageBasicNoNS.getBytes()); PipeRunResult prr = doPipe(pipe, new LoggingInputStream(bais, sc), session); String actual = Message.asString(prr.getResult()); assertThat(sc.hitCount.get("in"), Matchers.lessThan(17)); assertEquals(expectedBasicNoNSFirstTwoElements, actual); }
@Test public void testBasicMaxItems1() throws Exception { SwitchCounter sc = new SwitchCounter(); pipe.setSender(getElementRenderer()); pipe.setMaxItems(1); configurePipe(); pipe.start(); ByteArrayInputStream bais = new ByteArrayInputStream(messageBasicNoNS.getBytes()); PipeRunResult prr = doPipe(pipe, new LoggingInputStream(bais, sc), session); String actual = Message.asString(prr.getResult()); assertEquals(expectedBasicNoNSFirstElement, actual); assertThat(sc.hitCount.get("in"), Matchers.lessThan(10)); }
@Test public void testBasicMaxItems2() throws Exception { SwitchCounter sc = new SwitchCounter(); pipe.setSender(getElementRenderer()); pipe.setMaxItems(2); configurePipe(); pipe.start(); ByteArrayInputStream bais = new ByteArrayInputStream(messageBasicNoNSLong.getBytes()); PipeRunResult prr = doPipe(pipe, new LoggingInputStream(bais, sc), session); String actual = Message.asString(prr.getResult()); assertEquals(expectedBasicNoNSFirstTwoElements, actual); assertThat(sc.hitCount.get("in"), Matchers.lessThan(15)); }