[ 
https://issues.apache.org/jira/browse/WICKET-6714?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16984310#comment-16984310
 ] 

Hans Schäfer commented on WICKET-6714:
--------------------------------------

Hello Sven, 

I've got two components, that are 
org.apache.wicket.markup.html.include.Include-components. These components 
include Markup provided by a webjar. These components do not work in a test 
unless a ServletContext is given. Unfortunatly these components are part of 
every page of the application, because they are Header and Footer of the pages. 
So every Test that renders any of the pages would have to be extended with a 
working ServletContext. This is not an option. We have got a workaround, but 
thats not nice: adding a try-catch around importUrl just to make the component 
not failing if it ist embedded in a tested page.

Looking at the test-code I found the MockServletContext and how it is 
initialized by a "standard" WicketTester. I thought it would be an improvement, 
if the MockServletContext would support Include-Components out of the box, even 
if no path is provided. Another option is, that WicketTester defines a 
reasonable path for the MockServletContext.

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
>
> 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)

Reply via email to