test1LF.closeContext(false);
}
public void testGlobalSession() throws Exception
{
Session jcrSession;
//
SynchronizationEventQueue queue = new SynchronizationEventQueue();
//
chromatticManager.beginRequest();
try
{
Chromattic chromattic = test1LF.getChromattic();
// No context should be open
assertNull(test1LF.getContext(true));
// Opens a session with the provided Chromattic
ChromatticSession session = chromattic.openSession();
// Now we should have a context
SessionContext context = test1LF.getContext(true);
assertNotNull(context);
// Register synchronzation with event queue
context.addSynchronizationListener(queue);
// Check how chromattic see the session
FooEntity foo = session.create(FooEntity.class);
assertEquals("portal-test", foo.getWorkspace());
// Check related JCR session
jcrSession = session.getJCRSession();
assertTrue(jcrSession.isLive());
Workspace workspace = jcrSession.getWorkspace();
assertEquals("portal-test", workspace.getName());
// Closing chromattic session should not close the underlying JCR session
session.close();
assertTrue(jcrSession.isLive());
// Queue should be empty up to here
queue.assertEmpty();
}
finally
{
chromatticManager.endRequest(false);
}
//
queue.assertEvent(SynchronizationEvent.BEFORE);
queue.assertEvent(SynchronizationEvent.DISCARDED);
// Assert JCR session was properly closed
assertFalse(jcrSession.isLive());
}