List of usage examples for org.springframework.integration.file.remote.session SessionFactory getSession
Session<F> getSession();
From source file:org.springframework.cloud.stream.app.test.ftp.FtpSourceTestConfiguration.java
@Bean public SessionFactory<FTPFile> ftpSessionFactory() { @SuppressWarnings("unchecked") SessionFactory<FTPFile> ftpSessionFactory = Mockito.mock(SessionFactory.class); @SuppressWarnings("unchecked") Session<FTPFile> session = mock(Session.class); when(ftpSessionFactory.getSession()).thenReturn(session); return ftpSessionFactory; }
From source file:org.springframework.integration.ftp.session.FtpRemoteFileTemplateTests.java
@Test public void testFileCloseOnBadConnect() throws Exception { @SuppressWarnings("unchecked") SessionFactory<FTPFile> sessionFactory = mock(SessionFactory.class); when(sessionFactory.getSession()).thenThrow(new RuntimeException("bar")); FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(sessionFactory); template.setRemoteDirectoryExpression(new LiteralExpression("foo")); template.afterPropertiesSet();//from ww w . jav a 2 s . c o m File file = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write("foo".getBytes()); fileOutputStream.close(); try { template.send(new GenericMessage<File>(file)); fail("exception expected"); } catch (MessagingException e) { assertEquals("bar", e.getCause().getMessage()); } File newFile = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); assertTrue(file.renameTo(newFile)); file.delete(); newFile.delete(); }
From source file:org.springframework.integration.ftp.session.SessionFactoryTests.java
@Test public void testStaleConnection() throws Exception { SessionFactory sessionFactory = Mockito.mock(SessionFactory.class); Session sessionA = Mockito.mock(Session.class); Session sessionB = Mockito.mock(Session.class); Mockito.when(sessionA.isOpen()).thenReturn(true); Mockito.when(sessionB.isOpen()).thenReturn(false); Mockito.when(sessionFactory.getSession()).thenReturn(sessionA); Mockito.when(sessionFactory.getSession()).thenReturn(sessionB); CachingSessionFactory cachingFactory = new CachingSessionFactory(sessionFactory, 2); Session firstSession = cachingFactory.getSession(); Session secondSession = cachingFactory.getSession(); secondSession.close();/*from w w w . j a va 2 s . c o m*/ Session nonStaleSession = cachingFactory.getSession(); assertEquals(TestUtils.getPropertyValue(firstSession, "targetSession"), TestUtils.getPropertyValue(nonStaleSession, "targetSession")); }
From source file:org.springframework.integration.ftp.session.SessionFactoryTests.java
@Test public void testSameSessionFromThePool() throws Exception { SessionFactory sessionFactory = Mockito.mock(SessionFactory.class); Session session = Mockito.mock(Session.class); Mockito.when(sessionFactory.getSession()).thenReturn(session); CachingSessionFactory cachingFactory = new CachingSessionFactory(sessionFactory, 2); Session s1 = cachingFactory.getSession(); s1.close();//www. j a v a2 s .co m Session s2 = cachingFactory.getSession(); s2.close(); assertEquals(TestUtils.getPropertyValue(s1, "targetSession"), TestUtils.getPropertyValue(s2, "targetSession")); Mockito.verify(sessionFactory, Mockito.times(2)).getSession(); }
From source file:org.springframework.integration.ftp.session.SessionFactoryTests.java
@Test(expected = MessagingException.class) // timeout expire public void testSessionWaitExpire() throws Exception { SessionFactory sessionFactory = Mockito.mock(SessionFactory.class); Session session = Mockito.mock(Session.class); Mockito.when(sessionFactory.getSession()).thenReturn(session); CachingSessionFactory cachingFactory = new CachingSessionFactory(sessionFactory, 2); cachingFactory.setSessionWaitTimeout(3000); cachingFactory.getSession();/*from w ww . ja v a 2s . c o m*/ cachingFactory.getSession(); cachingFactory.getSession(); }
From source file:org.springframework.integration.samples.advice.FileTransferDeleteAfterSuccessDemo.java
public static void main(String[] args) throws Exception { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/expression-advice-context.xml"); context.registerShutdownHook();// w ww . j a v a 2 s.c o m @SuppressWarnings("unchecked") SessionFactory<FTPFile> sessionFactory = context.getBean(SessionFactory.class); SourcePollingChannelAdapter fileInbound = context.getBean(SourcePollingChannelAdapter.class); @SuppressWarnings("unchecked") Session<FTPFile> session = mock(Session.class); when(sessionFactory.getSession()).thenReturn(session); fileInbound.start(); LOGGER.info("\n=========================================================" + "\n " + "\n This is the Expression Advice Sample - " + "\n " + "\n Press 'Enter' to terminate. " + "\n " + "\n Place a file in ${java.io.tmpdir}/adviceDemo ending " + "\n with .txt " + "\n The demo simulates a file transfer followed by the " + "\n Advice deleting the file; the result of the deletion " + "\n is logged. " + "\n " + "\n========================================================="); System.in.read(); System.exit(0); }
From source file:org.springframework.integration.samples.advice.FileTransferRenameAfterFailureDemo.java
public static void main(String[] args) throws Exception { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to Spring Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/integration/expression-advice-context.xml"); context.registerShutdownHook();//from w w w . j a v a2 s. c o m @SuppressWarnings("unchecked") SessionFactory<FTPFile> sessionFactory = context.getBean(SessionFactory.class); SourcePollingChannelAdapter fileInbound = context.getBean(SourcePollingChannelAdapter.class); when(sessionFactory.getSession()).thenThrow(new RuntimeException("Force Failure")); fileInbound.start(); LOGGER.info("\n=========================================================" + "\n " + "\n This is the Expression Advice Sample - " + "\n " + "\n Press 'Enter' to terminate. " + "\n " + "\n Place a file in ${java.io.tmpdir}/adviceDemo ending " + "\n with .txt " + "\n The demo simulates a file transfer failure followed " + "\n by the Advice renaming the file; the result of the " + "\n rename is logged. " + "\n " + "\n========================================================="); System.in.read(); System.exit(0); }