@Test public void testJobRepositoryDefaults() throws Exception { ApplicationContext ctx = stepParserParentAttributeTestsCtx; assertTrue(getJobRepository("defaultRepoStep", ctx) instanceof SimpleJobRepository); assertTrue(getJobRepository("defaultRepoStepWithParent", ctx) instanceof SimpleJobRepository); assertTrue(getJobRepository("overrideRepoStep", ctx) instanceof SimpleJobRepository); assertDummyJobRepository("injectedRepoStep", "dummyJobRepository", ctx); assertDummyJobRepository("injectedRepoStepWithParent", "dummyJobRepository", ctx); assertDummyJobRepository("injectedOverrideRepoStep", "dummyJobRepository", ctx); assertDummyJobRepository("injectedRepoFromParentStep", "dummyJobRepository2", ctx); assertDummyJobRepository("injectedRepoFromParentStepWithParent", "dummyJobRepository2", ctx); assertDummyJobRepository("injectedOverrideRepoFromParentStep", "dummyJobRepository2", ctx); assertTrue(getJobRepository("defaultRepoStandaloneStep", ctx) instanceof SimpleJobRepository); assertDummyJobRepository("specifiedRepoStandaloneStep", "dummyJobRepository2", ctx); }
@Test public void testTransactionManagerDefaults() throws Exception { ApplicationContext ctx = stepParserParentAttributeTestsCtx; assertTrue(getTransactionManager("defaultTxMgrStep", ctx) instanceof ResourcelessTransactionManager); assertDummyTransactionManager("specifiedTxMgrStep", "dummyTxMgr", ctx); assertDummyTransactionManager("defaultTxMgrWithParentStep", "dummyTxMgr", ctx); assertDummyTransactionManager("overrideTxMgrOnParentStep", "dummyTxMgr2", ctx); }
@SuppressWarnings("unchecked") @Test public void testStepWithListsNoMerge() throws Exception { ApplicationContext ctx = stepParserParentAttributeTestsCtx; Map<Class<? extends Throwable>, Boolean> skippable = new HashMap<>(); skippable.put(SkippableException.class, true); skippable.put(FatalSkippableException.class, false); skippable.put(ForceRollbackForWriteSkipException.class, true); Map<Class<? extends Throwable>, Boolean> retryable = new HashMap<>(); retryable.put(FatalSkippableException.class, true); retryable.put(ForceRollbackForWriteSkipException.class, true); List<Class<CompositeItemStream>> streams = Arrays.asList(CompositeItemStream.class); List<Class<DummyRetryListener>> retryListeners = Arrays.asList(DummyRetryListener.class); List<Class<CompositeStepExecutionListener>> stepListeners = Arrays.asList(CompositeStepExecutionListener.class); List<Class<SkippableRuntimeException>> noRollback = Arrays.asList(SkippableRuntimeException.class); StepParserStepFactoryBean<?, ?> fb = (StepParserStepFactoryBean<?, ?>) ctx.getBean("&stepWithListsNoMerge"); Map<Class<? extends Throwable>, Boolean> skippableFound = getExceptionMap(fb, "skippableExceptionClasses"); Map<Class<? extends Throwable>, Boolean> retryableFound = getExceptionMap(fb, "retryableExceptionClasses"); ItemStream[] streamsFound = (ItemStream[]) ReflectionTestUtils.getField(fb, "streams"); RetryListener[] retryListenersFound = (RetryListener[]) ReflectionTestUtils.getField(fb, "retryListeners"); Set<StepExecutionListener> stepListenersFound = (Set<StepExecutionListener>) ReflectionTestUtils.getField(fb, "stepExecutionListeners"); Collection<Class<? extends Throwable>> noRollbackFound = getExceptionList(fb, "noRollbackExceptionClasses"); assertSameMaps(skippable, skippableFound); assertSameMaps(retryable, retryableFound); assertSameCollections(streams, toClassCollection(streamsFound)); assertSameCollections(retryListeners, toClassCollection(retryListenersFound)); assertSameCollections(stepListeners, toClassCollection(stepListenersFound)); assertSameCollections(noRollback, noRollbackFound); }
@SuppressWarnings("unchecked") @Test public void testStepWithListsOverrideWithEmpty() throws Exception { ApplicationContext ctx = stepParserParentAttributeTestsCtx; StepParserStepFactoryBean<?, ?> fb = (StepParserStepFactoryBean<?, ?>) ctx .getBean("&stepWithListsOverrideWithEmpty"); assertEquals(1, getExceptionMap(fb, "skippableExceptionClasses").size()); assertEquals(1, getExceptionMap(fb, "retryableExceptionClasses").size()); assertEquals(0, ((ItemStream[]) ReflectionTestUtils.getField(fb, "streams")).length); assertEquals(0, ((RetryListener[]) ReflectionTestUtils.getField(fb, "retryListeners")).length); assertEquals(0, ((Set<StepExecutionListener>) ReflectionTestUtils.getField(fb, "stepExecutionListeners")).size()); assertEquals(0, getExceptionList(fb, "noRollbackExceptionClasses").size()); }
@Test @SuppressWarnings("resource") public void testStepParserCompletionPolicy() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/StepParserCompletionPolicyTests-context.xml"); Map<String, Step> beans = ctx.getBeansOfType(Step.class); assertTrue("'s1' bean not found", beans.containsKey("s1")); Step s1 = (Step) ctx.getBean("s1"); CompletionPolicy completionPolicy = getCompletionPolicy(s1); assertTrue(completionPolicy instanceof DummyCompletionPolicy); }
private PlatformTransactionManager getTransactionManager(String beanName, ApplicationContext ctx) throws Exception { Object jobRepository = getFieldFromBean(beanName, "transactionManager", ctx); assertTrue(jobRepository instanceof PlatformTransactionManager); return (PlatformTransactionManager) jobRepository; }
@Test public void testParentStep() throws Exception { ApplicationContext ctx = stepParserParentAttributeTestsCtx; // Inline Step assertTrue(getListener("s1", ctx) instanceof StepExecutionListenerSupport); // Standalone Step assertTrue(getListener("s2", ctx) instanceof StepExecutionListenerSupport); // Inline With Tasklet Attribute Step assertTrue(getListener("s3", ctx) instanceof StepExecutionListenerSupport); // Standalone With Tasklet Attribute Step assertTrue(getListener("s4", ctx) instanceof StepExecutionListenerSupport); }
private void assertDummyJobRepository(String beanName, String jobRepoName, ApplicationContext ctx) throws Exception { JobRepository jobRepository = getJobRepository(beanName, ctx); assertTrue(jobRepository instanceof DummyJobRepository); assertEquals(jobRepoName, ((DummyJobRepository) jobRepository).getName()); }
@Test @SuppressWarnings("resource") public void testStepParserCommitInterval() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "org/springframework/batch/core/configuration/xml/StepParserCommitIntervalTests-context.xml"); Map<String, Step> beans = ctx.getBeansOfType(Step.class); assertTrue("'s1' bean not found", beans.containsKey("s1")); Step s1 = (Step) ctx.getBean("s1"); CompletionPolicy completionPolicy = getCompletionPolicy(s1); assertTrue(completionPolicy instanceof SimpleCompletionPolicy); assertEquals(25, ReflectionTestUtils.getField(completionPolicy, "chunkSize")); }
private JobRepository getJobRepository(String beanName, ApplicationContext ctx) throws Exception { Object jobRepository = getFieldFromBean(beanName, "jobRepository", ctx); assertTrue(jobRepository instanceof JobRepository); return (JobRepository) jobRepository; }
Map<Class<? extends Throwable>, Boolean> skippableFound = getExceptionMap(fb, "skippableExceptionClasses"); Map<Class<? extends Throwable>, Boolean> retryableFound = getExceptionMap(fb, "retryableExceptionClasses"); ItemStream[] streamsFound = (ItemStream[]) ReflectionTestUtils.getField(fb, "streams"); RetryListener[] retryListenersFound = (RetryListener[]) ReflectionTestUtils.getField(fb, "retryListeners"); Set<StepExecutionListener> stepListenersFound = (Set<StepExecutionListener>) ReflectionTestUtils.getField(fb, "stepExecutionListeners"); Collection<Class<? extends Throwable>> noRollbackFound = getExceptionList(fb, "noRollbackExceptionClasses"); assertSameMaps(skippable, skippableFound); assertSameMaps(retryable, retryableFound); assertSameCollections(streams, toClassCollection(streamsFound)); assertSameCollections(retryListeners, toClassCollection(retryListenersFound)); assertSameCollections(stepListeners, toClassCollection(stepListenersFound)); assertSameCollections(noRollback, noRollbackFound);