You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Chad Woolley <li...@thewoolleyweb.com> on 2004/01/02 05:47:29 UTC
What is the proper way to handle resource bundles when unit testing?
Hi,
I use a resource bundle in my app. In my ResourceManager class, I load it like
this:
ClassLoader classLoader = this.getClass().getClassLoader();
resourceBundle = ResourceBundle.getBundle(resourceFileName, locale,
classLoader);
However, when I run my ResourceManagerTest unit test via the default "test"
goal, my class always fails because it cannot find the resource bundle.
I tried specifying the bundle in the <resources> section of project.xml, but
this doesn't seem to work.
Is there a standard way to handle this, or any other maven projects that I can
look at for an example?
FYI - if I make custom goals to manually copy the bundle to basedir, and
manually invoke JUnit, then it works. This method doesn't work when using the
standard maven "test" goal, though.
Thanks,
Chad
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: What is the proper way to handle resource bundles when unit testing?
Posted by di...@multitask.com.au.
Yes, you use <resources> for this.
e.g.
<build>
.....
<resources>
<resource>
<directory>src/conf</directory>
<includes>
<include>*.xsd</include>
<include>*.dtd</include>
<include>*.mod</include>
<include>*.properties</include>
<include>driver.jelly</include>
</includes>
</resource>
<resource>
<directory>src/messages</directory>
<targetPath>org/apache/maven/messages</targetPath>
<includes>
<include>messages*.properties</include>
</includes>
</resource>
</resources>
</build>
--
dIon Gillard, Multitask Consulting
Blog: http://blogs.codehaus.org/people/dion/
Keith Irwin <ke...@keithirwin.com> wrote on 02/01/2004 04:42:39 PM:
> On Thu, 2004-01-01 at 20:47, Chad Woolley wrote:
> > Hi,
> >
> > I use a resource bundle in my app. In my ResourceManager class, I
load it like
> > this:
> >
> > ClassLoader classLoader = this.getClass().getClassLoader();
> > resourceBundle = ResourceBundle.getBundle(resourceFileName,
locale,
> > classLoader);
>
> Hm. I used cactus tests to run unit tests in a container to get this
> working. I'm guessing that it won't work unless your resource bundles
> are on the classpath. How you add *.properties files to a classpath in
> Maven -- well, I don't know. ;)
>
> I'm curious, but does the <resource> tag take care of this? Or do you
> have to do something interesting in maven.xml?
>
> Keith
>
> > However, when I run my ResourceManagerTest unit test via the default
"test"
> > goal, my class always fails because it cannot find the resource
bundle.
> >
> > I tried specifying the bundle in the <resources> section of
project.xml, but
> > this doesn't seem to work.
> >
> > Is there a standard way to handle this, or any other maven projects
that I can
> > look at for an example?
> >
> > FYI - if I make custom goals to manually copy the bundle to basedir,
and
> > manually invoke JUnit, then it works. This method doesn't work when
using the
> > standard maven "test" goal, though.
> >
> > Thanks,
> > Chad
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: What is the proper way to handle resource bundles when unit
testing?
Posted by Keith Irwin <ke...@keithirwin.com>.
On Thu, 2004-01-01 at 20:47, Chad Woolley wrote:
> Hi,
>
> I use a resource bundle in my app. In my ResourceManager class, I load it like
> this:
>
> ClassLoader classLoader = this.getClass().getClassLoader();
> resourceBundle = ResourceBundle.getBundle(resourceFileName, locale,
> classLoader);
Hm. I used cactus tests to run unit tests in a container to get this
working. I'm guessing that it won't work unless your resource bundles
are on the classpath. How you add *.properties files to a classpath in
Maven -- well, I don't know. ;)
I'm curious, but does the <resource> tag take care of this? Or do you
have to do something interesting in maven.xml?
Keith
> However, when I run my ResourceManagerTest unit test via the default "test"
> goal, my class always fails because it cannot find the resource bundle.
>
> I tried specifying the bundle in the <resources> section of project.xml, but
> this doesn't seem to work.
>
> Is there a standard way to handle this, or any other maven projects that I can
> look at for an example?
>
> FYI - if I make custom goals to manually copy the bundle to basedir, and
> manually invoke JUnit, then it works. This method doesn't work when using the
> standard maven "test" goal, though.
>
> Thanks,
> Chad
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: What is the proper way to handle resource bundles when unit testing?
Posted by "Jefferson K. French" <je...@frenches.org>.
When you say using <resources> doesn't seem to work, does that mean
the files are not copied at all, or they are copied to the wrong
place? Could you show us your <build> snippet and where you want the
resource files to go?
On Thu, 01 Jan 2004, at 21:47:29 [GMT -0700] Chad Woolley wrote:
> Hi,
> I use a resource bundle in my app. In my ResourceManager class, I load it like
> this:
> ClassLoader classLoader = this.getClass().getClassLoader();
> resourceBundle = ResourceBundle.getBundle(resourceFileName, locale,
> classLoader);
> However, when I run my ResourceManagerTest unit test via the default "test"
> goal, my class always fails because it cannot find the resource bundle.
> I tried specifying the bundle in the <resources> section of project.xml, but
> this doesn't seem to work.
> Is there a standard way to handle this, or any other maven projects that I can
> look at for an example?
> FYI - if I make custom goals to manually copy the bundle to basedir, and
> manually invoke JUnit, then it works. This method doesn't work when using the
> standard maven "test" goal, though.
> Thanks,
> Chad
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
--
mailto:jeff@frenches.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: What is the proper way to handle resource bundles when unit testing?
Posted by di...@multitask.com.au.
These are <unitTest> <resources> right, and not <build>?
--
dIon Gillard, Multitask Consulting
Blog: http://blogs.codehaus.org/people/dion/
Chad Woolley <li...@thewoolleyweb.com> wrote on 02/01/2004 03:47:29 PM:
> Hi,
>
> I use a resource bundle in my app. In my ResourceManager class, I load
it like
> this:
>
> ClassLoader classLoader = this.getClass().getClassLoader();
> resourceBundle = ResourceBundle.getBundle(resourceFileName, locale,
> classLoader);
>
> However, when I run my ResourceManagerTest unit test via the default
"test"
> goal, my class always fails because it cannot find the resource bundle.
>
> I tried specifying the bundle in the <resources> section of project.xml,
but
> this doesn't seem to work.
>
> Is there a standard way to handle this, or any other maven projects that
I can
> look at for an example?
>
> FYI - if I make custom goals to manually copy the bundle to basedir, and
> manually invoke JUnit, then it works. This method doesn't work when
using the
> standard maven "test" goal, though.
>
> Thanks,
> Chad
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org