1

I am building an application with Wicket and I am writing JUnit tests for my pages. My pages are in one package, which also contains a properties file called wicket-package.utf8.properties. The properties are successfully loaded when I deploy the application on a server:

INFO  org.apache.wicket.resource.PropertiesFactory - Loading properties files from file:/tmp/cargo/conf/webapps/my-project/WEB-INF/classes/com/myproject/web/wicket/page/wicket-package.utf8.properties with loader org.apache.wicket.resource.UtfPropertiesFilePropertiesLoader@37024e21

The problem appears, when I run the JUnit tests, because the PropertiesFactory loads a different properties file:

INFO  org.apache.wicket.resource.PropertiesFactory - Loading properties files from jar:file:/home/lovro/.gradle/caches/modules-2/files-2.1/org.apache.wicket/wicket-core/6.16.0/85dd5611907b269f6a25569d9df45513bd0b1b5a/wicket-core-6.16.0.jar!/org/apache/wicket/Application.properties with loader org.apache.wicket.resource.IsoPropertiesFilePropertiesLoader@62e7f11d

What you can see is, that on the server a UtfPropertiesFilePropertiesLoader is used, while in the tests a IsoPropertiesFilePropertiesLoader is used for loading the properties.

How can I force the usage of my custom utf8 properties file in the JUnit tests?

lmazgon
  • 1,215
  • 1
  • 21
  • 40

2 Answers2

1

Wicket should load all available resource bundles, i.e. both your UTF-8 based one and the one provided by Wicket distro with the defaults. It loads them lazily though. I.e. your UTF-8 based one will be loaded only if a page from com.myproject.web.wicket.page package is loaded.

martin-g
  • 17,243
  • 2
  • 23
  • 35
  • Thanks for the description, but this is not an answer to my problem. I know it "should" do that, the problem is it doesn't. And the page that I'm testing is of course in the same package as the properties file. – lmazgon Feb 16 '15 at 08:34
  • Then it may be a bug in Wicket. Please create a test case and attach it to a ticket in JIRA. – martin-g Feb 16 '15 at 09:46
  • I made a test project just with one page and a test - it works as it should. I must look into my project more deeply to see what is going on. – lmazgon Feb 17 '15 at 13:58
  • Oddly enough, as I opened my project again and ran the test, my properties were loaded. Must have been a Gradle / IntelliJ build issue. – lmazgon Feb 17 '15 at 14:14
0

Not an actual answer for the case that was asked, but very much related and included in case it would help someone else. I had an issue with one project where translation didn't work in unit tests after switching from .properties to .utf8.properties, although translations worked ok with WAR deployed on Tomcat. XML format for properties didn't work in neither case.

After some inspection I came into the conclusion that moving the property files to the same place where my HTML files were solved the issue. Originally properties were in the same dir as the .java files, which should've been ok. The reason for .properties.xml files not working on Tomcat probably was due to the ant build file not including them in the WAR in the first place.

Had I followed the default (best practice?) of having all sources (code and resources) together I would have avoid the issue completely, of course.

zagrimsan
  • 195
  • 2
  • 14