git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Integration tests with Spring annotations


Hi Damien,

Sorry for the late response, been a bit busy with Camel and Rabbit routes at work.
Did you get this to work by any chance?
If not, I think what's missing in your  test setup is the @Bean declarations in your test context. In the pastebin example you posted I saw an empty @Configuration class being passed into the test context. If you want you can also pass in the real context from the application, but that usually is overkill and not necessary (unless you're doing a full on end-to-end integration test, but there are better way to do that).
Basically your test context needs the @Bean declarations that are used by your class under test. So, if your RouteBuilder.class has @Autowired dependencies, then you either need to declare @Bean for them in the test context or provide a mock for them.

This would be part of my RestTestConfiguration.class:

...
@Bean
	public PersonServiceFacade personServiceFacade() {
		return new PersonServiceFacadeImpl();
	}

	@Bean
	public RequestContextListener requestContextListener() {
		return new RequestContextListener();
	}
 
    @Bean
    public StubProcessor stubProcessor() {
    	return new StubProcessor();
    }

    @Bean
    public WebServicesFacade testWebservicesFacade() {
		return new StubWebServicesFacadeImpl();
	}
...

And so on...


Thanks,
Valdis

-----Original Message-----
From: Damien Nicolas [mailto:dmn.nicolas@xxxxxxxxx] 
Sent: 02 October 2018 15:47
To: users@xxxxxxxxxxxxxxxx
Subject: Re: Integration tests with Spring annotations

My @Autowired are in my "RouteBuilder.class". Plus, I'm using JpaRepository (WorkflowRepository is this implementing it).
I declared my service " WorkflowService" as a bean in my configuration, but It is not referenced in the application context of the test..

Le lun. 1 oct. 2018 à 13:04, Valdis Andersons <valdis.andersons@xxxxxx> a écrit :

> Hi Damien,
>
> In your test you need specify the configuration your Camel context is 
> supposed to use. This is how we're setting it up:
>
> @Override
> protected AbstractApplicationContext createApplicationContext() {
>
>                 AbstractApplicationContext applicationContext = new 
> AnnotationConfigApplicationContext(RestTestConfiguration.class,
> SomeRouteBuilder.class, RepoFactory4Test.class);
>                 return applicationContext;
>         }
>
> In your case the bean you're looking for - WorkflowRepository, also 
> needs to be specified there. Whether you do it directly like 
> SomeRouteBuilder above or via a @Configuration class like the above 
> RestTestConfiguration and RepoFactory4Test classes is entirely up to 
> you. The Spring's ContextConfiguration class might also work there if 
> you specify the WorkflowRepository configuration on/in it.
> We keep all the common beans that all tests need in the @Configuration 
> classes and the test specific one's are then passed in directly in 
> each test case.
> While I'm not 100% certain it's the best or the most correct way of 
> doing things it's been working very reliably so far for us.
>
> Regards,
> Valdis
>
> -----Original Message-----
> From: Damien Nicolas [mailto:dmn.nicolas@xxxxxxxxx]
> Sent: 01 October 2018 10:20
> To: users@xxxxxxxxxxxxxxxx
> Subject: Re: Integration tests with Spring annotations
>
> Thanks for you reply!
>
> Here its a sample of my test configuration:
> https://scanmail.trustwave.com/?c=6600&d=hYWz26Ot-ae0hW1VlFM7GqsIjY4SG
> yMJ8Afh0VM_0Q&s=33&u=https%3a%2f%2fpastebin%2ecom%2f7C82BLGT
>
> but I always get the exception:
> Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
> No qualifying bean of type
> 'com.camel.database.repositories.WorkflowRepository' available: 
> expected at least 1 bean which qualifies as autowire candidate. 
> Dependency
> annotations:
> {@org.springframework.beans.factory.annotation.Autowired(required=true
> )}
>
>
> Le lun. 1 oct. 2018 à 09:59, Valdis Andersons 
> <valdis.andersons@xxxxxx> a écrit :
>
> > Hi Damien,
> >
> > We use Spring annotations in our integrations quite a lot and it's 
> > working rather well for us. In order to invoke the RouteBuilder 
> > instance we just provide a class name for it in the 
> > ApplicationContext of the test createApplicationContext method and 
> > then use a test configuration file to specify the endpoints for it. 
> > Then we send various messages to the endpoints and assert the 
> > results when consuming
> from the output endpoints.
> > What is you test setup, maybe you can provide a small sample to 
> > illustrate the issue you're facing?
> >
> > Regards,
> > Valdis
> >
> > -----Original Message-----
> > From: Damien Nicolas [mailto:dmn.nicolas@xxxxxxxxx]
> > Sent: 30 September 2018 19:15
> > To: users@xxxxxxxxxxxxxxxx
> > Subject: Integration tests with Spring annotations
> >
> > Hello,
> >
> > I am using CamelSpringTestSupport for an integration test with 
> > Springboot, but I cannot use the annotation as mentionned here <
> >
> http://scanmail.trustwave.com/?c=6600&d=hYWz26Ot-ae0hW1VlFM7GqsIjY4SGy
> MJ8ATnh15ohQ&s=33&u=http%3a%2f%2fcamel%2eapache%2eorg%2fspring-testing
> %2ehtml
> >.
> > I need to use "@Autowired"
> > cause I am generating routes dynamically from a database.
> > Is there a way to use Spring annotations but with the advantages of  
> >CamelSpringTestSupport (by using createRouteBuilder())?
> >
> >
> > --
> > Damien NICOLAS
> >
> > Vhi Group DAC (Vhi) is a holding company for insurance and 
> > healthcare services, which include Vhi Healthcare DAC, Vhi Insurance 
> > DAC, Vhi Health Services DAC and Vhi Investments DAC. Vhi Healthcare 
> > DAC trading as Vhi Healthcare and Vhi Insurance DAC trading as Vhi 
> > Insurance are regulated by the Central Bank of Ireland. Vhi 
> > Healthcare is tied to Vhi Insurance DAC for health insurance in 
> > Ireland which is
> underwritten by Vhi Insurance DAC.
> > Vhi Healthcare is tied to Zurich Life Assurance plc for Vhi Life 
> > Term Insurance and Vhi Mortgage Protection which is underwritten by 
> > Zurich Life Assurance plc. Vhi Healthcare is tied to Collinson 
> > Insurance Services Limited for MultiTrip Travel Insurance, 
> > Backpacker Travel Insurance and Vhi Dental Insurance which are 
> > underwritten by Great Lakes Insurance SE, UK branch and for Vhi 
> > Canada Cover and Vhi International Health Insurance which are 
> > underwritten by Astrenska Insurance Limited. For more information 
> > about the Vhi Group please go
> > to:
> > https://scanmail.trustwave.com/?c=6600&d=zvKx2wzOXtG5KKdFoKiUVWe72PA
> > V8 oVAvVe0yRENYw&s=33&u=https%3a%2f%2fwww%2evhi%2eie%2fabout-vhi
> >
> >
> > Tá Vhi Group DAC (Vhi) ina chuideachta sealbhaíochta le haghaidh 
> > seirbhísí árachais agus seirbhísí cúram sláinte, lena n-áirítear Vhi 
> > Healthcare DAC, Vhi Insurance DAC, Vhi Health Services DAC agus Vhi
> Investments DAC.
> > Déanann Banc Ceannais na hÉireann rialáil ar Vhi Healthcare DAC, ag 
> > trádáil dó mar Vhi Healthcare, agus ar Vhi Insurance DAC, ag trádáil 
> > dó mar Vhi Insurance. Tá Vhi Healthcare ceangailte le Vhi Insurance 
> > DAC le haghaidh árachas sláinte in Éirinn, rud atá frithgheallta ag 
> > Vhi Insurance DAC. Tá Vhi Healthcare ceangailte le Zurich Life 
> > Assurance plc le haghaidh Árachais Saoil de chuid Vhi agus Árachas 
> > Cosanta Morgáiste de chuid Vhi atá frithgheallta ag Zurich Life 
> > Assurance plc. Tá Vhi Healthcare ceangailte le Collinson Insurance 
> > Services Limited le haghaidh Árachas Taistil Ilturais agus Turasóirí 
> > Mála Droma agus Árachas Fiaclóireachta de chuid Vhi atá 
> > frithgheallta ag Great Lakes Insurance SE, UK branch agus le 
> > haghaidh Clúdach Cheanada de chuid Vhi agus Árachas Sláinte 
> > Idirnáisiúnta de chuid Vhi atá frithgheallta ag Astrenska Insurance 
> > Limited. Chun tuilleadh
> faisnéise a fháil faoi Ghrúpa Vhi, tabhair cuairt ar:
> > https://scanmail.trustwave.com/?c=6600&d=zvKx2wzOXtG5KKdFoKiUVWe72PA
> > V8 oVAvVe0yRENYw&s=33&u=https%3a%2f%2fwww%2evhi%2eie%2fabout-vhi
> >
> > This e-mail and any files transmitted with it contain information 
> > which may be confidential and which may also be privileged and is 
> > intended solely for the use of the individual or entity to whom it 
> > is addressed. Unless you are the intended recipient you may not copy 
> > or use it, or disclose it to anyone else. Any opinions expressed are 
> > that of the individual and not necessarily that of the Vhi Group. If 
> > you have received this e-mail in error please notify the sender by return.
> >
> >
> >
> >
> >
> >
> >
>
> --
> Damien NICOLAS
>


--
Damien NICOLAS