чт, 11 авг. 2022 г. в 05:21, Han Li <aooo...@gmail.com>: > > > > > 2022年8月11日 06:52,Konstantin Kolinko <knst.koli...@gmail.com> 写道: > > > > ср, 10 авг. 2022 г. в 13:25, Han Li <aooo...@gmail.com > > <mailto:aooo...@gmail.com>>: > >> > >> Mark, > >> > >> Can I make a suggestion related to the ant build script. Can we add two > >> properties to set the values of ` -Duser.language` and `-Duser.country`, > >> because in the course of my testing I found that some of the unit test > >> assertions are in English, but there may be cases where the values are > >> converted by sm, e.g. Chinese. > >> Just like this: > >> Assert.assertEquals("ok”,x); > >> The variable x becomes "好" after passing through the StringManager. > >> > >> So this makes it a bit inconvenient for non-English speaking developers to > >> test. I avoid this problem by adding a statement to build.xml each time I > >> run a test. > >> <jvmarg value="-Duser.language=en"/> > >> <jvmarg value="-Duser.country=US"/> > >> > >> So I was wondering if we could dynamically set these two values via > >> build.properties > >> > >> Thanks, > >> > >> Han > > > > I think that such tests are just broken and require fixing. > > > > E.g. get an instance of StringManager and read the expected message from it. > > > > > > Maybe we can add -Duser.language=zh -Duser.country=CN to ANT_OPTS in > > some Buildbot configurations, to be able to detect such tests. > > Sorry, my explanation may be confusing. > > Let me explain why with a concrete unit test. Just like this: > org.apache.catalina.valves.TestErrorReportValve#testBug53071 > > ``` > Assert.assertTrue(res.toString().contains("<p><b>Message</b> " + > ErrorServlet.ERROR_TEXT + "</p>")); > ``` > org.apache.catalina.valves.ErrorReportValve#report > ``` > sb.append("<p><b>"); > sb.append(smClient.getString("errorReportValve.message")); > sb.append("</b> "); > ``` > Since the local of my OS is zh-CN, the response contains `<p><b>信息</b> .... ` > instead of `<p><b>Message</b>.... ', so I’m trying to avoid this by changing > user.language and user.country. > Unfortunately, I can’t find any way to do this at the moment, so I have to > manually modify the build.xml. >
1. I think that you could add a request header Accept-Language: en-US using the variant of getUrl() call that accepts a "reqHead" map. In TomcatBaseTest: public static int getUrl(String path, ByteChunk out, Map<String, List<String>> reqHead, Map<String, List<String>> resHead) throws IOException { 2. Alternatively, using StringManager: StringManager smClient = StringManager.getManager( Constants.Package, request.getLocales()); where Constants is org.apache.catalina.valves.Constants ServletRequest.getLocales() is documented as: * header. If the client request doesn't provide an Accept-Language header, * this method returns an <code>Enumeration</code> containing one * <code>Locale</code>, the default locale for the server. 3. BTW, I was faxing a similar failure3 years ago, https://github.com/apache/tomcat/commit/1758f6460a8e8fbf38b88385860379a4424cc66b Time flies fast... Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org