001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.commons.chain.web.servlet;
018    
019    
020    import org.apache.commons.chain.web.MockEnumeration;
021    
022    import javax.servlet.ServletContext;
023    import javax.servlet.http.HttpSession;
024    import javax.servlet.http.HttpSessionContext;
025    import java.util.Enumeration;
026    import java.util.HashMap;
027    
028    
029    
030    // Mock Object for HttpSession (Version 2.3)
031    public class MockHttpSession implements HttpSession {
032    
033    
034    
035        public MockHttpSession() {
036            super();
037        }
038    
039    
040        public MockHttpSession(ServletContext servletContext) {
041            super();
042            setServletContext(servletContext);
043        }
044    
045    
046    
047        protected HashMap attributes = new HashMap();
048        protected ServletContext servletContext = null;
049    
050    
051        // --------------------------------------------------------- Public Methods
052    
053    
054        public void setServletContext(ServletContext servletContext) {
055            this.servletContext = servletContext;
056        }
057    
058    
059        // ---------------------------------------------------- HttpSession Methods
060    
061    
062        public Object getAttribute(String name) {
063            return (attributes.get(name));
064        }
065    
066    
067        public Enumeration getAttributeNames() {
068            return (new MockEnumeration(attributes.keySet().iterator()));
069        }
070    
071    
072        public long getCreationTime() {
073            throw new UnsupportedOperationException();
074        }
075    
076    
077        public String getId() {
078            throw new UnsupportedOperationException();
079        }
080    
081    
082        public long getLastAccessedTime() {
083            throw new UnsupportedOperationException();
084        }
085    
086    
087        public int getMaxInactiveInterval() {
088            throw new UnsupportedOperationException();
089        }
090    
091    
092        public ServletContext getServletContext() {
093            return (this.servletContext);
094        }
095    
096    
097        public HttpSessionContext getSessionContext() {
098            throw new UnsupportedOperationException();
099        }
100    
101    
102        public Object getValue(String name) {
103            throw new UnsupportedOperationException();
104        }
105    
106    
107        public String[] getValueNames() {
108            throw new UnsupportedOperationException();
109        }
110    
111    
112        public void invalidate() {
113            throw new UnsupportedOperationException();
114        }
115    
116    
117        public boolean isNew() {
118            throw new UnsupportedOperationException();
119        }
120    
121    
122        public void putValue(String name, Object value) {
123            throw new UnsupportedOperationException();
124        }
125    
126    
127        public void removeAttribute(String name) {
128            attributes.remove(name);
129        }
130    
131    
132        public void removeValue(String name) {
133            throw new UnsupportedOperationException();
134        }
135    
136    
137        public void setAttribute(String name, Object value) {
138            if (value == null) {
139                attributes.remove(name);
140            } else {
141                attributes.put(name, value);
142            }
143        }
144    
145    
146        public void setMaxInactiveInterval(int interval) {
147            throw new UnsupportedOperationException();
148        }
149    
150    
151    }