FileDataInputParameter extends FileParameter implements DataInputParameter<String> { @Override public String extract(InterlokMessage message) throws CoreException { try { return load(new URLString(url(message)), message.getContentEncoding()); } catch (IOException ex) { throw ExceptionHelper.wrapCoreException(ex); } } FileDataInputParameter(); @Override String extract(InterlokMessage message);  }
@Test(expected = CoreException.class) public void testNonExistingFile() throws Exception { AdaptrisMessage m = new DefaultMessageFactory().newMessage(); FileDataInputParameter p = new FileDataInputParameter(); try { p.url(m); fail(); } catch (IllegalArgumentException e) { } p.setDestination(new ConfiguredProduceDestination("file: assertEquals("file: String result = p.extract(m); }
@Test public void testExtract() throws Exception { FileDataInputParameter p = new FileDataInputParameter(); 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()); assertEquals(TEXT, p.extract(msg)); }
@Test public void testExtractDestination() throws Exception { FileDataInputParameter p = new FileDataInputParameter(); 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()); assertEquals(TEXT, p.extract(msg)); }
@Test public void testExtractFromClasspath() throws Exception { FileDataInputParameter p = new FileDataInputParameter(); 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); FileDataInputParameter p = new FileDataInputParameter(); p.setDestination(helper.createProduceDestination()); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); assertNotNull(p.extract(msg)); } finally { LifecycleHelper.stopAndClose(channel); helper.stopServer(); } }