You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by emeka okafor <em...@yahoo.com> on 2012/11/10 00:04:20 UTC

testing with cayenne

New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
Thank you.

Re: testing with cayenne

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 10/11/12 10:04am, emeka okafor wrote:
> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?

One approach that can work is http://www.dbunit.org/ with an in memory database like Derby. Basically it makes it easy to fire up a database, inject a bunch of known data and then run your tests.


Ari



-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Re: createIfNoSchemaStrategy

Posted by Michael Gentry <mg...@masslight.net>.
Hi Emeka,

I had never used a schema with my H2 stuff and you are correct, it
dies when you have it.  :-)

You seem to have found the correct answer, too, from what I could tell
when I updated mine.  Here is what my node XML file ended up looking
like:

<driver project-version="3.0.0.1" class="org.h2.Driver">
	<url value="jdbc:h2:mem:cbe;INIT=CREATE SCHEMA IF NOT EXISTS CBE"/>
	<connectionPool min="1" max="10"/>
	<login/>
</driver>


mrg

On Sat, Nov 10, 2012 at 10:14 AM, emeka okafor <em...@yahoo.com> wrote:
> From your URL I could infer that I could run arbitrary statement at connection time. A quick look in the h2 documentation and I can now run my tests with the following url:
> jdbc:h2:/~/test.db;INIT=create schema if not exists test
>
> Thank you again.
>
>
> ________________________________
>  From: Mike Kienenberger <mk...@gmail.com>
> To: user@cayenne.apache.org; emeka okafor <em...@yahoo.com>
> Sent: Saturday, November 10, 2012 3:36 PM
> Subject: Re: createIfNoSchemaStrategy
>
> I haven't used H2 without schemas.
>
> Normally I work using this:
>
> jdbc:h2:~/database.file;SCHEMA_SEARCH_PATH=schema1,schema2,schema3,etc
>
> On Sat, Nov 10, 2012 at 9:12 AM, emeka okafor <em...@yahoo.com> wrote:
>> Hello again,
>>
>> thank you for the help. I settled with h2database to begin with and now I am getting this error when I try to run cayenne:
>>
>> Schema "TEST" not found; SQL statement: create blablabla....
>>
>>
>> even though I have set the following:
>>
>> schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"
>>
>>
>> Any idea?
>>
>> ________________________________
>>  From: Michael Gentry <mg...@masslight.net>
>> To: user@cayenne.apache.org; emeka okafor <em...@yahoo.com>
>> Sent: Saturday, November 10, 2012 2:26 PM
>> Subject: Re: testing with cayenne
>>
>> Hi Emeka,
>>
>> We've used http://h2database.com/ before to create a real in-memory
>> database to run tests against.  H2 is small and fast and works pretty
>> well, plus by creating your schema/data in-memory only, you don't have
>> to worry about file permissions or cleanup when your tests are done
>> running.
>>
>> mrg
>>
>>
>> On Fri, Nov 9, 2012 at 6:04 PM, emeka okafor <em...@yahoo.com> wrote:
>>> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
>>> Thank you.

Re: createIfNoSchemaStrategy

Posted by emeka okafor <em...@yahoo.com>.
>From your URL I could infer that I could run arbitrary statement at connection time. A quick look in the h2 documentation and I can now run my tests with the following url:
jdbc:h2:/~/test.db;INIT=create schema if not exists test

Thank you again.


________________________________
 From: Mike Kienenberger <mk...@gmail.com>
To: user@cayenne.apache.org; emeka okafor <em...@yahoo.com> 
Sent: Saturday, November 10, 2012 3:36 PM
Subject: Re: createIfNoSchemaStrategy
 
I haven't used H2 without schemas.

Normally I work using this:

jdbc:h2:~/database.file;SCHEMA_SEARCH_PATH=schema1,schema2,schema3,etc

On Sat, Nov 10, 2012 at 9:12 AM, emeka okafor <em...@yahoo.com> wrote:
> Hello again,
>
> thank you for the help. I settled with h2database to begin with and now I am getting this error when I try to run cayenne:
>
> Schema "TEST" not found; SQL statement: create blablabla....
>
>
> even though I have set the following:
>
> schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"
>
>
> Any idea?
>
> ________________________________
>  From: Michael Gentry <mg...@masslight.net>
> To: user@cayenne.apache.org; emeka okafor <em...@yahoo.com>
> Sent: Saturday, November 10, 2012 2:26 PM
> Subject: Re: testing with cayenne
>
> Hi Emeka,
>
> We've used http://h2database.com/ before to create a real in-memory
> database to run tests against.  H2 is small and fast and works pretty
> well, plus by creating your schema/data in-memory only, you don't have
> to worry about file permissions or cleanup when your tests are done
> running.
>
> mrg
>
>
> On Fri, Nov 9, 2012 at 6:04 PM, emeka okafor <em...@yahoo.com> wrote:
>> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
>> Thank you.

Re: createIfNoSchemaStrategy

Posted by Mike Kienenberger <mk...@gmail.com>.
I haven't used H2 without schemas.

Normally I work using this:

jdbc:h2:~/database.file;SCHEMA_SEARCH_PATH=schema1,schema2,schema3,etc

On Sat, Nov 10, 2012 at 9:12 AM, emeka okafor <em...@yahoo.com> wrote:
> Hello again,
>
> thank you for the help. I settled with h2database to begin with and now I am getting this error when I try to run cayenne:
>
> Schema "TEST" not found; SQL statement: create blablabla....
>
>
> even though I have set the following:
>
> schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"
>
>
> Any idea?
>
> ________________________________
>  From: Michael Gentry <mg...@masslight.net>
> To: user@cayenne.apache.org; emeka okafor <em...@yahoo.com>
> Sent: Saturday, November 10, 2012 2:26 PM
> Subject: Re: testing with cayenne
>
> Hi Emeka,
>
> We've used http://h2database.com/ before to create a real in-memory
> database to run tests against.  H2 is small and fast and works pretty
> well, plus by creating your schema/data in-memory only, you don't have
> to worry about file permissions or cleanup when your tests are done
> running.
>
> mrg
>
>
> On Fri, Nov 9, 2012 at 6:04 PM, emeka okafor <em...@yahoo.com> wrote:
>> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
>> Thank you.

createIfNoSchemaStrategy

Posted by emeka okafor <em...@yahoo.com>.
Hello again,

thank you for the help. I settled with h2database to begin with and now I am getting this error when I try to run cayenne:

Schema "TEST" not found; SQL statement: create blablabla....


even though I have set the following:

schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"


Any idea?

________________________________
 From: Michael Gentry <mg...@masslight.net>
To: user@cayenne.apache.org; emeka okafor <em...@yahoo.com> 
Sent: Saturday, November 10, 2012 2:26 PM
Subject: Re: testing with cayenne
 
Hi Emeka,

We've used http://h2database.com/ before to create a real in-memory
database to run tests against.  H2 is small and fast and works pretty
well, plus by creating your schema/data in-memory only, you don't have
to worry about file permissions or cleanup when your tests are done
running.

mrg


On Fri, Nov 9, 2012 at 6:04 PM, emeka okafor <em...@yahoo.com> wrote:
> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
> Thank you.

Re: testing with cayenne

Posted by Mike Kienenberger <mk...@gmail.com>.
My cayenne tests are all run against an in-memory hsqldb database with dbunit.

For some things, I subclass my <Entity>.java files as
Mock<Entity>.java and provide a mock DAO manager that skips the
database.   The subclassing was because I hadn't set up my references
to entities as interfaces.  I'd probably have just generated separate
mock classes with interfaces if starting fresh.

My newer apps use H2 for testing.   My only issue with H2 is it is not
completely in-memory.   It still uses a file, which makes it more
difficult to run tests in parallel.   On the other hand, it's trivial
to switch between app-specific, shared server, tcp-ip server, and so
on, which makes debugging a failing test far easier.

On Sat, Nov 10, 2012 at 8:26 AM, Michael Gentry <mg...@masslight.net> wrote:
> Hi Emeka,
>
> We've used http://h2database.com/ before to create a real in-memory
> database to run tests against.  H2 is small and fast and works pretty
> well, plus by creating your schema/data in-memory only, you don't have
> to worry about file permissions or cleanup when your tests are done
> running.
>
> mrg
>
>
> On Fri, Nov 9, 2012 at 6:04 PM, emeka okafor <em...@yahoo.com> wrote:
>> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
>> Thank you.

Re: testing with cayenne

Posted by Michael Gentry <mg...@masslight.net>.
Hi Emeka,

We've used http://h2database.com/ before to create a real in-memory
database to run tests against.  H2 is small and fast and works pretty
well, plus by creating your schema/data in-memory only, you don't have
to worry about file permissions or cleanup when your tests are done
running.

mrg


On Fri, Nov 9, 2012 at 6:04 PM, emeka okafor <em...@yahoo.com> wrote:
> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
> Thank you.

Re: testing with cayenne

Posted by Andrus Adamchik <an...@objectstyle.org>.
Performance tests certainly need to be run against a real database. Mock assembly won't give you the right picture.

For unit tests yeah, in you can mock ObjectContext. I am not aware of a comprehensive framework to do that, but it is doable. To me the problem with unit testing the data layer is that it is hard to scale to complex schemas with wide tables with many relationships. The test cases become too large and convoluted. So I often take my tests a level up and concentrate on testing the service layer (that works on top of the data layer). But YMMV of course, and I'd be glad to hear of a successful Cayenne data layer test approach.

In Cayenne itself we developed a set of JDBC tools to quickly create simple DB datasets:

http://svn.apache.org/repos/asf/cayenne/main/trunk/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/

But then in Cayenne we do care about testing all the way down to DB, as it is nearly impossible to mock the differences say between Oracle and Derby DBs. So we have a different focus.

Andrus


On Nov 10, 2012, at 2:34 AM, emeka okafor <em...@yahoo.com> wrote:
> Let's say, I would like to test some complex relationships of my objects, all the validations and the little things that cayenne does for you automatically. But i do not want to start a database, create table, populate them and stop a database for each test. Is there anything like a mockdatacontext? 
> 
> 
> ________________________________
> From: Robert Zeigler <ro...@roxanemy.com>
> To: user@cayenne.apache.org 
> Sent: Saturday, November 10, 2012 12:19 AM
> Subject: Re: testing with cayenne
> 
> I've done both. But using an actual database is trending toward an integration test rather than a unit test.
> 
> Robert
> 
> On Nov 9, 2012, at 11/95:04 PM , emeka okafor wrote:
> 
>> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
>> Thank you.


Re: problem starting with cayenne

Posted by emeka okafor <em...@yahoo.com>.
My Fault;
I still had this line in my application:
ServerRuntime cayenneRuntime = new ServerRuntime("cayenne.xml");
Sorry.


________________________________
 From: emeka okafor <em...@yahoo.com>
To: "user@cayenne.apache.org" <us...@cayenne.apache.org> 
Sent: Saturday, November 10, 2012 1:11 AM
Subject: problem starting with cayenne
 
My cayenne file is name cayenne-domainName.xml and so I can't seem to figure out this error:

[v.3.1B1 May 28 2012 18:42:43] Configuration resource "cayenne.xml" is not found.


I don't know why he is searching for cayenne.xml instead of cayenne-domainName.xml; I am using maven by the way.
Thanks.

problem starting with cayenne

Posted by emeka okafor <em...@yahoo.com>.
My cayenne file is name cayenne-domainName.xml and so I can't seem to figure out this error:

[v.3.1B1 May 28 2012 18:42:43] Configuration resource "cayenne.xml" is not found.


I don't know why he is searching for cayenne.xml instead of cayenne-domainName.xml; I am using maven by the way.
Thanks.

Re: testing with cayenne

Posted by emeka okafor <em...@yahoo.com>.
Let's say, I would like to test some complex relationships of my objects, all the validations and the little things that cayenne does for you automatically. But i do not want to start a database, create table, populate them and stop a database for each test. Is there anything like a mockdatacontext? 


________________________________
 From: Robert Zeigler <ro...@roxanemy.com>
To: user@cayenne.apache.org 
Sent: Saturday, November 10, 2012 12:19 AM
Subject: Re: testing with cayenne
 
I've done both. But using an actual database is trending toward an integration test rather than a unit test.

Robert

On Nov 9, 2012, at 11/95:04 PM , emeka okafor wrote:

> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
> Thank you.

Re: testing with cayenne

Posted by Robert Zeigler <ro...@roxanemy.com>.
I've done both. But using an actual database is trending toward an integration test rather than a unit test.

Robert

On Nov 9, 2012, at 11/95:04 PM , emeka okafor wrote:

> New cayenne user here. I am trying to use cayenne as the orm for an application and I was wondering how you guys write your unit test? do you test with a real database or do you have predefined mock objectcontext and son on to be able to write performant test?
> Thank you.