Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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