Search in sources :

Example 1 with JobRegistry

use of org.springframework.batch.core.configuration.JobRegistry in project camel by apache.

the class SpringBatchEndpointTest method shouldInjectJobRegistryByReferenceName.

@Test
public void shouldInjectJobRegistryByReferenceName() throws Exception {
    // Given
    Job mockJob = mock(Job.class);
    when(jobRegistry.getJob(eq("mockJob"))).thenReturn(mockJob);
    context().addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:jobRegistryRefTest").to("spring-batch:mockJob?jobRegistry=#jobRegistry");
        }
    });
    // When
    template.sendBody("direct:jobRegistryRefTest", "Start the job, please.");
    // Then
    SpringBatchEndpoint batchEndpoint = context().getEndpoint("spring-batch:mockJob?jobRegistry=#jobRegistry", SpringBatchEndpoint.class);
    JobRegistry batchEndpointJobRegistry = (JobRegistry) FieldUtils.readField(batchEndpoint, "jobRegistry", true);
    assertSame(jobRegistry, batchEndpointJobRegistry);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) JobRegistry(org.springframework.batch.core.configuration.JobRegistry) Job(org.springframework.batch.core.Job) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Example 2 with JobRegistry

use of org.springframework.batch.core.configuration.JobRegistry in project camel by apache.

the class SpringBatchEndpointTest method shouldUseJobRegistryFromComponent.

@Test
public void shouldUseJobRegistryFromComponent() throws Exception {
    // Given
    SpringBatchComponent batchComponent = new SpringBatchComponent();
    batchComponent.setJobRegistry(jobRegistry);
    batchComponent.setJobLauncher(jobLauncher);
    context.addComponent("customBatchComponent", batchComponent);
    // When
    context().addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:startCustom").to("customBatchComponent:mockJob");
        }
    });
    // Then
    SpringBatchEndpoint batchEndpoint = context().getEndpoint("customBatchComponent:mockJob", SpringBatchEndpoint.class);
    JobRegistry batchEndpointJobRegistry = (JobRegistry) FieldUtils.readField(batchEndpoint, "jobRegistry", true);
    assertSame(jobRegistry, batchEndpointJobRegistry);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) JobRegistry(org.springframework.batch.core.configuration.JobRegistry) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) Test(org.junit.Test)

Aggregations

FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 Test (org.junit.Test)2 JobRegistry (org.springframework.batch.core.configuration.JobRegistry)2 Job (org.springframework.batch.core.Job)1