[
https://issues.apache.org/jira/browse/WICKET-6714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16989834#comment-16989834
]
Hans Schäfer commented on WICKET-6714:
--------------------------------------
Hi Sven,
You are right: "." is not correct. "null" is semantical more precise ("I dont
know it") but with the drawback of not supporting resource-loading via
MockServletContext (as it is implemented now). So improving MockServletContext
in a way, so that it supports resource-loading from META-INF/resources in the
classpath with appBase = null, is a good way.
Otherwise: Especially in test-code you have to make good default guesses. If
you take a look at the affected lines of code in BaseWicketTester:
servletContext = servletCtx != null ? servletCtx
// If it's provided from the container it's not necessary to mock.
: !init && application.getServletContext() != null ?
application.getServletContext()
: new MockServletContext(application, null);
This is just a reasonable approach for determining a ServletContext with good
guesses. It guesses that "MockServletContext(application, null)" is a good
default. I also think "." is a better guess for a context root than "null", so
"MockServletContext(application, ".") is a better guess for a good default.
Regardless of whether BaseWicketTester or MockServletContext is changed or even
both: I think there won't be much tests affected. Resource-related methods of
ServletContext are rarely used.
Best regards
Hans
> Please add better getResource-Support for MockServletContext
> ------------------------------------------------------------
>
> Key: WICKET-6714
> URL: https://issues.apache.org/jira/browse/WICKET-6714
> Project: Wicket
> Issue Type: Improvement
> Components: wicket-core
> Affects Versions: 8.0.0, 9.0.0-M3
> Reporter: Hans Schäfer
> Priority: Minor
> Attachments: wicket-case-include.tar
>
>
> Hello!
> WicketTester does not provide a useful MockServletContext#getResource(). As
> WicketTester always instantiates MockServletContext passing a null-Value as
> path (webappRoot), the method MockServletContext#getResource always returns
> null, even if a resource in the classpath exists.
> My proposal for the implementation of Method MockServletContext#getResource()
> is:
> URL result = {color:#000080}null{color};
> {color:#000080}if {color}(name.startsWith({color:#008000}"/"{color})) {
> name = name.substring({color:#0000ff}1{color});
> }
> if (webappRoot != null) {
> final File f = {color:#000080}new
> {color}File({color:#660e7a}webappRoot{color}, name);
> {color:#000080} if {color}(f.exists()) {
> result = f.toURI().toURL();
> }
> {color:#000080}if {color}(result == {color:#000080}null{color}) {
> result =
> getClass().getClassLoader().getResource({color:#008000}"META-INF/resources/"
> {color}+ name);
> }
> {color:#000080}return {color}result;
> Best regards
> Hans
--
This message was sent by Atlassian Jira
(v8.3.4#803005)