001// Copyright 2006, 2007, 2008 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.internal.test;
016
017import org.apache.tapestry5.commons.util.CollectionFactory;
018import org.apache.tapestry5.http.services.Session;
019import org.apache.tapestry5.ioc.internal.util.InternalUtils;
020
021import static org.apache.tapestry5.commons.util.CollectionFactory.newList;
022
023import java.util.List;
024import java.util.Map;
025
026public class PageTesterSession implements Session
027{
028    private final Map<String, Object> attributes = CollectionFactory.newMap();
029
030    public List<String> getAttributeNames()
031    {
032        return InternalUtils.sortedKeys(attributes);
033    }
034
035    public List<String> getAttributeNames(String prefix)
036    {
037        List<String> result = newList();
038
039        for (String name : getAttributeNames())
040            if (name.startsWith(prefix)) result.add(name);
041
042        return result;
043    }
044
045    public Object getAttribute(String name)
046    {
047        return attributes.get(name);
048    }
049
050    public void setAttribute(String name, Object value)
051    {
052        if (value == null)
053        {
054            attributes.remove(name);
055        }
056        else
057        {
058            attributes.put(name, value);
059        }
060    }
061
062    private void nyi(String name)
063    {
064        throw new IllegalStateException(String.format("%s.%s() is not yet implemented.", getClass()
065                .getName(), name));
066    }
067
068    public int getMaxInactiveInterval()
069    {
070        nyi("getMaxInativeInterval");
071
072        return 0;
073    }
074
075    public void invalidate()
076    {
077        nyi("invalidate");
078    }
079
080    public boolean isInvalidated()
081    {
082        return false;
083    }
084
085    public void restoreDirtyObjects()
086    {
087    }
088
089    public void setMaxInactiveInterval(int seconds)
090    {
091        nyi("setMaxInactiveInterval");
092    }
093}