Hi Toni,

Thanks for your response.

So basically you are asking for mocking OSGi services in order to satisfy
> dependencies for the service under test, right ?
>

Yes, this is exactly right.


> Well Pax Exam itself will not help you directly but it does not have to.
>
> Some ideas:
>
> - You could write a mock bundle yourself (probably a lame approach, but if
> you create mock bundles per subsystem - not for each single bundle - then it
> could be a worthwhile approach) -> Benefit: you can use that mock bundle
> elsewhere, too.
>
>
Yup, I'll save that approach for when all else fails.



> - Use Tinybundles to create a bundle on-the-fly which registers mock
> versions of your services. [1].
>

I think I see how to do this using Option[] configuration() method and
provisioning multiple bundles, but is there a way to do this using
the MavenConfiguredJUnit4TestRunner?  I don't see how I'd provision another
bundle this way.


>
> - Last but not least the probably simpliest and most straightforward
> option: create & reigster the mocked services inside your test. Like you do
> with unit-tests, too. You've got everyrhing you need: decent mock fw
> (mockito for example), the BundleContext in order to register the service.
> For this approach you need to have scheduling in place for the services to
> wire up and resolve (that also depends on the higher level service framework
> you use.)
>
>
After some effort I did get this to work. I'm getting the BundleContext
injected into my test method, registering the mock services that I need, and
then performing the actual tests.  I had tried similar approaches earlier,
but was running into problems because I think I was trying to register the
services before the BundleContext had been injected.

I was not able to get mockito to work here because of an apparent conflict
where mockito exports the hamcrest interfaces which are also exported by
junit4.  Is there a known workaround for this?



> WDYT?
>

In the end the solution is actually pretty straightforward, but it sure took
a while for me to wrap my head around. Which, of course, I'll take the blame
for!  :)


cheers,
Mike


Toni
>
> [1] http://wiki.ops4j.org/display/paxexam/ExamAndTinybundles
>
>
> On Thu, Feb 17, 2011 at 12:35 AM, Mike Smoot <[email protected]> wrote:
>
>> Hi,
>>
>> I'm currently using pax-exam in a simple integration test that just checks
>> to see if the expected services get registered when the bundle starts.  This
>> is meant to be a compile time check that my Spring configuration is OK.
>>  This works great in cases with few dependencies, however some bundles
>> require many services to be present before properly starting.  I'm wondering
>> if there's an easy way to provide mock versions of these services using
>> pax-exam?
>>
>> thanks,
>> Mike
>> --
>> ____________________________________________________________
>> Michael Smoot, Ph.D.
>> UCSD Department of Medicine
>> tel: 858-822-4756
>>
>> _______________________________________________
>> general mailing list
>> [email protected]
>> http://lists.ops4j.org/mailman/listinfo/general
>>
>>
>
>
> --
> *Toni Menzel - http://www.okidokiteam.com*
>



-- 
____________________________________________________________
Michael Smoot, Ph.D.
UCSD Department of Medicine
tel: 858-822-4756
_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to