Oh, colleague... I have solved all the issues I faced today.

Here are my points.

1) to use the bery last approaches of Camel testing you should use
Camel Spring JUnit5 testing Kit. You can use it with following
dependensies 

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.apache.camel:camel-test-spring-junit5:3.10.0'

and annotating your test with

@ActiveProfiles("test")
@SpringBootTest(classes = MyApplication.class)
@CamelSpringBootTest
public class MyTest {

}


2) to use Advice approach you should annotate your test with
@UseAdviceWith - it makes CamelContext not to start automatically. It
is needed to apply Advices to you routes.

Then - advice your routes like:

@BeforeEach
public void init() throws Exception {
  AdviceWith.adviceWith(camelContext, "create-person", in -> {        
in.interceptSendToEndpoint(parametersProvider.getHostCardServiceEndpoin
tForCreateNewPerson()).setBody().body(ex -> "new body);
  });
  AdviceWith.adviceWith(camelContext, "issue-card", in -> {           
in.interceptSendToEndpoint(parametersProvider.getHostCardServiceEndpoin
tForIssueCard()).setBody().body(ex -> "new body);
  });
}

Prefer to use routeId for advicing.

Good luck!



On Thu, 2021-06-24 at 14:49 +0000, Steve Huston wrote:
> I got stuck on the same point... there is a good explanation in the
> Camel 3 migration guide:
> https://camel.apache.org/manual/latest/camel-3-migration-guide.html
> 
> Search for "advice" in that page.
> 
> -Steve
> 
> > -----Original Message-----
> > From: mail4...@gmail.com <mail4...@gmail.com>
> > Sent: Thursday, June 24, 2021 2:23 AM
> > To: users@camel.apache.org
> > Subject: How to adviceWith in Camel 3.10 ?
> > 
> > Hello.
> > 
> > Seems it is unable to adviceWith route definitions in Camel 3.10
> > anymore.
> > Isn't it?
> > 
> > My project is SpringBoot project with dependensies:
> > - camel-spring-boot-starter:3.10.0,
> > - spring-boot-starter-test,
> > - camel-test-spring-junit5:3.10.0
> > 
> > I got stuck on writing my test.
> > My intention is to skip original endpoint and to use mock instead of
> > it.
> > I have already tried several approaches to implement a test and my
> > last test
> > looks like:
> > 
> > @ActiveProfiles("test")
> > @CamelSpringBootTest
> > @ContextConfiguration(classes = SpreingBootApplication.class)
> > @MockEndpoints("direct://" + QUEUE_CARD_ISSUED_NOTIFICATION)
> > @UseAdviceWith public class CardIssuingTest extends CamelTestSupport
> > {
> >     // ...
> > }
> > 
> > 
> > But when I do
> > 
> > context.getRouteTemplateDefinition("my-route")
> > 
> > it returns a RouteDefinition object that does not provide
> > adviceWith()
> > method.
> > 
> > So...
> > How to adviceWith? What is the latest approach to test application
> > with
> > SpringBoot, Camel, JUnit5?
> > 
> > 
> > _________________
> > Vyacheslav Boyko,
> > mailto:mail4...@gmail.com
> 

-- 
_________________
Vyacheslav Boyko,
mailto:mail4...@gmail.com

Reply via email to