openejb:Resource/ds or java:global/ds if you set a global name to the ds.
Le 7 déc. 2015 22:45, "Steve Goldsmith" <[email protected]> a écrit :

> In order to keep my tests consistent I don't mind looking up the datasource
> without injection. So if I use:
>
>         final Map p = new HashMap();
>         p.put(Context.INITIAL_CONTEXT_FACTORY,
>                 "org.apache.openejb.core.LocalInitialContextFactory");
>         p.put("openejb.embedded.initialcontext.close ", "DESTROY");
>         p.put("openejb.embedded.remotable", "true");
>         p.put("dataSource", "new://Resource?type=DataSource");
>         p.put("dataSource.JdbcDriver", "org.hsqldb.jdbcDriver");
>         p.put("dataSource.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
>         p.put(EJBContainer.APP_NAME, "datasource");
>         p.put(EJBContainer.PROVIDER, "tomee-embedded");
>         // Add WAR and MDB modules
>         p.put(EJBContainer.MODULES, new File[]{Archive.archive().copyTo(
>             "WEB-INF/classes", jarLocation(TestService.class)).asDir()});
>         // Random port
>         p.put(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1");
>         container = EJBContainer.createEJBContainer(p);
>
> What would the lookup look like?
>
> context.lookup("java:global/.../dataSource");
>
>
>
> On Mon, Dec 7, 2015 at 4:11 PM, Romain Manni-Bucau <[email protected]>
> wrote:
>
> > maybe the easiest is to try
> >
> >
> https://github.com/apache/tomee/blob/120a33c7b4de07ae01c17978ea37d88a911ea860/container/openejb-junit/src/test/java/org/apache/openejb/junit/TestEJBContainerRule.java#L46
> >
> > side note: you can need to decorate your test @ManagedBean
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <http://rmannibucau.wordpress.com> | Github <
> > https://github.com/rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com>
> >
> > 2015-12-07 22:03 GMT+01:00 Steve Goldsmith <[email protected]>:
> >
> > > You say Injector class which I assume is not
> > > container.getContext().bind("inject", this). Is there an example
> > somewhere?
> > >
> > > On Mon, Dec 7, 2015 at 3:55 PM, Romain Manni-Bucau <
> > [email protected]>
> > > wrote:
> > >
> > > > Injector class can do the trick
> > > >
> > > >
> > > > Romain Manni-Bucau
> > > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > > <http://rmannibucau.wordpress.com> | Github <
> > > > https://github.com/rmannibucau> |
> > > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > > <http://www.tomitribe.com>
> > > >
> > > > 2015-12-07 21:36 GMT+01:00 sgjava <[email protected]>:
> > > >
> > > > > I am testing an app with EmbeddedTomEEContainer, but it's unable to
> > > > inject
> > > > > a
> > > > > DataSource as a @Resource. This works fine with standard
> > EJBContainer.
> > > Is
> > > > > this because injection is done on web app (deployment) vs. unit
> test?
> > > > >
> > > > > Works:
> > > > >
> > > > >
> > > >
> > >
> >
> https://github.com/sgjava/datasource-tomee/blob/master/src/test/java/com/codeferm/datasource/DataSourceTest.java
> > > > >
> > > > > Fails:
> > > > >
> > > > >
> > > >
> > >
> >
> https://github.com/sgjava/datasource-tomee/blob/master/src/test/java/com/codeferm/datasource/DataSourceWebTest.java
> > > > >
> > > > > Considering that is there a way to inject a DataSource resource in
> a
> > > web
> > > > > base unit test? The app doesn't use any database access, but I need
> > it
> > > > for
> > > > > the unit tests. I can always just use DbUtils/Commons Pool, but I
> > like
> > > to
> > > > > get resources from the container for tests.
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > View this message in context:
> > > > >
> > > >
> > >
> >
> http://tomee-openejb.979440.n4.nabble.com/Test-DataSource-injection-with-EmbeddedTomEEContainer-tp4677167.html
> > > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Steven P. Goldsmith
> > >
> >
>
>
>
> --
> Steven P. Goldsmith
>

Reply via email to