Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. @ApplicationScoped
  2. public class TransactionScopeLifecycleEventsTest {
  3.  
  4. private static boolean initializedObserved;
  5.  
  6. private AutoCloseable container;
  7.  
  8. @Before
  9. public void setUp() throws Exception {
  10. this.tearDown();
  11. final Weld weld = new Weld()
  12. .addExtension(new TransactionExtension())
  13. .addBeanClass(this.getClass());
  14. this.container = weld.initialize();
  15. }
  16.  
  17. @After
  18. public void tearDown() throws Exception {
  19. if (this.container != null) {
  20. this.container.close();
  21. this.container = null;
  22. }
  23. }
  24.  
  25. private static void onStartup(@Observes @Initialized(ApplicationScoped.class) final Object event,
  26. final TransactionScopeLifecycleEventsTest self) throws SystemException {
  27. self.doSomethingTransactional();
  28. }
  29.  
  30. @Transactional
  31. void doSomethingTransactional() throws SystemException {
  32.  
  33. }
  34.  
  35. void transactionScopeActivated(@Observes @Initialized(TransactionScoped.class) final Object event) {
  36. assertNotNull(event);
  37. initializedObserved = true;
  38. }
  39.  
  40. @Test
  41. public void testIt() throws Exception {
  42. assert initializedObserved;
  43. initializedObserved = false;
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement