protected final void train_getAttributeNames(Session session, String prefix, String... names) { expect(session.getAttributeNames(prefix)).andReturn(Arrays.asList(names)); }
public void discardChanges(String pageName) { Session session = request.getSession(false); if (session == null) return; String fullPrefix = prefix + pageName + ":"; for (String name : session.getAttributeNames(fullPrefix)) { session.setAttribute(name, null); } }
private void clearSession() { Session session = request.getSession(false); if (session != null) { for (String name : session.getAttributeNames()) { session.setAttribute(name, null); } } }
public String store(final String script) { Session session = request.getSession(true); String key = createKey(script); Integer max = 0; if ( session.getAttribute(key) != null ) { List<String> names = session.getAttributeNames(prefix); for ( String name : names ) { String[] parts = name.split("-"); Integer seq = new Integer(parts[1]); if ( seq > max ) { max = seq; } } } final String fkey = key + "-" + (max+1); session.setAttribute(fkey, script); return keyToUrl(fkey); }
public final Collection<PersistentFieldChange> gatherFieldChanges(String pageName) { Session session = request.getSession(false); if (session == null) return Collections.emptyList(); List<PersistentFieldChange> result = newList(); String fullPrefix = prefix + pageName + ":"; for (String name : session.getAttributeNames(fullPrefix)) { Object persistedValue = session.getAttribute(name); Object applicationValue = persistedValue == null ? null : convertPersistedToApplicationValue( persistedValue); PersistentFieldChange change = buildChange(name, applicationValue); result.add(change); didReadChange(session, name); } return result; }
@Test public void get_attribute_names() { Enumeration e = Collections.enumeration(Arrays.asList("fred", "barney")); HttpSession hs = mockHttpSession(); SessionLock lock = mockLock(); lock.acquireReadLock(); expect(hs.getAttributeNames()).andReturn(e); replay(); Session session = new SessionImpl(null, hs, lock); assertEquals(session.getAttributeNames(), Arrays.asList("barney", "fred")); verify(); }
@Test public void get_attribute_names_by_prefix() { Enumeration e = Collections.enumeration(Arrays.asList("fred", "barney", "fanny")); HttpSession hs = mockHttpSession(); SessionLock lock = mockLock(); lock.acquireReadLock(); expect(hs.getAttributeNames()).andReturn(e); replay(); Session session = new SessionImpl(null, hs, lock); assertEquals(session.getAttributeNames("f"), Arrays.asList("fanny", "fred")); verify(); }
pw = newPropertyWriter(writer, session.getAttributeNames()); for (String name : session.getAttributeNames())