[
https://issues.apache.org/jira/browse/WICKET-6714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16987807#comment-16987807
]
Hans Schäfer commented on WICKET-6714:
--------------------------------------
Hi Sven,
I added a quickstart, a small SpringBoot-Application. Don't take care too much
about webjars. Webjars just provide resources in META-INF/resources-directories.
What's not working is loading resources using ServletContext#getResource within
tests if using the default-MockServletContext of WicketTester.
ServletContext#getResource must load resources from
META-INF/resources-directories (see
[https://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getResource(java.lang.String)]
but it doesn't inside a "standard" WicketTester.
Creating the quickstart I just thought about the fix. I think, it's just
changing the directory passed to the MockServletContext from "null" to ".".
Just take a look at the tests, that I have added to the quickstart. I hope they
explain detailed enough.
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)