1 16 package org.apache.commons.chain.web.servlet; 17 18 19 import javax.servlet.RequestDispatcher ; 20 import javax.servlet.Servlet ; 21 import javax.servlet.ServletContext ; 22 import javax.servlet.ServletException ; 23 import java.io.InputStream ; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Enumeration ; 27 import java.util.Hashtable ; 28 import java.util.Set ; 29 30 31 public class MockServletContext implements ServletContext { 33 34 35 private Hashtable attributes = new Hashtable (); 36 private Hashtable parameters = new Hashtable (); 37 38 39 41 42 public void addInitParameter(String name, String value) { 43 parameters.put(name, value); 44 } 45 46 47 49 50 public Object getAttribute(String name) { 51 return (attributes.get(name)); 52 } 53 54 public Enumeration getAttributeNames() { 55 return (attributes.keys()); 56 } 57 58 public ServletContext getContext(String uripath) { 59 throw new UnsupportedOperationException (); 60 } 61 62 public String getInitParameter(String name) { 63 return ((String ) parameters.get(name)); 64 } 65 66 public Enumeration getInitParameterNames() { 67 return (parameters.keys()); 68 } 69 70 public int getMajorVersion() { 71 return (2); 72 } 73 74 public String getMimeType(String path) { 75 throw new UnsupportedOperationException (); 76 } 77 78 public int getMinorVersion() { 79 return (3); 80 } 81 82 public RequestDispatcher getNamedDispatcher(String name) { 83 throw new UnsupportedOperationException (); 84 } 85 86 public String getRealPath(String path) { 87 throw new UnsupportedOperationException (); 88 } 89 90 public RequestDispatcher getRequestDispatcher(String path) { 91 throw new UnsupportedOperationException (); 92 } 93 94 public URL getResource(String path) throws MalformedURLException { 95 throw new UnsupportedOperationException (); 96 } 97 98 public InputStream getResourceAsStream(String path) { 99 throw new UnsupportedOperationException (); 100 } 101 102 public Set getResourcePaths(String path) { 103 throw new UnsupportedOperationException (); 104 } 105 106 public Servlet getServlet(String name) throws ServletException { 107 throw new UnsupportedOperationException (); 108 } 109 110 public String getServletContextName() { 111 return ("MockServletContext"); 112 } 113 114 public String getServerInfo() { 115 return ("MockServletContext"); 116 } 117 118 public Enumeration getServlets() { 119 throw new UnsupportedOperationException (); 120 } 121 122 public Enumeration getServletNames() { 123 throw new UnsupportedOperationException (); 124 } 125 126 public void log(String message) { 127 throw new UnsupportedOperationException (); 128 } 129 130 public void log(Exception exception, String message) { 131 throw new UnsupportedOperationException (); 132 } 133 134 public void log(String message, Throwable exception) { 135 throw new UnsupportedOperationException (); 136 } 137 138 public void removeAttribute(String name) { 139 attributes.remove(name); 140 } 141 142 public void setAttribute(String name, Object value) { 143 attributes.put(name, value); 144 } 145 146 147 } 148 | Popular Tags |