简体   繁体   中英

Jenkins Maven Job Charset

I'm using Spring Test to test my Spring Application, which is basically a REST webservice that serves JSON and some other uploaded media.

The unit tests are working fine in all developer's machines, and some of them tests for strings returning inside the JSON responses, and a little subset of them tests special characters.

The application is completely configured to use UTF-8 with everything, however the JSON response is returning with the wrong charset, so the test fails.

I tried to configure on /etc/default/jenkins the following line:

JAVA_ARGS="-Djava.awt.headless=true -Dfile.encoding=UTF8"

But I still get the same result.

I also had the chance to see what Charset.defaultCharset() was, when running a particular test... And it appeared something like US-ASCII ...

Can someone please tell me what am I doing wrong?

I found out what was wrong.

In my Spring Test configuration, I was reading a DML.sql file to create initial test data, and the line that initialized the database was like this:

<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="classpath:sql/DML.sql" />
</jdbc:initialize-database>

That left my configuration dependent from the server charset, and in my case I had that weird "US-ASCII" set in my server.

I made it independent by setting the encoding attribute to UTF-8 :

<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="classpath:sql/DML.sql" encoding="UTF-8" />
</jdbc:initialize-database>

So the values that came from the H2 database could be tested against values with special characters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM