1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.chain.web.portlet;
18
19
20 import javax.portlet.Portlet;
21 import javax.portlet.PortletContext;
22 import javax.portlet.PortletRequestDispatcher;
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
32 public class MockPortletContext implements PortletContext {
33
34
35 private int majorVersion = 1;
36 private int minorVersion = 0;
37 private String portletContextName = "MockPortletContext";
38 private String serverInfo = portletContextName;
39 private Hashtable parameters = new Hashtable();
40 private Hashtable attributes = new Hashtable();
41
42
43
44
45
46 public void setPortletContextName(String portletContextName) {
47 this.portletContextName = portletContextName;
48 }
49
50 public void setServerInfo(String serverInfo) {
51 this.serverInfo = serverInfo;
52 }
53
54 public void addInitParameter(String name, String value) {
55 parameters.put(name, value);
56 }
57
58
59
60
61
62 public Object getAttribute(String name) {
63 return attributes.get(name);
64 }
65
66 public Enumeration getAttributeNames() {
67 return attributes.keys();
68 }
69
70 public String getInitParameter(String name) {
71 return (String)parameters.get(name);
72 }
73
74 public Enumeration getInitParameterNames() {
75 return parameters.keys();
76 }
77
78 public int getMajorVersion() {
79 return majorVersion;
80 }
81
82 public String getMimeType(String path) {
83 throw new UnsupportedOperationException();
84 }
85
86 public int getMinorVersion() {
87 return minorVersion;
88 }
89
90 public PortletRequestDispatcher getNamedDispatcher(String name) {
91 throw new UnsupportedOperationException();
92 }
93
94 public String getPortletContextName() {
95 return portletContextName;
96 }
97
98 public String getRealPath(String path) {
99 throw new UnsupportedOperationException();
100 }
101
102 public PortletRequestDispatcher getRequestDispatcher(String path) {
103 throw new UnsupportedOperationException();
104 }
105
106 public URL getResource(String path) throws MalformedURLException {
107 throw new UnsupportedOperationException();
108 }
109
110 public InputStream getResourceAsStream(String path) {
111 throw new UnsupportedOperationException();
112 }
113
114 public Set getResourcePaths(String path) {
115 throw new UnsupportedOperationException();
116 }
117
118 public String getServerInfo() {
119 return serverInfo;
120 }
121
122 public void log(String message) {
123 throw new UnsupportedOperationException();
124 }
125
126 public void log(String message, Throwable exception) {
127 throw new UnsupportedOperationException();
128 }
129
130 public void removeAttribute(String name) {
131 attributes.remove(name);
132 }
133
134 public void setAttribute(String name, Object value) {
135 attributes.put(name, value);
136 }
137
138 }