I don’t know whether I’m being too lazy to fix this but just ‘parent’ me here.
What I’m intending to do is to create an ‘mpd’ directory of path “C:\Users\Samuel34\Application Data\OpenMRS\mpd” but depending on
OpenmrsUtil.getDirectoryInApplicationDataDirectory(“Directory_NAME”)
However, this acts wickedly. Like for instance in my implementation in the mergepatientdata module, it creates a random/dynamic directory in the “AppData\Local\Temp” directory.
When you run the above snippet in the mergepatient module, here is the output “C:\Users\Samuel34\AppData\Local\Temp\appdir-for-unit-tests-192667210576031389\mpd”
But when I tested the same Test case in the sync2 module, I got the expected output “C:\Users\Samuel34\Application Data\OpenMRS\mpd”
But I want the directory to be created “C:\Users\Samuel34\Application Data\OpenMRS\mpd”not“C:\Users\Samuel34\AppData\Local\Temp\appdir-for-unit-tests-192667210576031389\mpd”. Could you give my question a second glance? @ssmusoke
I want to store customized “mpd.json” configuration in a known stable unchanging location just like sync2 does. I’m intending to store it in some dir like “C:\Users\Samuel34\Application Data\OpenMRS\mpd\mpd.json”.
The major challenge I’m facing is for my implementation, the dir is created like randomly, so it keeps changing. Thats not what we want @ssmusoke
@samuel34 AFAIK this is by design. This is done in order for unit tests to have a clean, independent application data directory to use. If you want to read a particular file from the application data directory, and to test this behavior, you should add some code into your unit test to first write the relevant file(s) to the “mpd/” folder before testing the code that reads these in. Or you could mock the behavior (see what @darius did here)
You’ll see when you actually run your module, that things work as intended with the application data directory you are expecting in C:\Users\Samuel34\Application Data\OpenMRS\mpd.
I’m not entirely sure why the sync2 module would behave differently than this - can you point me to the code that is in that repository that you say works differently?
Here is the Util method that works differently. I creates the directory in C:\Users\Samuel34\AppData\Local\Temp\appdir-for-unit-tests-232261003667222724 instead of C:\Users\Samuel34\Application Data\OpenMRS
@dkayiwa Actually, just to explain my blocker in a wider context,
I made this method expecting it to make a dir something like C:\Users\Samuel34\Application Data\OpenMRS\mpd but it acted otherwise. I went ahead and looked at sync2 codebase, I found out that in sync2, things actually work fine here. So in my mind I thought that maybe my implementation could be wrong,
Just for clarity, I made the above test case and tested it with both modules, but stubbornly it produced such “C:\Users\Samuel34\AppData\Local\Temp\appdir-for-unit-tests-192667210576031389\mpd” for my module and “C:\Users\Samuel34\Application Data\OpenMRS\mpd” for sync2.