You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Per Newgro <pe...@gmx.ch> on 2008/05/02 11:30:45 UTC

Testing with IModel mocks

Hi *,

i try to test a page with some panels. They all get their models thru the 
constructor. The assigned models are always implementing IModel. At the 
highest level (page) there is a CompoundPropertyModel and all sub-components 
use a chain of PropertyModels. So far so good.

Now i try to use "easymock - interface api" to unit test the page. I assign 
the mock proxy (IMpdel) to the page and the sub-components should get their 
part of the model. The problem is that i can't find a way to give the 
sub-component an appropriate new IModel mock proxy, because on the original 
IModel only getObject() will be called. I don't have the abillity to 
distinguish by property expression.

Another way would be to use the class extension of easymock. But i would like 
to avoid it. Maybe someone solved this issue somehow with only usage of the 
easymock - interface api.

I hope i made my points clear.

Thanks
Per

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Testing with IModel mocks

Posted by Per Newgro <pe...@gmx.ch>.
Am Freitag, 2. Mai 2008 12:22:53 schrieb James Carman:
> I don't usually mock the actual models.  If I'm using a
> LoadableDetachableModel, I'll mock the DAO or "repository" that the
> model is using to find its data, but I never actually mock the model
> itself.
But then i have to know the structures "under the IModel". Don't misunderstand 
me. I don't mean IModel and wicket related structures - i mean stuff from the 
IModel.getObject() instance (business object). And that's exactly what i try 
to avoid. I only try to access everything by the property name.

The background is the following:
In our project everyone has access to "business model instances". They simply 
get the interface and call the appropriate (get/set) method. We now tried to 
refactor some code and found that we have "deployed" business logic all over 
our panels and pages. Thats because you can access deeper model by the 
accessor chain. That sucks :-).

So i set up a little test project. In this the frontend components have only 
access to the "business interfaces". Within this you only have some methods 
defined like "doMyBusinessStuff()". There are no more getMyModel() and stuff 
like that. 
The accessible way for component binding is using a constant for property name 
in association with a PropertyModel. The real accessor methods 
(getter/setter) are departed in another "accessor interface" which can't be 
used from within the frontend (and thus is hidden for frontend tests to).

So i would like to ignore the "accessor interfaces" and only use the calls for 
the propertyname to return the appropriate IModel instance.

Thanks
Per

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Testing with IModel mocks

Posted by James Carman <ja...@carmanconsulting.com>.
I don't usually mock the actual models.  If I'm using a
LoadableDetachableModel, I'll mock the DAO or "repository" that the
model is using to find its data, but I never actually mock the model
itself.

On Fri, May 2, 2008 at 5:30 AM, Per Newgro <pe...@gmx.ch> wrote:
> Hi *,
>
>  i try to test a page with some panels. They all get their models thru the
>  constructor. The assigned models are always implementing IModel. At the
>  highest level (page) there is a CompoundPropertyModel and all sub-components
>  use a chain of PropertyModels. So far so good.
>
>  Now i try to use "easymock - interface api" to unit test the page. I assign
>  the mock proxy (IMpdel) to the page and the sub-components should get their
>  part of the model. The problem is that i can't find a way to give the
>  sub-component an appropriate new IModel mock proxy, because on the original
>  IModel only getObject() will be called. I don't have the abillity to
>  distinguish by property expression.
>
>  Another way would be to use the class extension of easymock. But i would like
>  to avoid it. Maybe someone solved this issue somehow with only usage of the
>  easymock - interface api.
>
>  I hope i made my points clear.
>
>  Thanks
>  Per
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org