1

am working with docker to run my DAO unit test which hits the SQLServer database which resides in the docker container.

STEP1: i want me to pull the latest BAK file from my remote server(Linux box in which the docker was installed) to my project class path(src/test/resources) so that i can use the MSSQLServerContainer to fetch it before it start the container.

So am doing a SSHJ to fetch the file like below :

final SSHClient ssh = new SSHClient();
establishConnection(ssh);
SFTPClient sftp = ssh.newSFTPClient();

List<RemoteResourceInfo> files = sftp.ls("public");
for (RemoteResourceInfo file : files) {
    String remoteServerFileLocation = file.getPath();
    //This will download the BAK file to target folder
    sftp.get(remoteServerFileLocation, "src/test/resources");
    //sftp.get(remoteServerFileLocation, "target");
}
sftp.close();
ssh.disconnect();

and starting the container like below :

 xMSSQLServerContainer.withClasspathResourceMapping(BACKUP_FILE_NAME, BACKUP_FILE_PATH, BindMode.READ_ONLY).start();

so now my problem is, it is failing with the below error :

java.lang.IllegalArgumentException: Resource with path CCS_Utility.bak could not be found on any of these classloaders: [sun.misc.Launcher$AppClassLoader@18b4aac2]

seems like it is not flushing the file to classpath until the container is started. is there a way i can flush the file as soon as the below line sftp.get(remoteServerFileLocation, "src/test/resources"); is executed. so that it will be available on classpath by the time container starts.

before the container starts, it has to put the BAK file into src/test/resources folder so that it can start the container and pick the file from the classpath and run the unit test.

Pradeep
  • 1,192
  • 2
  • 12
  • 30
  • 1
    Do you use a build tool like Maven? If so, then `src/test/resources` is usually not part of the classpath. Try to copy the file into `target/test-classes`. – Roland Weisleder May 27 '18 at 18:43
  • Your classloader might have already been initialized by this point and does not know about the newly downloaded file? – Hiery Nomus Jun 18 '18 at 07:42

0 Answers0