INT-2267
removed test compile warnings INT-2267 removed test compile warnings(2)
This commit is contained in:
@@ -25,6 +25,7 @@ import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.Proxy;
|
||||
import com.jcraft.jsch.SocketFactory;
|
||||
@@ -38,7 +39,7 @@ import com.jcraft.jsch.UserInfo;
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public class DefaultSftpSessionFactory implements SessionFactory {
|
||||
public class DefaultSftpSessionFactory implements SessionFactory<LsEntry> {
|
||||
|
||||
private volatile String host;
|
||||
|
||||
@@ -141,7 +142,7 @@ public class DefaultSftpSessionFactory implements SessionFactory {
|
||||
}
|
||||
|
||||
|
||||
public Session getSession() {
|
||||
public Session<LsEntry> getSession() {
|
||||
Assert.hasText(this.host, "host must not be empty");
|
||||
Assert.hasText(this.user, "user must not be empty");
|
||||
Assert.isTrue(this.port >= 0, "port must be a positive number");
|
||||
|
||||
@@ -16,17 +16,6 @@
|
||||
|
||||
package org.springframework.integration.sftp.inbound;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Vector;
|
||||
@@ -44,6 +33,17 @@ import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
import com.jcraft.jsch.SftpATTRS;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
@@ -75,6 +75,7 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
ftpSessionFactory.setPassword("frog");
|
||||
ftpSessionFactory.setHost("foo.com");
|
||||
|
||||
|
||||
SftpInboundFileSynchronizer synchronizer = spy(new SftpInboundFileSynchronizer(ftpSessionFactory));
|
||||
synchronizer.setDeleteRemoteFiles(true);
|
||||
synchronizer.setRemoteDirectory("remote-test-dir");
|
||||
@@ -103,7 +104,9 @@ public class SftpInboundRemoteFileSystemSynchronizerTests {
|
||||
|
||||
public static class TestSftpSessionFactory extends DefaultSftpSessionFactory {
|
||||
|
||||
public Session getSession() {
|
||||
|
||||
@Override
|
||||
public Session<LsEntry> getSession() {
|
||||
try {
|
||||
ChannelSftp channel = mock(ChannelSftp.class);
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.integration.sftp.session.SftpTestSessionFactory;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -55,7 +56,7 @@ public class SftpSendingMessageHandlerTests {
|
||||
if (file.exists()){
|
||||
file.delete();
|
||||
}
|
||||
SessionFactory sessionFactory = new TestSftpSessionFactory();
|
||||
SessionFactory<LsEntry> sessionFactory = new TestSftpSessionFactory();
|
||||
FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sessionFactory);
|
||||
DefaultFileNameGenerator fGenerator = new DefaultFileNameGenerator();
|
||||
fGenerator.setExpression("payload + '.test'");
|
||||
@@ -66,21 +67,20 @@ public class SftpSendingMessageHandlerTests {
|
||||
assertTrue(new File("remote-target-dir", "template.mf.test").exists());
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testHandleStringMessage() throws Exception {
|
||||
File file = new File("remote-target-dir", "foo.txt");
|
||||
if (file.exists()){
|
||||
file.delete();
|
||||
}
|
||||
SessionFactory sessionFactory = new TestSftpSessionFactory();
|
||||
SessionFactory<LsEntry> sessionFactory = new TestSftpSessionFactory();
|
||||
FileTransferringMessageHandler handler = new FileTransferringMessageHandler(sessionFactory);
|
||||
DefaultFileNameGenerator fGenerator = new DefaultFileNameGenerator();
|
||||
fGenerator.setExpression("'foo.txt'");
|
||||
handler.setFileNameGenerator(fGenerator);
|
||||
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
|
||||
|
||||
handler.handleMessage(new GenericMessage("hello"));
|
||||
handler.handleMessage(new GenericMessage<String>("hello"));
|
||||
assertTrue(new File("remote-target-dir", "foo.txt").exists());
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ public class SftpSendingMessageHandlerTests {
|
||||
|
||||
public static class TestSftpSessionFactory extends DefaultSftpSessionFactory {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Session getSession() {
|
||||
@Override
|
||||
public Session<LsEntry> getSession() {
|
||||
try {
|
||||
ChannelSftp channel = mock(ChannelSftp.class);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation)
|
||||
throws Throwable {
|
||||
File file = new File((String)invocation.getArguments()[1]);
|
||||
@@ -120,7 +120,7 @@ public class SftpSendingMessageHandlerTests {
|
||||
|
||||
}).when(channel).put(Mockito.any(InputStream.class), Mockito.anyString());
|
||||
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation)
|
||||
throws Throwable {
|
||||
File file = new File((String) invocation.getArguments()[0]);
|
||||
|
||||
@@ -17,13 +17,15 @@ package org.springframework.integration.sftp.session;
|
||||
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class SftpTestSessionFactory {
|
||||
|
||||
public static Session createSftpSession(com.jcraft.jsch.Session jschSession) {
|
||||
public static Session<LsEntry> createSftpSession(com.jcraft.jsch.Session jschSession) {
|
||||
SftpSession sftpSession = new SftpSession(jschSession);
|
||||
sftpSession.connect();
|
||||
return sftpSession;
|
||||
|
||||
Reference in New Issue
Block a user