Re: Using JspTaglibs outside servlet context

Attila Szegedi <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Yep, FreeMarker test suite actually has a mock servlet container  
implementation which you can use as a starting point/general idea.

OTOH, you can also instantiate a full servlet container in your JUnit  
test (Jetty is nicely embeddable and has low-footprint), bound to a  
random port, installing a rudimentary webapp into it, then triggering  
a HTTP request to it, and inspect the state of objects in the webapp  
after the HTTP request returned. Also, you can use HttpUnit or  
HtmlUnit if you want to make assertions on the HTTP response.

This approach is usually called "don't mock infrastructure" --  
googling for this expression can turn up an article or two arguing pro  
or contra it. The basic idea is that you run your unit test within a  
real framework instead of mocking one. Having easily embeddable  
framework components is of course essential for this; I prefer Jetty  
for test-embedded servlet container and ActiveMQ for test-embedded JMS.

Attila.

On 2007.12.11., at 10:58, Daniel Dekany wrote:

> Tuesday, December 11, 2007, 10:15:14 AM, Albertas Mickenas wrote:
>
>> Hi all,
>>
>>
>> I'm trying to accomplish rather an exotic setup.
>>
>> I'm programming portlets. I'm using Spring and Spring Webflow for  
>> that.
>> I'm using freemarker with portlet tld.
>>
>> What i'm trying to do is to create Unit tests for my Webflow states  
>> in
>> every state i want to check if the template compiles OK.
>
> You mean, check if the template *executes* OK?
>
>> To do that i get freemarker configurer from Spring context:
>>
>> freemarkerConfig = (FreeMarkerConfigurer)
>> context.getBean("freemarkerConfig");
>>
>> then i get the template, set view name and model to it and try to
>> process it.
>>
>> The problem is with JspTaglib - freemarker does not seem to find  
>> it. As
>> far as i dug into freemarker sources, i see JspTaglibFactory  
>> created and
>> used only in FreemarkerServlet.
>>
>> The question is - can i use JspTaglibs outside servlet context?
>
> That's a strange question, because the JSP tags themselves need
> servlet environment. That is, even if JspTaglib somehow magically
> works outside it, you still will not be able to execute the templates,
> since the JSP tags surely need the servlet environment. So you will
> need to setup a mock servlet environment somehow. (I guess you can
> find some examples of that in the test suite of FreeMarker.)
>
> -- 
> Best regards,
> Daniel Dekany
>
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://sourceforge.net/services/buy/index.php
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user

Attila.

--
home: http://www.szegedi.org
weblog: http://constc.blogspot.com





-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.