JUnit Access DataSource from Context?

Discussion in 'Java' started by gilgantic, Jul 18, 2005.

  1. gilgantic

    gilgantic Guest

    I am trying to run JUnit test case in my WebSphere Studio, but it fails
    during a context.lookup in my DAO class. The DataSource is defined on
    the server, so I start the Development Test Server. Here is a snippet
    of the the code in my DAO class.

    Context context = new InitialContext();
    DataSource dataSource = (DataSource) context.lookup("jdbc/sample");

    Is it because my Dev Test Server and JUnit are using two different
    JVMs? How do I solve this problem?
     
    gilgantic, Jul 18, 2005
    #1
    1. Advertising

  2. gilgantic

    Ray McVay Guest

    gilgantic wrote:
    > I am trying to run JUnit test case in my WebSphere Studio, but it fails
    > during a context.lookup in my DAO class. The DataSource is defined on
    > the server, so I start the Development Test Server. Here is a snippet
    > of the the code in my DAO class.
    >
    > Context context = new InitialContext();
    > DataSource dataSource = (DataSource) context.lookup("jdbc/sample");
    >
    > Is it because my Dev Test Server and JUnit are using two different
    > JVMs?

    I think so although I've never understood why since JNDI is supposed to
    be a network service.

    > How do I solve this problem?
    >

    I've been told, "use Cactus." You can also include the test classes in
    the web app and drive them from JSPs with the app running in a test
    environment.
     
    Ray McVay, Jul 19, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VS_NET_DEV
    Replies:
    2
    Views:
    3,828
    jenny
    May 25, 2004
  2. =?Utf-8?B?U3VuU21pbGU=?=
    Replies:
    0
    Views:
    715
    =?Utf-8?B?U3VuU21pbGU=?=
    Jan 10, 2006
  3. Ron de Waard
    Replies:
    2
    Views:
    12,658
    HansDampf
    Oct 5, 2007
  4. Aljosa Mohorovic

    context.xml and DataSource

    Aljosa Mohorovic, Nov 28, 2006, in forum: Java
    Replies:
    1
    Views:
    3,543
    Juha Laiho
    Dec 4, 2006
  5. JEFF JARRELL

    detecting in a JUnit context

    JEFF JARRELL, Sep 3, 2007, in forum: Java
    Replies:
    3
    Views:
    343
    Mark Space
    Sep 5, 2007
Loading...

Share This Page