-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PowerMock and FakeSftpServerRule Server wont start #18
Comments
When i comment out powermock, the server starts package de.itout.spinterface.interfaces.fileDistributor;
import com.github.stefanbirkner.fakesftpserver.rule.*;
import de.gsq.system.*;
import de.itout.spinterfaces.*;
import de.itout.spinterfaces.interfaces.*;
import java.io.*;
import java.net.*;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.util.*;
import org.junit.*;
import static org.junit.Assert.*;
import org.junit.runner.*;
import static org.mockito.Mockito.*;
import org.powermock.api.mockito.*;
import org.powermock.core.classloader.annotations.*;
import org.powermock.modules.junit4.*;
/**
* Unit Test der Schnittstelle FileDistributor.
*
* Testcase: File SFTP Upload.
*
* @author swendelmann
*/
//@RunWith(PowerMockRunner.class)
//@PrepareForTest(VO.class)
//@PowerMockIgnore(
// {
// "javax.management.*", "javax.script.*", "org.apache.sshd.*", "com.github.*"
// })
public class FileDistributorSFTPUploadTest
{
/**
* Interface to Test.
*/
private SPInterface inter;
@Rule
public final FakeSftpServerRule sftpServer = new FakeSftpServerRule().addUser("username", "password");
private final String sftpDir = "/data";
private final String sftpUser = "username";
private final String sftpPass = "password";
private File testFile;
public FileDistributorSFTPUploadTest()
{
}
@Before
public void setUp() throws URISyntaxException, IOException
{
Environment.getInstance().setApplicationType(Environment.APPLICATION_TYPE_CLI);
// PowerMockito.mockStatic(VO.class);
// PowerMockito.when(VO.getVO(anyString())).thenReturn("mocked");
// PowerMockito.when(VO.getVO(anyString(), any(Object[].class))).thenReturn("mocked");
// PowerMockito.when(VO.getVO(anyString(), any(Object[].class), anyString())).thenReturn("mocked");
// PowerMockito.when(VO.getVO(anyString(), any(Class.class))).thenReturn("mocked");
// PowerMockito.when(VO.getVOEntry(anyString(), anyString(), anyString(), any(Object[].class), anyString(), anyString())).thenReturn("mocked");
//
// // Interface Setup
// inter = new FileDistributor();
// inter.setLaufID("FD00002");
// inter.setSchnittstelle("FileDist");
// inter.setVersion("FD02");
//
// testFile = new File(getClass().getClassLoader().getResource("order.csv").toURI());
sftpServer.createDirectory(sftpDir);
}
@After
public void tearDown()
{
}
@Test
public void ftpUloadFileFromFilesystem() throws URISyntaxException, IOException
{
// Init Interface Parameter
HashMap<String, SPInterface.ParameterHeader> header = new HashMap<>();
LinkedHashMap<String, SPParameter> parameter = new LinkedHashMap<>();
header.put("SAVE_DIC", inter.new ParameterHeader("A", 1, "Sicherungsverzeichnis"));
header.put("IN_DIR", inter.new ParameterHeader("A", 1, "Input Verzeichnis"));
header.put("FILESEL", inter.new ParameterHeader("A", 1, "Datei Selection"));
header.put("SFTP", inter.new ParameterHeader("A", 1, "SFTP übertragen?"));
header.put("SFTPDIR", inter.new ParameterHeader("A", 1, "SFTP Verz"));
header.put("SFTPHOST", inter.new ParameterHeader("A", 1, "SFTP host"));
header.put("SFTPPORT", inter.new ParameterHeader("A", 1, "SFTP Port"));
header.put("SFTPUSER", inter.new ParameterHeader("A", 1, "SFTP User"));
header.put("SFTPPWD", inter.new ParameterHeader("A", 1, "SFTP PWD"));
parameter.put("SAVE_DIC_1", new SPParameter("A", "test-save-dic", 0, "", "Sicherungsverzeichnis"));
parameter.put("IN_DIR_1", new SPParameter("A", testFile.getParent(), 0, "", "Input Verzeichnis"));
parameter.put("FILESEL_1", new SPParameter("A", testFile.getName(), 0, "", "Datei Selection"));
parameter.put("SFTP_1", new SPParameter("A", "JA", 0, "", "SFTP übertragen?"));
parameter.put("SFTPDIR_1", new SPParameter("A", sftpDir, 0, "", "SFTP Verz"));
parameter.put("SFTPHOST_1", new SPParameter("A", "localhost", 0, "", "SFTP host"));
parameter.put("SFTPPORT_1", new SPParameter("A", "", sftpServer.getPort(), "", "SFTP Port"));
parameter.put("SFTPUSER_1", new SPParameter("A", sftpUser, 0, "", "SFTP User"));
parameter.put("SFTPPWD_1", new SPParameter("A", sftpPass, 0, "", "SFTP PWD"));
inter.loadTestParameter(header, parameter);
inter.startTest();
// Assertions
// Assert Interface Values (status, appended files, logging, etc.)
assertEquals(SPInterface.OK, inter.getLaufStatus());
assertTrue(inter.getLaufDateien().stream().filter(o -> o.getDatei().equals(testFile.getName())).findFirst().isPresent());
assertTrue(sftpServer.existsFile(sftpDir + "/order.csv"));
assertEquals("A;B;C", sftpServer.getFileContent(sftpDir + "/order.csv", UTF_8));
//TODO: Weitere Assertions definieren.
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a worst case scenario application i have to write unit test for.
Much static & legacy code.
I managed to get it running by powermock static methods.
One Unit test has to run against a SFTP Server.
I tried your rule in a clean env. and it works as designed.
But when i add it to our code, the server wont start. (Tired with FileZilla to connect to the random port).
The Output
The text was updated successfully, but these errors were encountered: