@Override public String send(final Message<?> message, String subDirectory, FileExistsMode... mode) { FileExistsMode modeToUse = mode == null || mode.length < 1 || mode[0] == null ? FileExistsMode.REPLACE : mode[0]; return send(message, subDirectory, modeToUse); }
@Override public String append(final Message<?> message, String subDirectory) { return send(message, subDirectory, FileExistsMode.APPEND); }
@Override public String send(Message<?> message, FileExistsMode... mode) { return send(message, null, mode); }
@Override protected void handleMessageInternal(Message<?> message) { String path = this.remoteFileTemplate.send(message, this.mode); if (this.chmod != null && isChmodCapable()) { doChmod(this.remoteFileTemplate, path, this.chmod); } }
/** * Put the file based on the message to the remote server. * The message can be consulted to determine some context. * The session argument isn't used in the default implementation. * @param message the request message related to this put command * @param session the remote protocol session related to this invocation context * @param subDirectory the target sub directory to put * @return The remote path, or null if no local file was found. * @since 5.0 */ protected String put(Message<?> message, Session<F> session, String subDirectory) { String path = this.remoteFileTemplate.send(message, subDirectory, this.fileExistsMode); if (path == null) { throw new MessagingException(message, "No local file found for " + message); } if (this.chmod != null && isChmodCapable()) { doChmod(this.remoteFileTemplate, path, this.chmod); } return 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()); }
@Test public void testReplace() throws Exception { this.template.send(new GenericMessage<File>(this.file), FileExistsMode.REPLACE); verify(this.session).write(Mockito.any(InputStream.class), Mockito.anyString()); }
@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 public void testAppend() throws Exception { this.template.setUseTemporaryFileName(false); this.template.send(new GenericMessage<File>(this.file), FileExistsMode.APPEND); verify(this.session).append(Mockito.any(InputStream.class), Mockito.anyString()); }