private void saveAndAssert(final StepExecution stepExecution, final String value) { new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { stepExecution.getExecutionContext().put("foo", value); dao.saveExecutionContext(stepExecution); return null; } }); ExecutionContext executionContext = dao.getExecutionContext(stepExecution); Assert.state(executionContext != null, "Lost insert: null executionContext at value=" + value); String foo = executionContext.getString("foo"); Assert.state(value.equals(foo), "Lost update: wrong value=" + value + " (found " + foo + ") for id=" + stepExecution.getId()); }
@Test public void testTransactionalSaveUpdate() throws Exception { final StepExecution stepExecution = new StepExecution("step", new JobExecution(11L)); stepExecution.setId(123L); new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { stepExecution.getExecutionContext().put("foo", "bar"); dao.saveExecutionContext(stepExecution); return null; } }); ExecutionContext executionContext = dao.getExecutionContext(stepExecution); assertEquals("bar", executionContext.get("foo")); }
@Test public void testSaveUpdate() throws Exception { StepExecution stepExecution = new StepExecution("step", new JobExecution(11L)); stepExecution.setId(123L); stepExecution.getExecutionContext().put("foo", "bar"); dao.saveExecutionContext(stepExecution); ExecutionContext executionContext = dao.getExecutionContext(stepExecution); assertEquals("bar", executionContext.get("foo")); }
@Test public void testPersistentCopy() throws Exception { MapExecutionContextDao tested = new MapExecutionContextDao(); JobExecution jobExecution = new JobExecution((long)1); StepExecution stepExecution = new StepExecution("stepName", jobExecution, 123L); assertTrue(stepExecution.getExecutionContext().isEmpty()); tested.updateExecutionContext(stepExecution); stepExecution.getExecutionContext().put("key","value"); ExecutionContext retrieved = tested.getExecutionContext(stepExecution); assertTrue(retrieved.isEmpty()); tested.updateExecutionContext(jobExecution); jobExecution.getExecutionContext().put("key", "value"); retrieved = tested.getExecutionContext(jobExecution); assertTrue(retrieved.isEmpty()); }
@Test public void testSaveBothJobAndStepContextWithSameId() throws Exception { MapExecutionContextDao tested = new MapExecutionContextDao(); JobExecution jobExecution = new JobExecution(1L); StepExecution stepExecution = new StepExecution("stepName", jobExecution, 1L); assertTrue(stepExecution.getId() == jobExecution.getId()); jobExecution.getExecutionContext().put("type", "job"); stepExecution.getExecutionContext().put("type", "step"); assertTrue(!jobExecution.getExecutionContext().get("type").equals(stepExecution.getExecutionContext().get("type"))); assertEquals("job", jobExecution.getExecutionContext().get("type")); assertEquals("step", stepExecution.getExecutionContext().get("type")); tested.saveExecutionContext(jobExecution); tested.saveExecutionContext(stepExecution); ExecutionContext jobCtx = tested.getExecutionContext(jobExecution); ExecutionContext stepCtx = tested.getExecutionContext(stepExecution); assertEquals("job", jobCtx.get("type")); assertEquals("step", stepCtx.get("type")); }