Created
March 11, 2019 19:22
-
-
Save ljnelson/7581a3f55dbb0f027e6463bd60033583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* JBoss, Home of Professional Open Source. | |
* Copyright 2019, Red Hat, Inc., and individual contributors | |
* as indicated by the @author tags. See the copyright.txt file in the | |
* distribution for a full listing of individual contributors. | |
* | |
* This is free software; you can redistribute it and/or modify it | |
* under the terms of the GNU Lesser General Public License as | |
* published by the Free Software Foundation; either version 2.1 of | |
* the License, or (at your option) any later version. | |
* | |
* This software is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
* Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public | |
* License along with this software; if not, write to the Free | |
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
*/ | |
package com.hp.mwtests.ts.jta.cdi.transactionScoped; | |
import javax.enterprise.context.ApplicationScoped; | |
import javax.enterprise.context.Initialized; | |
import javax.enterprise.event.Observes; | |
import javax.inject.Inject; | |
import javax.naming.InitialContext; | |
import javax.transaction.Transaction; | |
import javax.transaction.TransactionManager; | |
import javax.transaction.TransactionScoped; | |
import javax.transaction.UserTransaction; | |
import org.jboss.arquillian.container.test.api.Deployment; | |
import org.jboss.arquillian.junit.Arquillian; | |
import org.jboss.shrinkwrap.api.ShrinkWrap; | |
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | |
import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
import org.junit.After; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import static org.junit.Assert.assertNotNull; | |
import static org.junit.Assert.assertTrue; | |
/** | |
* @author <a href="https://about.me/lairdnelson" | |
* target="_parent">Laird Nelson</a> | |
*/ | |
@RunWith(Arquillian.class) | |
public class TransactionScopeLifecycleEventsTest { | |
private static boolean initializedObserved; | |
@Inject | |
UserTransaction userTransaction; | |
@Deployment | |
public static JavaArchive createTestArchive() { | |
return ShrinkWrap.create(JavaArchive.class, "test.jar") | |
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); | |
} | |
@After | |
public void tearDown() throws Exception { | |
this.userTransaction.rollback(); | |
} | |
@Test | |
public void testIt() throws Exception { | |
userTransaction.begin(); | |
assertTrue(initializedObserved); | |
} | |
@ApplicationScoped | |
public static class Foo { | |
public Foo() { | |
super(); | |
} | |
private static void kaboing(@Observes @Initialized(TransactionScoped.class) final Object event) { | |
assertNotNull(event); | |
initializedObserved = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment