@Test public void testSessionScopes() { // Create global scope int nPrev = AbstractScopeSPI.getBegin(); int nPrevT = AbstractThrowingScopeSPI.getBegin(); ScopeManager.onGlobalBegin("global"); assertEquals(nPrev + 1, AbstractScopeSPI.getBegin()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getBegin()); // Create request scope nPrev = AbstractScopeSPI.getBegin(); nPrevT = AbstractThrowingScopeSPI.getBegin(); ScopeManager.onRequestBegin("appid", "scopeid", "sessionid"); assertEquals(nPrev + 1, AbstractScopeSPI.getBegin()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getBegin()); // Create application scope nPrev = AbstractScopeSPI.getBegin(); nPrevT = AbstractThrowingScopeSPI.getBegin(); ScopeManager.getApplicationScope(); assertEquals(nPrev + 1, AbstractScopeSPI.getBegin()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getBegin()); // Create second application scope nPrev = AbstractScopeSPI.getBegin(); nPrevT = AbstractThrowingScopeSPI.getBegin(); ScopeManager.getApplicationScope("any other blabla"); assertEquals(nPrev + 1, AbstractScopeSPI.getBegin()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getBegin()); // Begin session scope nPrev = AbstractScopeSPI.getBegin(); nPrevT = AbstractThrowingScopeSPI.getBegin(); final ISessionScope aSessionScope = ScopeManager.getSessionScope(); assertEquals(nPrev + 1, AbstractScopeSPI.getBegin()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getBegin()); // End request scope nPrev = AbstractScopeSPI.getEnd(); nPrevT = AbstractThrowingScopeSPI.getEnd(); ScopeManager.onRequestEnd(); assertEquals(nPrev + 1, AbstractScopeSPI.getEnd()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getEnd()); // End session scope nPrev = AbstractScopeSPI.getEnd(); nPrevT = AbstractThrowingScopeSPI.getEnd(); ScopeManager.destroySessionScope(aSessionScope); assertEquals(nPrev + 1, AbstractScopeSPI.getEnd()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getEnd()); // End global scope and application scopes nPrev = AbstractScopeSPI.getEnd(); nPrevT = AbstractThrowingScopeSPI.getEnd(); ScopeManager.onGlobalEnd(); assertEquals(nPrev + 3, AbstractScopeSPI.getEnd()); assertEquals(nPrevT + 3, AbstractThrowingScopeSPI.getEnd()); }
@Test public void testApplicationScope() { // Create global scope int nPrev = AbstractScopeSPI.getBegin(); int nPrevT = AbstractThrowingScopeSPI.getBegin(); ScopeManager.onGlobalBegin("global"); assertEquals(nPrev + 1, AbstractScopeSPI.getBegin()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getBegin()); // Create request scope nPrev = AbstractScopeSPI.getBegin(); nPrevT = AbstractThrowingScopeSPI.getBegin(); ScopeManager.onRequestBegin("appid", "scopeid", "sessionid"); assertEquals(nPrev + 1, AbstractScopeSPI.getBegin()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getBegin()); // Create application scope nPrev = AbstractScopeSPI.getBegin(); nPrevT = AbstractThrowingScopeSPI.getBegin(); ScopeManager.getApplicationScope(); assertEquals(nPrev + 1, AbstractScopeSPI.getBegin()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getBegin()); // End request scope nPrev = AbstractScopeSPI.getEnd(); nPrevT = AbstractThrowingScopeSPI.getEnd(); ScopeManager.onRequestEnd(); assertEquals(nPrev + 1, AbstractScopeSPI.getEnd()); assertEquals(nPrevT + 1, AbstractThrowingScopeSPI.getEnd()); // End global scope and application scope nPrev = AbstractScopeSPI.getEnd(); nPrevT = AbstractThrowingScopeSPI.getEnd(); ScopeManager.onGlobalEnd(); assertEquals(nPrev + 2, AbstractScopeSPI.getEnd()); assertEquals(nPrev + 2, AbstractThrowingScopeSPI.getEnd()); }
/** * @param bCreateIfNotExisting <code>true</code> to create a new scope, if none is present yet, * <code>false</code> to return <code>null</code> if either no global scope or no application * scope is present. * @return The scope to be used for this type of singleton. */ @Nullable private static IApplicationScope _getStaticScope(final boolean bCreateIfNotExisting) { return ScopeManager.getApplicationScope(bCreateIfNotExisting); }