cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matero <mat...@gmail.com>
Subject Re: Unit Testing cayenne apps
Date Tue, 23 Apr 2013 16:34:25 GMT
That's awesome!
I'll give it a try tonight and tell you how it was 

If I succeed with this approach, I'll blog about it to make a note to future me ;)

Enviado desde mi iPad

El 23/04/2013, a las 11:42, John Huss <johnthuss@gmail.com> escribió:

> You can configure the database connection in 3.1 with a module like:
> 
> import org.apache.cayenne.configuration.Constants;
> import org.apache.cayenne.di.Binder;
> import org.apache.cayenne.di.Module;
> 
> public class AppModule implements Module {
> public void configure(Binder binder) {
> binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_URL_PROPERTY,
> "jdbc:postgresql://localhost/mydb");
> binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_DRIVER_PROPERTY,
> org.postgresql.Driver.class.getName());
> }
> 
> }
> 
> You just have to list your module when creating the ServerRuntime:
> 
> CayenneRuntime runtime = new ServerRuntime("cayenne-MyDomain.xml", new
> AppModule());
> 
> It can also be specified in web.xml instead if you are using CayenneFilter
> or something.
> 
> The JDBC_URL_PROPERTY will override the url for all databases.  If you have
> more than one you'll want to override each independently by appending the
> domain name and dataNode name to the property name, like:
> 
> binder.bindMap(Constants.PROPERTIES_MAP).put(Constants.JDBC_URL_PROPERTY +
> ".MyDomain.MyDataNode", "jdbc:postgresql://localhost/mydb");
> 
> The specific url value or driver value you are using doesn't have to be
> hard coded.  You can read it from a file or from the system properties set
> on the command line - whatever you want.
> 
> John
> 
> 
> 
> On Tue, Apr 23, 2013 at 7:05 AM, Juan José Gil <matero@gmail.com> wrote:
> 
>> Hi, I'm using cayenne as persistence layer.
>> 
>> The project is builded with maven and developed with Eclipse.
>> 
>> The DB is migrated using flyway (http://flywaydb.org/) and I'm using
>> different DBs config for:
>> 
>> * production
>> * development
>> * testing
>> 
>> So, for migrations, deployment, continuous integration and anything that
>> relies on maven I'm using maven "filtering" capabilities to define the jdbc
>> url of the database to be used.
>> 
>> BUT when I'm working at eclipse, and try to run my tests / startup my
>> webapp, I cant filter the project resources (not automatically at least)
>> So currently I'm copy-pasting my cayenne conf from src/main/resources/db to
>> src/test/resources/db... and I'm not happy with this solution, I feel it
>> smelly, propense to failure, it's ugly, very ugly!
>> 
>> I did try to only define the cayenne config at testing resources, but when
>> I do that, it doesn't find the mapping xml.
>> 
>> Is there a way con pass the mapping path instead of a mapping name to a
>> cayenne config?
>> 
>> Can someone point me what should be done to avoid this code/conf smell?
>> 

Mime
View raw message