3

Having a file.txt inside the resources folder. And having a Bean to load that file on the Application start lifecycle:

In Development profile when compiled and running the resources folder is copied into the build (or target with maven) directory and the working dir is relative to the resources file so no need of special path or what so ever.

So basically is enough to have defined the filename in the application.properties.


In Test profile instead the working dir is the project root, so that file cannot be found anymore without giving the full relative path into the resources folder.

Is there any way to tell Quarkus test profile, and/or Microprofile config annotation, to lookup in resources folder to load some resources when needed?

I did not find anything apart a work-around to this not tidy profile difference.

Raffaello
  • 1,641
  • 15
  • 29
  • Did you try to put needed files under test/resources and perform the test ? – iabughosh Feb 22 '20 at 16:33
  • yes i tried and same error. the file must be on the same path of project root folder where also run the wrapper maven|gradle. if the file is located there can find it.. – Raffaello Feb 22 '20 at 18:40

2 Answers2

2

I solved by using profiled configuration, in my case seems in test the root folder is the root project folder, while in dev mode is the target folder, so I used this configuration in my property file:

cv-store-folder=./stored-cvs/
%dev.cv-store-folder=../stored-cvs/

I hope it can help you.

  • Thanks Salvatore, in my env it's exactly as you said. To be more specific: OS Windows 10 64b, Maven 3.6.3. For integration tests I'm copying the file using maven plugin to "${basedir}/target/file-name" and in integration test the launched app is using path "./target/file-name" – king pong Feb 14 '22 at 11:53
  • thanks, please vote up this answer if it helps – Salvatore Pannozzo Capodiferro Feb 14 '22 at 15:48
1

I don't know if there is much we can do automatically here, gradle/maven control the working directory of the test process. With maven at least you can control the working directory of the surefire process, see this answer here: Maven: change the directory in which tests are executed

Stuart Douglas
  • 847
  • 5
  • 4
  • The quarkus plugin cannot have some extra control over the profiles? Probably woukd be enough having the resouces dir has a quarkus property so the path can be built indipendently of the working dir... Anyway thanks, for sure might not be a priority neither. – Raffaello Feb 23 '20 at 11:16