From 8c22a0c4f26acf153cabd776ea7cd2f565fec5ac Mon Sep 17 00:00:00 2001
From: "anh.phamtu" The test can either be run
+ *
right click > run as > JUnit Test
)mvn clean verify
)
Detailed guidance on writing these kind of tests can be found in our + * Process Testing docs + *
+ */ +@IvyProcessTest(enableWebServer = true) +public class SftpProcessSSHTest { + + private static final BpmProcess TEST_HELPER_PROCESS = BpmProcess.path("Sftp/SftpHelper"); + private static final BpmProcess TEST_UPLOAD_FILE_PROCESS = BpmProcess.path("Sftp/SftpUploadFile"); + private static final BpmProcess TEST_DOWNLOAD_FILE_PROCESS = BpmProcess.path("Sftp/SftpDownloadFile"); + + private static final String TEST_FILE_NAME = "market_market_connector_sftp.pdf"; + private static final long TEST_FILE_SIZE = 207569L; + + + @Test + @Order(1) + public void callOpenConnection(BpmClient bpmClient) { + String prefix = "com_axonivy_connector_sftp_server_"; + Ivy.var().set(prefix+"auth", "ssh"); + Ivy.var().set(prefix+"password", ""); + + String keyString = Files.readString("~/.ssh/sftptest"); + Ivy.var().set(prefix+"secret_sshkey", keyString); + Ivy.var().set(prefix+"secret_sshpassphrase", "123456"); + + BpmElement startable = TEST_HELPER_PROCESS.elementName("openConnection()"); + + SubProcessCallResult result = bpmClient.start() + .subProcess(startable) + .execute() // Callable sub process input arguments + .subResult(); + + SftpClientService sftpClient = result.param("sftpClient", SftpClientService.class); + assertThat(sftpClient).isNotNull(); + sftpClient.close(); + } + + // @Test + // @Order(2) + // public void callUploadFile(BpmClient bpmClient) { + // InputStream fileToBeUploaded = getClass().getResourceAsStream(TEST_FILE_NAME); + + // BpmElement startable = TEST_UPLOAD_FILE_PROCESS.elementName("uploadFile(InputStream,String)"); + + // SubProcessCallResult result = bpmClient.start() + // .subProcess(startable) + // .execute(fileToBeUploaded, TEST_FILE_NAME) // Callable sub process input arguments + // .subResult(); + + // Boolean isSuccess = result.param("isSuccess", Boolean.class); + // assertThat(isSuccess).isTrue(); + // } + + // @Test + // @Order(3) + // public void callUploadIvyFile(BpmClient bpmClient) throws IOException { + // InputStream fileToBeUploaded = getClass().getResourceAsStream(TEST_FILE_NAME); + // java.io.File javaFile = new java.io.File(TEST_FILE_NAME); + // FileUtils.copyInputStreamToFile(fileToBeUploaded, javaFile); + + // File ivyFile = new File(TEST_FILE_NAME, true); + // FileUtils.moveFile(javaFile, ivyFile.getJavaFile()); + + // BpmElement startable = TEST_UPLOAD_FILE_PROCESS.elementName("uploadFile(File)"); + + // SubProcessCallResult result = bpmClient.start() + // .subProcess(startable) + // .execute(ivyFile) // Callable sub process input arguments + // .subResult(); + + // Boolean isSuccess = result.param("isSuccess", Boolean.class); + // assertThat(isSuccess).isTrue(); + // } + + // @Test + // @Order(4) + // public void callListAllFiles(BpmClient bpmClient) { + // BpmElement startable = TEST_DOWNLOAD_FILE_PROCESS.elementName("listAllFiles(String)"); + + // SubProcessCallResult result = bpmClient.start() + // .subProcess(startable) + // .execute(".") // Callable sub process input arguments + // .subResult(); + // List