I now this is some-what unrelated to the original topic, but as we are talking of unit tests...

Is there a way to avoid accessing / initializing a DB in order to be able to use Cayenne generated models? I mean, most of my "business logic" unit tests / specs time is consumed by configuring cayenne access to an in-memory derby db.

As far as I understand how cayenne works I could avoid some of this time by having some "persistent" (not in memory) db for unit tests & similar; but... is there a way to use models without accessing the db?

I someone considers this merits its own thread, tell me and I resend it in its own topic :)

Best Regards
Juanjo

On 17/09/12 11:36, Andrus Adamchik wrote:
In your unit tests you may simply create an instance of ServerRuntime with a 
set of custom modules. Or use DIBootstrap.createInjector for more isolated 
testing of DI.
Cayenne sure takes the full advantage of DI in its own tests:

http://svn.apache.org/repos/asf/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/DICase.java
http://svn.apache.org/repos/asf/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/di/server/ServerCase.java

Not sure if that's directly applicable to your tests though, but still may give 
you some ideas.

Andrus

On Sep 17, 2012, at 10:20 AM, Juan José Gil <[email protected]> wrote:

Ok, I'll try this option to... I need it for my unit tests.
To do this I need to create an injector? Is ther a TestCase I could extend?

Regards,
Juanjo

2012/9/17 Andrus Adamchik <[email protected]>

In 3.1 you can also do that with a custom module:

  binder.bindList(Constants.SERVER_USER_TYPES_LIST)
                .add(new XyzType())
                .add(new AbcType());

Still need to document that in the new cayenne-guide.pdf. BTW, check out
org.apache.cayenne.configuration.Constants - it declares all supported
extension points. Then you may take a look at ServerModule sources to see
what Cayenne currently uses for each of those things.

Andrus

On Sep 17, 2012, at 4:22 AM, Tore Halset <[email protected]> wrote:
Hello.

I do it this way with 3.1.

           ServerRuntime runtime = .....
           DataDomain domain = runtime.getDataDomain();
           DataNode node = domain.getDataNode("mydatanode");
           ExtendedTypeMap extendedTypes =
node.getAdapter().getExtendedTypes();
           extendedTypes.registerType(new ColorType());
           extendedTypes.registerType(new
WKTGeometryType(Geometry.class));
Btw, you should use 3.1B instead of 3.1M as B is newer.

Regards,
Tore Halset.

On Sep 17, 2012, at 02:11 , Juan José Gil wrote:

Hi,

I'm trying to use 3.1M3 version and I've noted that my ExtendedType
registrations aren't working anymore.
I've looked at docs, but they don't seem to be update. So I had readed
the
unit tests at svn; but I did not understand them :(

Has anynoe already solved this problem?

The errors are:

import org.apache.cayenne.BaseContext;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.access.DataDomain;
import org.apache.cayenne.access.DataNode;
import org.apache.cayenne.conf.Configuration;

...

@Before public void setupCayenne() {
  final DataDomain domain =
Configuration.getSharedConfiguration().getDomain(); // <-- it does not
know
"Configuration"
  for (final DataNode node : domain.getDataNodes()) {


node.getAdapter().getExtendedTypes().registerType(DateTimeType.INSTANCE);

node.getAdapter().getExtendedTypes().registerType(LocalDateType.INSTANCE);

node.getAdapter().getExtendedTypes().registerType(LocalDateTimeType.INSTANCE);

node.getAdapter().getExtendedTypes().registerType(LocalTimeType.INSTANCE);
  }

  final ObjectContext context = DataContext.createDataContext(); // <--
this method doesn't exists anymore
  BaseContext.bindThreadObjectContext(context);
}

is there a sample I could reach?

Best Regards
Juanjo



Reply via email to