@Test @SuppressWarnings("resource") public void testExecutionWithApplicationContext() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("test-context.xml", getClass()); MapJobRegistry registry = (MapJobRegistry) context.getBean("registry"); Collection<String> configurations = registry.getJobNames(); // System.err.println(configurations); String[] names = context.getBeanNamesForType(JobSupport.class); int count = names.length; // Each concrete bean of type JobConfiguration is registered... assertEquals(count, configurations.size()); // N.B. there is a failure / wonky mode where a parent bean is given an // explicit name or beanName (using property setter): in this case then // child beans will have the same name and will be re-registered (and // override, if the registry supports that). assertNotNull(registry.getJob("test-job")); assertEquals(context.getBean("test-job-with-name"), registry.getJob("foo")); assertEquals(context.getBean("test-job-with-bean-name"), registry.getJob("bar")); assertEquals(context.getBean("test-job-with-parent-and-name"), registry.getJob("spam")); assertEquals(context.getBean("test-job-with-parent-and-bean-name"), registry.getJob("bucket")); assertEquals(context.getBean("test-job-with-concrete-parent"), registry.getJob("maps")); assertEquals(context.getBean("test-job-with-concrete-parent-and-name"), registry.getJob("oof")); assertEquals(context.getBean("test-job-with-concrete-parent-and-bean-name"), registry.getJob("rab")); }
/** * Test method for {@link org.springframework.batch.core.configuration.support.MapJobRegistry#unregister(String)}. * @throws Exception */ public void testUnregister() throws Exception { registry.register(new ReferenceJobFactory(new JobSupport("foo"))); assertNotNull(registry.getJob("foo")); registry.unregister("foo"); try { assertNull(registry.getJob("foo")); fail("Expected NoSuchJobConfigurationException"); } catch (NoSuchJobException e) { // expected assertTrue(e.getMessage().indexOf("foo")>=0); } }
@Test public void testLocateJob() throws Exception { Resource[] jobPaths = new Resource[] { new ClassPathResource("org/springframework/batch/core/launch/support/job.xml"), new ClassPathResource("org/springframework/batch/core/launch/support/job2.xml") }; @SuppressWarnings("resource") GenericApplicationContext applicationContext = new GenericApplicationContext(); applicationContext.refresh(); setUpApplicationContextFactories(jobPaths, applicationContext); registrar.setApplicationContext(applicationContext); registrar.start(); Collection<String> names = registry.getJobNames(); assertEquals(2, names.size()); assertTrue(names.contains("test-job")); assertTrue(names.contains("test-job2")); Job job = registry.getJob("test-job"); assertEquals("test-job", job.getName()); job = registry.getJob("test-job2"); assertEquals("test-job2", job.getName()); }