Wicket JUnit test doesn't use UTF-8 properties

420 Views Asked by At

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?

2

There are 2 best solutions below

4
martin-g On

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.

0
zagrimsan On

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.