FileInputStreamDataInputParameter extends FileParameter implements DataInputParameter<InputStream> { @Override public InputStream extract(InterlokMessage message) throws CoreException { try { return connect(new URLString(url(message))); } catch (IOException ex) { throw ExceptionHelper.wrapCoreException(ex); } }  @Override InputStream extract(InterlokMessage message);  }
@Test(expected = CoreException.class) public void testNonExistingFile() throws Exception { AdaptrisMessage m = new DefaultMessageFactory().newMessage(); FileInputStreamDataInputParameter p = new FileInputStreamDataInputParameter(); try { p.url(m); fail(); } catch (IllegalArgumentException e) { } p.setDestination(new ConfiguredProduceDestination("file: assertEquals("file: InputStream result = p.extract(m); }
@Test public void testExtract() throws Exception { FileInputStreamDataInputParameter p = new FileInputStreamDataInputParameter(); File f = TempFileUtils.createTrackedFile(testName.getMethodName(), "", p); p.setDestination(new ConfiguredDestination("file: FileUtils.write(f, TEXT, false); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); assertNotSame(TEXT, msg.getContent()); InputStream stream = p.extract(msg); byte[] result = new byte[TEXT.length()]; stream.read(result); assertEquals(TEXT, new String(result)); }
@Test public void testExtractDestination() throws Exception { FileInputStreamDataInputParameter p = new FileInputStreamDataInputParameter(); File f = TempFileUtils.createTrackedFile(testName.getMethodName(), "", p); p.setDestination(new ConfiguredProduceDestination("file: FileUtils.write(f, TEXT, false); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); assertNotSame(TEXT, msg.getContent()); InputStream stream = p.extract(msg); byte[] result = new byte[TEXT.length()]; stream.read(result); assertEquals(TEXT, new String(result)); }
@Test public void testExtractFromClasspath() throws Exception { FileInputStreamDataInputParameter p = new FileInputStreamDataInputParameter(); p.setDestination(new ConfiguredProduceDestination("xstream-standalone.xml")); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); assertNotNull(p.extract(msg)); }
@Test public void testExtractFromRemote() throws Exception { EmbeddedJettyHelper helper = new EmbeddedJettyHelper(); helper.startServer(); MockMessageProducer mockProducer = new MockMessageProducer(); Channel channel = JettyHelper.createChannel(new EmbeddedConnection(), JettyHelper.createConsumer(URL_TO_POST_TO), mockProducer); try { LifecycleHelper.initAndStart(channel); FileInputStreamDataInputParameter p = new FileInputStreamDataInputParameter(); p.setDestination(helper.createProduceDestination()); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); assertNotNull(p.extract(msg)); } finally { LifecycleHelper.stopAndClose(channel); helper.stopServer(); } }