You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Gregor Grambow <Gr...@isb-ag.de> on 2009/03/13 14:54:33 UTC

Problems finding templates in junit test

Hi everyone!

I am integrating velocity into our project and everything seems to work fine.
now i'm trying to write tests. There i have the problem that i cannot find my
velocity templates.
the project is no web app. it just generates text files.

i use the same process as in the real app:

p.setProperty("file.resource.loader.path", templateDir); 
Velocity.init(p);

in the app it works fine, but in the test the template is not found.
i tried different combinations of strings, relative, absolute, with "/" and
"\".
i checked if the starting path is the same in both cases (in both cases
project root).

then i checked via:

String test = (String) Velocity.getProperty("file.resource.loader.path");

if the property is set. for the real app it returns:
".\src\main\resources\templates"
and for the test it returns:
"."

if i move the templates to project root, it works fine, but that is no option
because there will be many templates.

could anyone tell me what i've done wrong? velocity version is 1.6.
or is it possibly a bug?

thanks in advance!

greetings
greg

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Problems finding templates in junit test

Posted by Gregor Grambow <Gr...@isb-ag.de>.
Hi Nathan!

Thanks for your help, now i use a separate instance and it works both for
main and test!

Greetings
Greg


-----Ursprüngliche Nachricht-----
Von: Gregor Grambow
Gesendet: Fr 13.03.2009 14:54
An: user@velocity.apache.org
Betreff: Problems finding templates in junit test
 
Hi everyone!

I am integrating velocity into our project and everything seems to work fine.
now i'm trying to write tests. There i have the problem that i cannot find my
velocity templates.
the project is no web app. it just generates text files.

i use the same process as in the real app:

p.setProperty("file.resource.loader.path", templateDir); 
Velocity.init(p);

in the app it works fine, but in the test the template is not found.
i tried different combinations of strings, relative, absolute, with "/" and
"\".
i checked if the starting path is the same in both cases (in both cases
project root).

then i checked via:

String test = (String) Velocity.getProperty("file.resource.loader.path");

if the property is set. for the real app it returns:
".\src\main\resources\templates"
and for the test it returns:
"."

if i move the templates to project root, it works fine, but that is no option
because there will be many templates.

could anyone tell me what i've done wrong? velocity version is 1.6.
or is it possibly a bug?

thanks in advance!

greetings
greg


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Problems finding templates in junit test

Posted by Nathan Bubna <nb...@gmail.com>.
I'm not sure why this is happening, but if i had to guess, this is
some sort of ClassLoader issue.  You might try using VelocityEngine
instead of the Velocity singleton, at least for your tests.  Then you
can be sure that you aren't double-initing the singleton or something.

On Fri, Mar 13, 2009 at 6:54 AM, Gregor Grambow
<Gr...@isb-ag.de> wrote:
> Hi everyone!
>
> I am integrating velocity into our project and everything seems to work fine.
> now i'm trying to write tests. There i have the problem that i cannot find my
> velocity templates.
> the project is no web app. it just generates text files.
>
> i use the same process as in the real app:
>
> p.setProperty("file.resource.loader.path", templateDir);
> Velocity.init(p);
>
> in the app it works fine, but in the test the template is not found.
> i tried different combinations of strings, relative, absolute, with "/" and
> "\".
> i checked if the starting path is the same in both cases (in both cases
> project root).
>
> then i checked via:
>
> String test = (String) Velocity.getProperty("file.resource.loader.path");
>
> if the property is set. for the real app it returns:
> ".\src\main\resources\templates"
> and for the test it returns:
> "."
>
> if i move the templates to project root, it works fine, but that is no option
> because there will be many templates.
>
> could anyone tell me what i've done wrong? velocity version is 1.6.
> or is it possibly a bug?
>
> thanks in advance!
>
> greetings
> greg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org