简体   繁体   English

詹金斯·马文(Jenkins Maven)Job Charset

[英]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. 我正在使用Spring Test来测试我的Spring Application,这基本上是一个REST Web服务,提供JSON和其他一些上传的媒体。

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. 单元测试在所有开发人员的机器上都可以正常工作,其中一些测试在JSON响应中返回的字符串,其中一小部分测试特殊字符。

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. 该应用程序已完全配置为对所有内容都使用UTF-8,但是JSON响应返回的字符集错误,因此测试失败。

I tried to configure on /etc/default/jenkins the following line: 我试图在/etc/default/jenkins配置以下行:

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 ... 当运行特定的测试时,我也有机会看到Charset.defaultCharset()是什么...它看起来像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: 在我的Spring Test配置中,我正在读取DML.sql文件以创建初始测试数据,并且初始化数据库的行是这样的:

<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. 这使我的配置依赖于服务器字符集,在我的情况下,我在服务器中设置了奇怪的“ US-ASCII”。

I made it independent by setting the encoding attribute to UTF-8 : 我通过将encoding属性设置为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. 因此,可以针对具有特殊字符的值测试来自H2数据库的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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