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:43:38 GMT
OK, bear with me.  Here is a revised test case that still fails.  You'll
note that my listing code, following your suggestion, works properly.  But
then a lookup based on that name--I hope--fails.

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;
    final NamingEnumeration<NameClassPair> ne = new
InitialContext(properties).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);
  }

}

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

> On Mon, Apr 20, 2009 at 2:40 PM, Jean-Louis MONTEIRO <
> jean-louis.monteiro@atosorigin.com> wrote:
>
>>
>> It works on my computer. I copy/paste your test case and I'm able to
>> lookup
>> the datasource.
>> The test fails because you did not change the context.list("") to
>> context.list("java:openejb/Resource")
>>
>
> Oh, so it's a forward slash before "Resource"?  OK, let me try that
> listing.
>
> Laird
>

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