You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by WHIRLYCOTT <ph...@whirlycott.com> on 2005/05/03 17:41:21 UTC
[Slightly OT] JNDI question
I'm wondering if somone has any creative ideas here. I'm working on a
project that gets javax.sql.DataSource instances via Tomcat's JNDI
provider. This works fine, except when we are developing code and need
to run Junit tests.
Because the tests need to run outside Tomcat, getting access to a
DataSource via JNDI becomes a pain in the neck.
I'm assuming that this is a very common situation and I'm wondering if
anybody has slick tricks for your dev environments that allow you do get
DataSource objects via JNDI...?
phil.
--
Whirlycott
Philip Jacob
phil@whirlycott.com
http://www.whirlycott.com/phil/
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Slightly OT] JNDI question
Posted by Mattias J <mj...@expertsystem.se>.
This is how we do it and it works fine.
Spring provides lots of stuff that makes testing easier. I should have a
more thorough look at it myself someday...
At 2005-05-03 20:38, you wrote:
>Stumbled across this just recently: Spring has a "mock" JNDI
>implementation. Create your datasource, bind it into the mock JNDI tree,
>activate it and off you go. Note that this class is in the spring-mock
>JAR, not the regular spring JAR. Class documentation is at
>http://springframework.org/docs/api/org/springframework/mock/jndi/SimpleNamingContextBuilder.html
>
>Here's an example (we used a mock datasource, but you get the idea).
>
> SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
> MockDataSource mockDataSource = new MockDataSource();
> builder.bind("jdbc/foo", mockDataSource);
> builder.activate();
>
>So, if you can't "inject" the datasource then here's a nice and easy JNDI
>implementation that you can use.
>
>>WHIRLYCOTT wrote:
>>
>>>I'm wondering if somone has any creative ideas here. I'm working on a
>>>project that gets javax.sql.DataSource instances via Tomcat's JNDI
>>>provider. This works fine, except when we are developing code and need
>>>to run Junit tests.
>>>
>>>Because the tests need to run outside Tomcat, getting access to a
>>>DataSource via JNDI becomes a pain in the neck.
>>>
>>>I'm assuming that this is a very common situation and I'm wondering if
>>>anybody has slick tricks for your dev environments that allow you do get
>>>DataSource objects via JNDI...?
>>>
>>>phil.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Slightly OT] JNDI question
Posted by Paulo Gaspar <de...@kebom.net>.
Ops! Spice and the JNDIKIT have a new home:
http://spice.codehaus.org/components.html
Have fun,
Paulo Gaspar
Paulo Gaspar wrote:
> Or you can use an in memory JNDI datasource like this one:
> http://spice.sourceforge.net/jndikit/
>
>
> BTW, wasn't there an in memory JNDI datasource available in commons too?
> Was it removed? Or am I just confused?
>
> Thanks and regards,
> Paulo Gaspar
>
>
> Brian Murray wrote:
>
>> Stumbled across this just recently: Spring has a "mock" JNDI
>> implementation. Create your datasource, bind it into the mock JNDI
>> tree, activate it and off you go. Note that this class is in the
>> spring-mock JAR, not the regular spring JAR. Class documentation is
>> at
>> http://springframework.org/docs/api/org/springframework/mock/jndi/SimpleNamingContextBuilder.html
>> Here's an example (we used a mock datasource, but you get the idea).
>>
>> SimpleNamingContextBuilder builder = new
>> SimpleNamingContextBuilder();
>> MockDataSource mockDataSource = new MockDataSource();
>> builder.bind("jdbc/foo", mockDataSource);
>> builder.activate();
>> So, if you can't "inject" the datasource then here's a nice and
>> easy JNDI implementation that you can use.
>>
>>> WHIRLYCOTT wrote:
>>>
>>>> I'm wondering if somone has any creative ideas here. I'm working
>>>> on a project that gets javax.sql.DataSource instances via Tomcat's
>>>> JNDI provider. This works fine, except when we are developing code
>>>> and need to run Junit tests.
>>>>
>>>> Because the tests need to run outside Tomcat, getting access to a
>>>> DataSource via JNDI becomes a pain in the neck.
>>>>
>>>> I'm assuming that this is a very common situation and I'm wondering
>>>> if anybody has slick tricks for your dev environments that allow
>>>> you do get DataSource objects via JNDI...?
>>>>
>>>> phil.
>>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Slightly OT] JNDI question
Posted by Paulo Gaspar <de...@kebom.net>.
Or you can use an in memory JNDI datasource like this one:
http://spice.sourceforge.net/jndikit/
BTW, wasn't there an in memory JNDI datasource available in commons too?
Was it removed? Or am I just confused?
Thanks and regards,
Paulo Gaspar
Brian Murray wrote:
> Stumbled across this just recently: Spring has a "mock" JNDI
> implementation. Create your datasource, bind it into the mock JNDI
> tree, activate it and off you go. Note that this class is in the
> spring-mock JAR, not the regular spring JAR. Class documentation is
> at
> http://springframework.org/docs/api/org/springframework/mock/jndi/SimpleNamingContextBuilder.html
> Here's an example (we used a mock datasource, but you get the idea).
>
> SimpleNamingContextBuilder builder = new
> SimpleNamingContextBuilder();
> MockDataSource mockDataSource = new MockDataSource();
> builder.bind("jdbc/foo", mockDataSource);
> builder.activate();
> So, if you can't "inject" the datasource then here's a nice and
> easy JNDI implementation that you can use.
>
>> WHIRLYCOTT wrote:
>>
>>> I'm wondering if somone has any creative ideas here. I'm working on
>>> a project that gets javax.sql.DataSource instances via Tomcat's JNDI
>>> provider. This works fine, except when we are developing code and
>>> need to run Junit tests.
>>>
>>> Because the tests need to run outside Tomcat, getting access to a
>>> DataSource via JNDI becomes a pain in the neck.
>>>
>>> I'm assuming that this is a very common situation and I'm wondering
>>> if anybody has slick tricks for your dev environments that allow you
>>> do get DataSource objects via JNDI...?
>>>
>>> phil.
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Slightly OT] JNDI question
Posted by Brian Murray <br...@vanderbilt.edu>.
Stumbled across this just recently: Spring has a "mock" JNDI
implementation. Create your datasource, bind it into the mock JNDI
tree, activate it and off you go. Note that this class is in the
spring-mock JAR, not the regular spring JAR. Class documentation is at
http://springframework.org/docs/api/org/springframework/mock/jndi/SimpleNamingContextBuilder.html
Here's an example (we used a mock datasource, but you get the idea).
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
MockDataSource mockDataSource = new MockDataSource();
builder.bind("jdbc/foo", mockDataSource);
builder.activate();
So, if you can't "inject" the datasource then here's a nice and easy
JNDI implementation that you can use.
> WHIRLYCOTT wrote:
>
>> I'm wondering if somone has any creative ideas here. I'm working on
>> a project that gets javax.sql.DataSource instances via Tomcat's JNDI
>> provider. This works fine, except when we are developing code and
>> need to run Junit tests.
>>
>> Because the tests need to run outside Tomcat, getting access to a
>> DataSource via JNDI becomes a pain in the neck.
>>
>> I'm assuming that this is a very common situation and I'm wondering
>> if anybody has slick tricks for your dev environments that allow you
>> do get DataSource objects via JNDI...?
>>
>> phil.
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Slightly OT] JNDI question
Posted by Matt Goodwin <mg...@metalexis.com>.
I don't have a slick trick, but what I do is get my datasources from a
dbhelper class. In that class I try to read from jndi, if I can't get
access to jndi I read from a config file that sits on the classpath. In
Tomcat it gets the connection from jndi, for tests i create it from the
config file. Of course you can use a filesystem jndi implementation
that does the same thing (so I've read), but I guess I took the easy way
out. Wish I had some slick way of doing this.
Matt
WHIRLYCOTT wrote:
> I'm wondering if somone has any creative ideas here. I'm working on a
> project that gets javax.sql.DataSource instances via Tomcat's JNDI
> provider. This works fine, except when we are developing code and
> need to run Junit tests.
>
> Because the tests need to run outside Tomcat, getting access to a
> DataSource via JNDI becomes a pain in the neck.
>
> I'm assuming that this is a very common situation and I'm wondering if
> anybody has slick tricks for your dev environments that allow you do
> get DataSource objects via JNDI...?
>
> phil.
>
--
Matt Goodwin
mgoodwin@metalexis.com
(515)708-0114
Metalexis
"Transcending the Ordinary"
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Slightly OT] JNDI question
Posted by Pablo Lalloni <pl...@afip.gov.ar>.
We actually have a TestCase base class with methods for setting up individual
mechanisms or the whole environment (jndi, jta/jts, datasources, hibernate's
session factories, etc.).
We're currently using ObjectWeb's Carol for JNDI & JOTM for JTA, all starts up
in less than a sec.
The datasources are created and binded in the JNDI tree programmatically in
the test case.
JOTM is binded automatically at startup, we just have to rebind the
TransactionManager and UserTransaction to the JNDI addresses where the app
expects to find them.
Before current setup using JOTM/Carol, we used to setup Sun's JNDI filesystem
SPI for test cases but now we're happier people ;-)
El Mar 03 May 2005 12:41, WHIRLYCOTT escribió:
> I'm wondering if somone has any creative ideas here. I'm working on a
> project that gets javax.sql.DataSource instances via Tomcat's JNDI
> provider. This works fine, except when we are developing code and need
> to run Junit tests.
>
> Because the tests need to run outside Tomcat, getting access to a
> DataSource via JNDI becomes a pain in the neck.
>
> I'm assuming that this is a very common situation and I'm wondering if
> anybody has slick tricks for your dev environments that allow you do get
> DataSource objects via JNDI...?
>
> phil.
--
Pablo I. Lalloni <pl...@afip.gov.ar>
Teléfono +54 (11) 4347-3177
Proyecto Pampa
Dirección Informática Tributaria
AFIP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If I have not seen so far it is because I stood in giant's footsteps.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [Slightly OT] JNDI question
Posted by Michal Slocinski <ms...@gmail.com>.
have you heard about mock objects (http://jmock.codehaus.org,
http://easymock.org) ?
On 5/3/05, WHIRLYCOTT <ph...@whirlycott.com> wrote:
> I'm wondering if somone has any creative ideas here. I'm working on a
> project that gets javax.sql.DataSource instances via Tomcat's JNDI
> provider. This works fine, except when we are developing code and need
> to run Junit tests.
>
> Because the tests need to run outside Tomcat, getting access to a
> DataSource via JNDI becomes a pain in the neck.
>
> I'm assuming that this is a very common situation and I'm wondering if
> anybody has slick tricks for your dev environments that allow you do get
> DataSource objects via JNDI...?
>
> phil.
>
> --
> Whirlycott
> Philip Jacob
> phil@whirlycott.com
> http://www.whirlycott.com/phil/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
--
best regards,
Michal
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org