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
015 package org.apache.tapestry5.internal.test;
016
017 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
018 import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
019 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
020 import org.apache.tapestry5.services.Session;
021
022 import java.util.List;
023 import java.util.Map;
024
025 public class PageTesterSession implements Session
026 {
027 private final Map<String, Object> attributes = CollectionFactory.newMap();
028
029 public List<String> getAttributeNames()
030 {
031 return InternalUtils.sortedKeys(attributes);
032 }
033
034 public List<String> getAttributeNames(String prefix)
035 {
036 List<String> result = newList();
037
038 for (String name : getAttributeNames())
039 if (name.startsWith(prefix)) result.add(name);
040
041 return result;
042 }
043
044 public Object getAttribute(String name)
045 {
046 return attributes.get(name);
047 }
048
049 public void setAttribute(String name, Object value)
050 {
051 if (value == null)
052 {
053 attributes.remove(name);
054 }
055 else
056 {
057 attributes.put(name, value);
058 }
059 }
060
061 private void nyi(String name)
062 {
063 throw new IllegalStateException(String.format("%s.%s() is not yet implemented.", getClass()
064 .getName(), name));
065 }
066
067 public int getMaxInactiveInterval()
068 {
069 nyi("getMaxInativeInterval");
070
071 return 0;
072 }
073
074 public void invalidate()
075 {
076 nyi("invalidate");
077 }
078
079 public boolean isInvalidated()
080 {
081 return false;
082 }
083
084 public void restoreDirtyObjects()
085 {
086 }
087
088 public void setMaxInactiveInterval(int seconds)
089 {
090 nyi("setMaxInactiveInterval");
091 }
092 }