/** * Set up a {@link JobExecution} as a test context attribute. * * @param testContext the current test context * @throws Exception if there is a problem * @see TestExecutionListener#prepareTestInstance(TestContext) */ @Override public void prepareTestInstance(TestContext testContext) throws Exception { JobExecution jobExecution = getJobExecution(testContext); if (jobExecution != null) { testContext.setAttribute(JOB_EXECUTION, jobExecution); } }
@Test public void testDefaultJobContext() throws Exception { TestContext testContext = getTestContext(new Object()); listener.prepareTestInstance(testContext); listener.beforeTestMethod(testContext); JobContext context = JobSynchronizationManager.getContext(); assertNotNull(context); listener.afterTestMethod(testContext); assertNull(JobSynchronizationManager.getContext()); }
private void testExecutionContext(Object target) throws Exception { TestContext testContext = getTestContext(target); listener.prepareTestInstance(testContext); try { listener.beforeTestMethod(testContext); JobContext context = JobSynchronizationManager.getContext(); assertNotNull(context); assertEquals("bar", context.getJobExecutionContext().get("foo")); } finally { listener.afterTestMethod(testContext); } assertNull(JobSynchronizationManager.getContext()); }
private void testJobParameters(Object target) throws Exception { TestContext testContext = getTestContext(target); listener.prepareTestInstance(testContext); try { listener.beforeTestMethod(testContext); JobContext context = JobSynchronizationManager.getContext(); assertNotNull(context); assertEquals("spam", context.getJobParameters().get("foo")); } finally { listener.afterTestMethod(testContext); } assertNull(JobSynchronizationManager.getContext()); }