@Override public boolean exists(final String path) { return execute(session -> session.exists(path)); }
@Test public void testIgnoreExists() throws Exception { when(session.exists(Mockito.anyString())).thenReturn(true); this.template.send(new GenericMessage<File>(this.file), FileExistsMode.IGNORE); verify(this.session, never()).write(Mockito.any(InputStream.class), Mockito.anyString()); }
@Test public void testFailNotExists() throws Exception { when(session.exists(Mockito.anyString())).thenReturn(false); this.template.send(new GenericMessage<File>(this.file), FileExistsMode.FAIL); verify(this.session).write(Mockito.any(InputStream.class), Mockito.anyString()); }
@Test public void testIgnoreNotExists() throws Exception { when(session.exists(Mockito.anyString())).thenReturn(false); this.template.send(new GenericMessage<File>(this.file), FileExistsMode.IGNORE); verify(this.session).write(Mockito.any(InputStream.class), Mockito.anyString()); }
return getSession().exists(path);
@Test public void testFailExists() throws Exception { when(session.exists(Mockito.anyString())).thenReturn(true); try { this.template.send(new GenericMessage<File>(this.file), FileExistsMode.FAIL); fail("Expected exception"); } catch (MessagingException e) { assertThat(e.getMessage(), Matchers.containsString("The destination file already exists")); } verify(this.session, never()).write(Mockito.any(InputStream.class), Mockito.anyString()); }
@Test //INT-2954 public void testMkDir() throws Exception { @SuppressWarnings("unchecked") Session<LsEntry> session = mock(Session.class); when(session.exists(anyString())).thenReturn(Boolean.FALSE); @SuppressWarnings("unchecked") SessionFactory<LsEntry> sessionFactory = mock(SessionFactory.class); when(sessionFactory.getSession()).thenReturn(session); FileTransferringMessageHandler<LsEntry> handler = new FileTransferringMessageHandler<LsEntry>(sessionFactory); handler.setAutoCreateDirectory(true); handler.setRemoteDirectoryExpression(new LiteralExpression("/foo/bar/baz")); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); final List<String> madeDirs = new ArrayList<String>(); doAnswer(invocation -> { madeDirs.add(invocation.getArgument(0)); return null; }).when(session).mkdir(anyString()); handler.handleMessage(new GenericMessage<String>("qux")); assertEquals(3, madeDirs.size()); assertEquals("/foo", madeDirs.get(0)); assertEquals("/foo/bar", madeDirs.get(1)); assertEquals("/foo/bar/baz", madeDirs.get(2)); }
@Override public boolean exists(final String path) { try { return this.sessionFactory.getSession().exists(path); } catch (IOException e) { throw new AmazonS3Exception("Failed to check the path " + path, e); } }
@Override public boolean exists(final String path) { try { return this.sessionFactory.getSession().exists(path); } catch (IOException e) { throw new AmazonS3Exception("Failed to check the path " + path, e); } }
assertTrue(session.rmdir("foo/")); }); assertFalse(template.getSession().exists("foo"));
return getSession().exists(path);