/** * Unregister all the {@link Job} instances that were registered by this * post processor. * @see org.springframework.beans.factory.DisposableBean#destroy() */ private void destroy() throws Exception { jobLoader.clear(); }
@Override public String toString() { return "ResourceXmlApplicationContext:" + getId(); }
@Override public String toString() { return "ResourceAnnotationApplicationContext:" + getId(); }
@PostConstruct public void initialize() { registrar.addApplicationContextFactory(new GenericApplicationContextFactory(TestConfiguration.class)); registrar.addApplicationContextFactory(new GenericApplicationContextFactory(VanillaConfiguration.class)); }
private void setUpApplicationContextFactories(Resource[] jobPaths, ApplicationContext parent) { Collection<ApplicationContextFactory> applicationContextFactories = new ArrayList<>(); for (Resource resource : jobPaths) { GenericApplicationContextFactory factory = new GenericApplicationContextFactory(resource); factory.setApplicationContext(parent); applicationContextFactories.add(factory); } registrar.setApplicationContextFactories(applicationContextFactories .toArray(new ApplicationContextFactory[jobPaths.length])); }
@Test public void testStartStopRunning() throws Exception { Resource[] jobPaths = new Resource[] { new ClassPathResource( "org/springframework/batch/core/launch/support/2jobs.xml") }; setUpApplicationContextFactories(jobPaths, null); registrar.start(); assertTrue(registrar.isRunning()); registrar.start(); assertEquals(2, registry.getJobNames().size()); registrar.stop(); assertFalse(registrar.isRunning()); }
@Before public void setUp() { DefaultJobLoader jobLoader = new DefaultJobLoader(); jobLoader.setJobRegistry(registry); registrar.setJobLoader(jobLoader); }
/** * Test method for {@link org.springframework.batch.core.configuration.support.MapJobRegistry#getJobNames()}. * @throws Exception */ public void testGetJobConfigurations() throws Exception { JobFactory jobFactory = new ReferenceJobFactory(new JobSupport("foo")); registry.register(jobFactory); registry.register(new ReferenceJobFactory(new JobSupport("bar"))); Collection<String> configurations = registry.getJobNames(); assertEquals(2, configurations.size()); assertTrue(configurations.contains(jobFactory.getJobName())); }
/** * Test method for {@link org.springframework.batch.core.configuration.support.MapJobRegistry#getJob(java.lang.String)}. */ public void testReplaceDuplicateConfiguration() throws Exception { registry.register(new ReferenceJobFactory(new JobSupport("foo"))); try { registry.register(new ReferenceJobFactory(new JobSupport("foo"))); fail("Expected DuplicateJobConfigurationException"); } catch (DuplicateJobException e) { // unexpected: even if the job is different we want a DuplicateJobException assertTrue(e.getMessage().indexOf("foo")>=0); } }
@Test public void createWithOnlyJobRegistry() { final DefaultJobLoader loader = new DefaultJobLoader(); loader.setJobRegistry(jobRegistry); loader.afterPropertiesSet(); }
@Override public Collection<Job> load(ApplicationContextFactory factory) throws DuplicateJobException { return doLoad(factory, false); }
/** * @param jobName the id of the {@link Job} in the application context to be * created * @param applicationContextFactory a factory for an application context * containing a job with the job name provided */ public ApplicationContextJobFactory(String jobName, ApplicationContextFactory applicationContextFactory) { @SuppressWarnings("resource") ConfigurableApplicationContext context = applicationContextFactory.createApplicationContext(); this.job = context.getBean(jobName, Job.class); }
protected abstract ConfigurableApplicationContext createApplicationContext(ConfigurableApplicationContext parent, Object... resources);
@Override protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { super.prepareBeanFactory(beanFactory); helper.prepareBeanFactory(beanFactory); }
@Test public void testPostProcessing() throws Exception { ApplicationContextJobFactory factory = new ApplicationContextJobFactory("job", new PostProcessingApplicationContextFactory()); assertEquals("bar", factory.getJobName()); }
@Test public void testFactoryContext() throws Exception { ApplicationContextJobFactory factory = new ApplicationContextJobFactory("job", new StubApplicationContextFactory()); assertNotNull(factory.createJob()); }
@Test public void getJobNotRegisteredNoRegistration() { final StepRegistry stepRegistry = createRegistry(); assertJobNotRegistered(stepRegistry, "a ghost"); }
protected StepRegistry createRegistry() { return new MapStepRegistry(); }
@Test public void testClear() throws Exception { Resource[] jobPaths = new Resource[] { new ClassPathResource( "org/springframework/batch/core/launch/support/2jobs.xml") }; setUpApplicationContextFactories(jobPaths, null); registrar.start(); assertEquals(2, registry.getJobNames().size()); registrar.stop(); assertEquals(0, registry.getJobNames().size()); }
/** * Delegates to {@link JobLoader#clear()}. * * @see Lifecycle#stop() */ @Override public void stop() { synchronized (this.lifecycleMonitor) { jobLoader.clear(); running = false; } }