Re: How to create EOClassDescription in test code?
Re: How to create EOClassDescription in test code?
- Subject: Re: How to create EOClassDescription in test code?
- From: Chuck Hill <email@hidden>
- Date: Tue, 28 Oct 2003 20:04:13 -0800
Hi,
At 12:20 AM 29/10/2003 +0100, Erlandsson Martin wrote:
>
>I am trying to create a dumb mock subclass (for unit tests) below an
entity class that extends EOGenericRecord. In order to be able to do that,
I need to create an EOClassDescription instance corresponding to my entity
class. How can I do this in a unit test context?
>
>I have tried all methods that return EOClassDescription, but I they all
produce a null result.
>Example:
>
> EOClassDescription eocd =
EOClassDescription.classDescriptionForEntityName("EntityClass"); //eocd is
null after this line
>
EntityClass must be the name of the *Entity* in the EOModel, not the name
of the implementing class. You can get it from the class using
classDescriptionForClass(EntityClass.class)
>
>A post I found pointed out that the model must (of course) be available
for a class description to be created.
>
Yes, or you can create one in code, but I don't think that is what you
should be doing in this case.
>Can the model file(s) be made available to isolated code (outside an
application context)? I tried to explicitly set the NEXT_ROOT, LOCALROOT
and WOAINSTALLROOT variables as JVM arguments in an attempt make the model
file available to the EOClassDescription methods, but no luck...
>
>Any comments about this problem or about other experiences of creating
Mocks for WO entity classes are greatly appreciated!
>
The very best way (meaning easiest and least likely to have problems) is to
ensure that the classes you are testing are in the jar file in the built
product (one of:
MyFW.framework\Resources\Java\myfw.jar
MyApp.woa\Contents\Resources\Java\myapp.jar
Then use this code to force loading of all the models:
EOModelGroup.defaultGroup().models();
You should be able to slip that into a TestSetup somewhere.
If that won't work for you, you can load them manually using
EOModel aModel = new EOModel(path);
EOModelGroup.defaultGroup().addModel(aModel);
or, shorter,
EOModelGroup.defaultGroup().addModelWithPath(modelPath);
Make sure you put all the models in the same group if you don't use
EOModelGroup.defaultGroup().
Chuck
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.