Skip to content

Instantly share code, notes, and snippets.

@ljnelson
Created March 13, 2019 19:08
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 ljnelson/15f0dfe964941538020d9f8fde4fd805 to your computer and use it in GitHub Desktop.
Save ljnelson/15f0dfe964941538020d9f8fde4fd805 to your computer and use it in GitHub Desktop.
@ApplicationScoped
public class TransactionScopeLifecycleEventsTest {
private static boolean initializedObserved;
private AutoCloseable container;
@Before
public void setUp() throws Exception {
this.tearDown();
final Weld weld = new Weld()
.addExtension(new TransactionExtension())
.addBeanClass(this.getClass());
this.container = weld.initialize();
}
@After
public void tearDown() throws Exception {
if (this.container != null) {
this.container.close();
this.container = null;
}
}
private static void onStartup(@Observes @Initialized(ApplicationScoped.class) final Object event,
final TransactionScopeLifecycleEventsTest self) throws SystemException {
self.doSomethingTransactional();
}
@Transactional
void doSomethingTransactional() throws SystemException {
}
void transactionScopeActivated(@Observes @Initialized(TransactionScoped.class) final Object event) {
assertNotNull(event);
initializedObserved = true;
}
@Test
public void testIt() throws Exception {
assert initializedObserved;
initializedObserved = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment