camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woggle23 <mattfelst...@yahoo.co.uk>
Subject Camel-test-blueprint
Date Wed, 03 Oct 2012 09:29:47 GMT
Morning

This is a repost of the topic below (which I mistakenly added to the
Developers list)

http://camel.465427.n5.nabble.com/camel-test-blueprint-tc5720280.html

Original post:

Good evening 

I've been using blueprint to define routes for my camel contexts, and would
like to create unit tests prior to deploying into servicemix, or running
integration tests using pax-exam. I note that blueprint based routes can be
pulled into unit tests using camel-test-blueprint, however, my routes
require references to a service interface (an implementation of which can be
defined in my unit test package), how do I register the implementation with
the camel-test-blueprint component so that it will be utilised when the
camelcontext initialises? 

Is anybody aware of any articles on this subject? 

Cheers 

Matt

-----------------------------------------------------------------------------------------------

Follow up post:

I've found out how to register implementations of a service, but these don't
appear to be available when the camelcontext is created. My camel-context is
defined in blueprint similar to the following: 

<reference id="cameraManager"
interface="org.myCompany.cameramanager.CameraManager">

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
    <route id="test-route">
      <from uri="direct:start"/>
        <bean ref="cameraManager" method="getAllCameras" />
      <to uri="mock:a"/>
    </route>
</camelContext>

I've created a second blueprint file, for the purpose of the test, which
exposes an implementation of CameraManager as a service, the contents of
which is as follows: 

<bean id="cameraManagerImpl"
class="org.myCompany.cameramanagerimpl.CameraManagerImpl" />
<service
ref="cameraManagerImpl"interface="org.myCompany.cameramanager.CameraManager"
/>

My getBlueprintDescriptor() method in the test returns both blueprint
descriptor files (the service implementing file first). The test fails as
the camel context isn't able to resolve dependencies for
org.myCompany.cameramanager.CameraManager. 

However, if I remove my CamelContext descriptor from the
getBlueprintDescriptor() implementation in my test, when running a test I
can access the implementation of CameraManager, e.g: 

import org.myCompany.cameramanager.CameraManager; 

@testCameraManagerImpl(){ 
CameraManager cameraManager =
(CameraManager)getOsgiService(CameraManager.class); 
    ArrayList<Camera> cameras = cameraManager.getAllCameras(); 
    for (Camera camera : cameras){ 
      System.out.println(String.format("Camera id: %s", camera.getId())); 
    } 
} 

The above works, so why is the service not available to my CamelContext
during start up? Having a brief look at the CamelBlueprintHelper class in
the camel-test-blueprint component I note that a "TinyBundle" is created
containing both descriptors prior to the PojoServiceRegistry being created.
I'm not familiar with how these should be used, but is the bundle containing
both descriptors effectively starting prior to the creation of the
PojoServiceRegistry? If so, I could understand that the CameraManager
implementation isn't available. 

In short is this a bug, or am I not using this correctly? 

Please note, the test also logs all ServiceReferences, and I note that
org.myCompany.CameraManager is listed - I'm assuming that this is somehow
picked up from the Maven Dependency I have within my project? 

Any help on this would be very much appreciated! 

Cheers 

Matt



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-test-blueprint-tp5720440.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message