KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > mock > MockResponse


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.environment.mock;
17
18 import java.util.Locale JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import junit.framework.AssertionFailedError;
25
26 import org.apache.cocoon.environment.Cookie;
27 import org.apache.cocoon.environment.Response;
28
29 public class MockResponse implements Response {
30
31     private String JavaDoc encoding;
32     private Locale JavaDoc locale;
33     private HashSet JavaDoc cookies = new HashSet JavaDoc();
34     private HashMap JavaDoc header = new HashMap JavaDoc();
35
36     public void setCharacterEncoding(String JavaDoc encoding) {
37         this.encoding = encoding;
38     }
39
40     public String JavaDoc getCharacterEncoding() {
41         return encoding;
42     }
43
44     public void setLocale(Locale JavaDoc locale) {
45         this.locale = locale;
46     }
47
48     public Locale JavaDoc getLocale() {
49         return locale;
50     }
51
52     public Cookie createCookie(String JavaDoc name, String JavaDoc value) {
53         MockCookie cookie = new MockCookie();
54         cookie.setName(name);
55         cookie.setValue(value);
56         return cookie;
57     }
58
59     public void addCookie(Cookie cookie) {
60         cookies.add(cookie);
61     }
62
63     public Set JavaDoc getCookies() {
64         return cookies;
65     }
66
67     public boolean containsHeader(String JavaDoc name) {
68         return header.containsKey(name);
69     }
70
71     public String JavaDoc encodeURL(String JavaDoc url) {
72         throw new AssertionFailedError("Not implemented");
73     }
74
75     public void setDateHeader(String JavaDoc name, long date) {
76         header.put(name, new Long JavaDoc(date));
77     }
78
79     public void addDateHeader(String JavaDoc name, long date) {
80         header.put(name, new Long JavaDoc(date));
81     }
82
83     public void setHeader(String JavaDoc name, String JavaDoc value) {
84         header.put(name, value);
85     }
86
87     public void addHeader(String JavaDoc name, String JavaDoc value) {
88         header.put(name, value);
89     }
90
91     public void setIntHeader(String JavaDoc name, int value) {
92         header.put(name, new Integer JavaDoc(value));
93     }
94
95     public void addIntHeader(String JavaDoc name, int value) {
96         header.put(name, new Integer JavaDoc(value));
97     }
98
99     public Map JavaDoc getHeader() {
100         return header;
101     }
102
103     public void reset() {
104         encoding = null;
105         locale = null;
106         cookies.clear();
107         header.clear();
108     }
109 }
110
Popular Tags