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 18:58:02 GMT
This, I hope, will be the last TestCase I post.  Thanks for folks' patience.

I hope this is a definitive case that shows my problem.  Please disregard my
earlier ones.

In this test case, I make sure to incorporate Jean-Louis' suggestions.  For
whatever reason, the list() method fails with a NameNotFoundException,
claiming that it cannot find (and I checked this carefully)
"java:openejb/Resource", and so cannot list its contents.

Thanks again so far for your help, Jean-Louis; I am grateful for it, but I'm
still stuck.  :-(

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.Before;
import org.junit.Test;

import static org.junit.Assert.*;

public class TestCaseOpenEJBBug {

  private Context context;

  @Before
  public final void setUp() 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", "sa");
    properties.setProperty("test.Password", "");
    properties.put("test.DefaultAutoCommit", Boolean.valueOf(false));
    // properties.setProperty("openejb.embedded.remotable", "true");
    this.context = new InitialContext(properties);

    String name = null;

    // XXX TODO FIXME: the test fails here with the following output:
    // javax.naming.NameNotFoundException: Name "java:openejb/Resource" not
found.
    // at
org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:172)
    // at
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:129)
    // at
org.apache.openejb.core.ivm.naming.IvmContext.list(IvmContext.java:328)
    // at
org.apache.openejb.core.ivm.naming.ContextWrapper.list(ContextWrapper.java:99)
    // at javax.naming.InitialContext.list(InitialContext.java:436)
    // at openejbbugs.TestCaseOpenEJBBug.setUp(TestCaseOpenEJBBug.java:45)
    final NamingEnumeration<NameClassPair> ne =
this.context.list("java:openejb/Resource");
    assertNotNull(ne);
    try {
      while (ne.hasMore()) {
        final NameClassPair ncp = ne.next();
        assertNotNull(ncp);
        name = ncp.getName();
        if (name != null && name.indexOf("test") >= 0) {
          break;
        }
      }
    } finally {
      ne.close();
    }
    assertNotNull(name);
    System.out.println("Name: " + name);
    final Object o = this.context.lookup("java:openejb/Resource/test");
    assertTrue(o instanceof javax.sql.DataSource);
  }

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

}

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