LineCountSplitter extends MessageSplitterImp { @Override public CloseableIterable<AdaptrisMessage> splitMessage(final AdaptrisMessage msg) throws CoreException { logR.trace("LineCountSplitter splits every {} lines", splitOnLine()); try { BufferedReader buf = new BufferedReader(msg.getReader(), bufferSize()); return new LineCountSplitGenerator(buf, msg, selectFactory(msg), readHeader(buf)); } catch (IOException e) { throw new CoreException(e); } } LineCountSplitter();  LineCountSplitter(Integer splitOnLine); @Override CloseableIterable<AdaptrisMessage> splitMessage(final AdaptrisMessage msg); void setSplitOnLine(Integer i); Integer getSplitOnLine(); void setIgnoreBlankLines(Boolean b); Boolean getIgnoreBlankLines(); Integer getBufferSize(); void setBufferSize(Integer b); Integer getKeepHeaderLines(); void setKeepHeaderLines(Integer keepHeaderLines);  }
@Test public void testDefaultSplit() throws Exception { LineCountSplitter s = new LineCountSplitter(); List<AdaptrisMessage> msgs = toList(s.splitMessage(msg)); assertEquals("10 split messages", 10, msgs.size()); }
@Test public void testDefaultSplit_WithCharEncoding() throws Exception { LineCountSplitter s = new LineCountSplitter(); msg.setContentEncoding(System.getProperty("file.encoding")); List<AdaptrisMessage> msgs = toList(s.splitMessage(msg)); assertEquals("10 split messages", 10, msgs.size()); }
@Test public void testSplitMessage() throws Exception { String obj = "ABCDEFG"; msg.addObjectHeader(obj, obj); LineCountSplitter s = new LineCountSplitter(); List<AdaptrisMessage> result = toList(s.splitMessage(msg)); assertEquals("10 split messages", 10, result.size()); for (AdaptrisMessage m : result) { assertFalse("Should not contain object metadata", m.getObjectHeaders().containsKey(obj)); } }
@Test public void testSplitMessageWithObjectMetadata() throws Exception { String obj = "ABCDEFG"; msg.addObjectHeader(obj, obj); LineCountSplitter s = new LineCountSplitter(); s.setCopyObjectMetadata(true); List<AdaptrisMessage> result = toList(s.splitMessage(msg)); assertEquals("10 split messages", 10, result.size()); for (AdaptrisMessage m : result) { assertTrue("Should contain object metadata", m.getObjectHeaders().containsKey(obj)); assertEquals(obj, m.getObjectHeaders().get(obj)); } }
@Test public void testIterator_DoubleProtection() throws Exception { MessageSplitterImp splitter = new LineCountSplitter(1); try (CloseableIterable<AdaptrisMessage> iterable = CloseableIterable.ensureCloseable(splitter.splitMessage(msg))) { Iterator<AdaptrisMessage> first = iterable.iterator(); try { Iterator<AdaptrisMessage> second = iterable.iterator(); fail(); } catch (IllegalStateException expected) { } } }
@Test public void testIterator_Remove() throws Exception { MessageSplitterImp splitter = new LineCountSplitter(1); try (CloseableIterable<AdaptrisMessage> iterable = CloseableIterable .ensureCloseable(splitter.splitMessage(msg))) { Iterator<AdaptrisMessage> first = iterable.iterator(); try { if (first.hasNext()) first.next(); first.remove(); fail(); } catch (UnsupportedOperationException expected) { } } }
@Test public void testIterator_HasNext() throws Exception { MessageSplitterImp splitter = new LineCountSplitter(1); try (CloseableIterable<AdaptrisMessage> iterable = CloseableIterable .ensureCloseable(splitter.splitMessage(msg))) { Iterator<AdaptrisMessage> first = iterable.iterator(); assertTrue(first.hasNext()); assertTrue(first.hasNext()); } }