You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Tony Giaccone <to...@giaccone.org> on 2019/01/09 15:46:21 UTC

Spinning up Cayenne for unit test

I'm trying to spin up an in memory instance of H2 so that I can run some
unit tests. The model, has just the model and no datanode. I spin it up
with this line:

This code is in a project that is just cayenne and represents our data
model. It does have some base level of service implementation and all  of
the other tests in this project are unit tests with mockito.  This jar file
is included in other projects that are using bootique. I'd like to test the
base level of some services that are common across both apps that use the
model.

The problem is that the tables aren't created as part of the spin up. Any
suggestions on how to make that happen?

serverRuntime =  ServerRuntime.builder()
        .addConfig("cayenne-MyModel.xml")
        .url("jdbc:h2:mem:MyDB;MVCC=TRUE")
        .jdbcDriver("org.h2.Driver")
        .user("user")
        .password("password")
        .build();

Re: Spinning up Cayenne for unit test

Posted by "Giaccone, Tony" <an...@nytimes.com>.
Andrus,

Perfect that worked like a charm, only one small change, addModule, not
module.


Tony

On Wed, Jan 9, 2019 at 10:58 AM Andrus Adamchik <an...@objectstyle.org>
wrote:

> You may do something like this:
>
> ServerRuntime.builder()
>    .module(b ->
> b.bind(SchemaUpdateStrategyFactory.class).toInstance(descriptor -> new
> CreateIfNoSchemaStrategy()))
>    ...
>
> This is what "bootique-cayenne" does to generate the schema.
>
> Andrus
>
> > On Jan 9, 2019, at 6:46 PM, Tony Giaccone <to...@giaccone.org> wrote:
> >
> > I'm trying to spin up an in memory instance of H2 so that I can run some
> > unit tests. The model, has just the model and no datanode. I spin it up
> > with this line:
> >
> > This code is in a project that is just cayenne and represents our data
> > model. It does have some base level of service implementation and all  of
> > the other tests in this project are unit tests with mockito.  This jar
> file
> > is included in other projects that are using bootique. I'd like to test
> the
> > base level of some services that are common across both apps that use the
> > model.
> >
> > The problem is that the tables aren't created as part of the spin up. Any
> > suggestions on how to make that happen?
> >
> > serverRuntime =  ServerRuntime.builder()
> >        .addConfig("cayenne-MyModel.xml")
> >        .url("jdbc:h2:mem:MyDB;MVCC=TRUE")
> >        .jdbcDriver("org.h2.Driver")
> >        .user("user")
> >        .password("password")
> >        .build();
>
>

Re: Spinning up Cayenne for unit test

Posted by Andrus Adamchik <an...@objectstyle.org>.
You may do something like this:

ServerRuntime.builder()
   .module(b -> b.bind(SchemaUpdateStrategyFactory.class).toInstance(descriptor -> new CreateIfNoSchemaStrategy()))
   ...

This is what "bootique-cayenne" does to generate the schema.

Andrus

> On Jan 9, 2019, at 6:46 PM, Tony Giaccone <to...@giaccone.org> wrote:
> 
> I'm trying to spin up an in memory instance of H2 so that I can run some
> unit tests. The model, has just the model and no datanode. I spin it up
> with this line:
> 
> This code is in a project that is just cayenne and represents our data
> model. It does have some base level of service implementation and all  of
> the other tests in this project are unit tests with mockito.  This jar file
> is included in other projects that are using bootique. I'd like to test the
> base level of some services that are common across both apps that use the
> model.
> 
> The problem is that the tables aren't created as part of the spin up. Any
> suggestions on how to make that happen?
> 
> serverRuntime =  ServerRuntime.builder()
>        .addConfig("cayenne-MyModel.xml")
>        .url("jdbc:h2:mem:MyDB;MVCC=TRUE")
>        .jdbcDriver("org.h2.Driver")
>        .user("user")
>        .password("password")
>        .build();