Created
September 23, 2013 16:08
-
-
Save dmitrygusev/6672859 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// see http://svn.apache.org/repos/asf/shiro/tags/shiro-root-1.2.2/core/src/test/java/org/apache/shiro/test/AbstractShiroTest.java | |
public class BaseIntegrationTest extends AbstractShiroTest | |
{ | |
public static Registry registry; | |
@BeforeClass | |
public static void setup() | |
{ | |
registry = new RegistryBuilder().add( | |
TapestryModule.class, | |
JpaModule.class, | |
SecurityModule.class, | |
QuartzModule.class, | |
AppModule.class, | |
IntegrationModule.class) | |
.build(); | |
ApplicationGlobals globals = registry.getObject( | |
ApplicationGlobals.class, null); | |
globals.storeContext(new PageTesterContext("")); | |
ServletContext servletContext = Mockito.mock(ServletContext.class); | |
Mockito.when(servletContext.getAttribute(TapestryFilter.REGISTRY_CONTEXT_NAME)) | |
.thenReturn(registry); | |
globals.storeServletContext(servletContext); | |
registry.performRegistryStartup(); | |
} | |
@AfterClass | |
public static void cleanup() | |
{ | |
if (registry != null) | |
{ | |
registry.shutdown(); | |
} | |
} | |
private EntityManagerManager entityManagerManager; | |
public EntityManager em; | |
@Before | |
public void before() | |
{ | |
Subject defaultSubject = Mockito.mock(Subject.class); | |
setSubject(defaultSubject); | |
entityManagerManager = registry.getService(EntityManagerManager.class); | |
em = JpaInternalUtils.getEntityManager(entityManagerManager, null); | |
em.getTransaction().begin(); | |
} | |
@After | |
public void after() | |
{ | |
if (em.getTransaction().isActive()) | |
{ | |
em.getTransaction().rollback(); | |
} | |
clearSubject(); | |
} | |
// Domain specific methods that create entities | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment