tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laird Nelson <ljnel...@gmail.com>
Subject Re: Putting data source into local container?
Date Mon, 20 Apr 2009 17:46:26 GMT
Here is my JUnit 4.5 test case demonstrating the problem.

package openejbbugs;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingEnumeration;
import javax.naming.NameClassPair;

import org.junit.BeforeClass;
import org.junit.Test;

import static org.junit.Assert.*;

public class TestCaseOpenEJBBug {

  private static Context context;

  @BeforeClass
  public static final void oneTimeSetup() throws Exception {
    final Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
org.apache.openejb.client.LocalInitialContextFactory.class.getName());
    properties.setProperty("test", "new://Resource?type=DataSource");
    properties.setProperty("test.JdbcDriver", "org.h2.Driver");
    properties.setProperty("test.JdbcUrl",
"jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    properties.setProperty("test.Username", "");
    properties.setProperty("test.Password", "");
    properties.put("test.DefaultAutoCommit", Boolean.valueOf(false));
    // properties.setProperty("openejb.embedded.remotable", "true");

    context = new InitialContext(properties);

    boolean found = false;
    final NamingEnumeration<NameClassPair> ne = context.list("");
    assertNotNull(ne);
    try {
      while (ne.hasMore()) {
        final NameClassPair ncp = ne.next();
        assertNotNull(ncp);
        final String n = ncp.getName();
        assertNotNull(n);
        if (n.indexOf("test") >= 0) {
          found = true;
          break;
        }
      }
    } finally {
      ne.close();
    }
    assertTrue(found); // XXX Test fails here
  }

  @Test
  public void testLoad() throws Exception {
    assertNotNull(context);
  }

}

Best,
Laird

On Mon, Apr 20, 2009 at 1:34 PM, Laird Nelson <ljnelson@gmail.com> wrote:

> 3.1, yes, and sure, although the rest of my test code does not execute,
> because I don't get past this.
>
> The code I've supplied is all that I do to the InitialContext.  I have a
> session bean which deploys properly (i.e. it is available in the Context).
>
> The JNDI content gets dumped by this code:
>
>  final NamingEnumeration<NameClassPair> ne = context.list("");
>     assertNotNull(ne);
>     try {
>       while (ne.hasMore()) {
>         final NameClassPair ncp = ne.next();
>         assertNotNull(ncp);
>         System.out.println(ncp.getName() + " = " + ncp.getClassName());
>       }
>     } finally {
>       ne.close();
>     }
>
> ...and outputs:
>
> . = java.lang.String
> PersonsRemote = org.apache.openejb.core.ivm.naming.BusinessRemoteReference
>
> (PersonsRemote is obviously the deployment of my SLSB.)
>
> I will see what I can do to separate out the setup code from my test case
> and will post it next, although it won't add one whit to the information
> I've already supplied :-).
>
> Best,
> Laird
>
>
> On Mon, Apr 20, 2009 at 1:28 PM, Jean-Louis MONTEIRO <
> jean-louis.monteiro@atosorigin.com> wrote:
>
>>
>> Which openejb version do you use ?
>> Did you dump the JNDI content ?
>> Can you give us more code (from you unit test case ?) ?
>>
>> Jean-Louis
>>
>>
>> ljnelson wrote:
>> >
>> > Hello; I'd like to set up a data source in my embedded OpenEJB
>> container.
>> >
>> > Here's my code so far, which results in nothing being bound into the
>> JNDI
>> > tree:
>> >
>> >     final Properties properties = new Properties();
>> >     properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>> > org.apache.openejb.client.LocalInitialContextFactory.class.getName());
>> >     properties.setProperty("jdbc/test",
>> "new://Resource?type=DataSource");
>> >     properties.setProperty("jdbc/test.JdbcDriver", "org.h2.Driver");
>> >     properties.setProperty("jdbc/test.JdbcUrl",
>> > "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
>> >     properties.setProperty("jdbc/test.Username", "");
>> >     properties.setProperty("jdbc/test.Password", "");
>> >     properties.put("jdbc/test.DefaultAutoCommit",
>> Boolean.valueOf(false));
>> >     this.context = new InitialContext(properties);
>> >
>> > Any ideas?  The context is empty.  I got this recipe from the
>> > documentation
>> > on the website.
>> >
>> > Best,
>> > Laird
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Putting-data-source-into-local-container--tp23138888p23141193.html
>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message