1
votes

I am doing unit test for my Spring Boot application with Camel. When the application runs, it can get bean which is configured as a @Component

@Component("agencyExporterProcessor")
public class AgencyExporterProcessor {}

and I get the bean like this :

 from(getTriggerExportEndpoint())
            .routeId(getTriggerExportId())
            // When shutting down, Camel will wait until the batch completed
            .shutdownRunningTask(ShutdownRunningTask.CompleteAllTasks)
            .log("[SamCustomExporter] - RouteId:${routeId} - Begin at ${date:now:MM/dd/yyyy HH:mm:ss.SSS}")
            .setHeader(Messaging.Names.SAM_DATA_AGENCY_CONFIGURATION_HEADER_KEY.toString(), constant(getConfiguration()))

            // Initialize a list to store exported CSV file names
            .bean(agencyExporterProcessor, "prepareExportedFileList")

But when I test, the route cannot get the bean"

org.apache.camel.FailedToCreateRouteException: Failed to create route agencyExporterRoute_triggerExport at: >>> Bean[ref:agencyExporterProcessor method:prepareExportedFileList] <<< in route: Route(agencyExporterRoute_triggerExport)[[From[direct:agency... because of No bean could be found in the registry for: agencyExporterProcessor

This is how I configured my unit test class:

@DirtiesContext
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
@SpringBootApplication
@SpringBootTest(classes = SamCustomExporterSpringApplication.class, 
webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class AgencyExporterRouteTest extends BaseRouteTestSupport {}

Please give advice!!!! Many thanks

1

1 Answers

0
votes

You should refer to the bean name as a String value in the Camel route:

.bean("agencyExporterProcessor", "prepareExportedFileList")