Skip to content

Instantly share code, notes, and snippets.

@PiotrNowicki
Created October 6, 2012 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PiotrNowicki/3846509 to your computer and use it in GitHub Desktop.
Save PiotrNowicki/3846509 to your computer and use it in GitHub Desktop.
Arquillian persistence problem
@Test
public void dataIsPopulated() {
// given populated cache
// when
List<Question> questions = cut.getQuestions();
// then
assertThat(questions.size()).isEqualTo(3);
}
@Test
//@Transactional(TransactionMode.ROLLBACK)
public void updateGeneratesEvent() throws NotSupportedException, SystemException {
utx.begin();
// given
Question question = cut.getQuestions().get(0);
// when
question.setSummary("My test summary");
cut.updateQuestion(question);
// then
Question actual = cut.getQuestionById(question.getId());
assertThat(actual.getSummary()).isEqualTo("My test summary");
utx.rollback();
}
@bartoszmajsak
Copy link

The trick is that APE cleans your db for each and every tests, to have it somehow "isolated". I know it's not really what you would expect from plain @transactional (a bit too much convention here ;)), that's why I'm working on moving JTA transaction to its own module (for next version - Alpha6). If you want to turn off clean-up use @cleanup(NONE) on class level.

@PiotrNowicki
Copy link
Author

Works like a charm mate! I put @Cleanup(phase = TestExecutionPhase.NONE) at the class level and @Transactional(TransactionMode.ROLLBACK) for each transactional method that should be rolled-back.

Thanks once again - I'll look forward to watching JTA module arriving :-)

BTW: great job with this APE :-)

@bartoszmajsak
Copy link

JTA module is already there, just hidden in APE internals hehe. Having kinda headache with it currently :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment